Commit fb5a3237 authored by Quxl's avatar Quxl

优化SwaggerUI,优化接口文档

parent 5db250e7
...@@ -46,9 +46,9 @@ public class MemberOpenApiController { ...@@ -46,9 +46,9 @@ public class MemberOpenApiController {
@PostMapping("register") @PostMapping("register")
@ApiOperation("会员注册") @ApiOperation("会员注册")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "username"), @ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "username"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "password"), @ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "password"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"), @ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "email"),
}) })
public Object register(HttpServletRequest request, String username, String password, String email) { public Object register(HttpServletRequest request, String username, String password, String email) {
XException.assertNotBlank(messages.get("err.email_null"), email); XException.assertNotBlank(messages.get("err.email_null"), email);
...@@ -76,7 +76,7 @@ public class MemberOpenApiController { ...@@ -76,7 +76,7 @@ public class MemberOpenApiController {
@ResponseBody @ResponseBody
@PostMapping("resetPassword") @PostMapping("resetPassword")
@ApiOperation("找回密码") @ApiOperation("找回密码")
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email")}) @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "email")})
public Object resetPassword(String email) { public Object resetPassword(String email) {
XException.assertNotBlank(messages.get("err.email_null"), email); XException.assertNotBlank(messages.get("err.email_null"), email);
int code = (int) ((Math.random() * 9 + 1) * 10000000); int code = (int) ((Math.random() * 9 + 1) * 10000000);
...@@ -113,7 +113,7 @@ public class MemberOpenApiController { ...@@ -113,7 +113,7 @@ public class MemberOpenApiController {
@ResponseBody @ResponseBody
@PostMapping("setLocale") @PostMapping("setLocale")
@ApiOperation("设置语言环境") @ApiOperation("设置语言环境")
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN")}) @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "i18n_language", defaultValue="zh_CN")})
public Object setLocale(HttpSession session, String i18n_language) { public Object setLocale(HttpSession session, String i18n_language) {
Locale locale = new Locale(i18n_language); Locale locale = new Locale(i18n_language);
session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale); session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale);
......
...@@ -42,11 +42,11 @@ public class MemberInfoController { ...@@ -42,11 +42,11 @@ public class MemberInfoController {
@PostMapping("save") @PostMapping("save")
@ApiOperation("保存会员基本信息") @ApiOperation("保存会员基本信息")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"), @ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "email"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "realname"), @ApiImplicitParam(paramType = "query", dataType = "String", required = false, name = "realname"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "address"), @ApiImplicitParam(paramType = "query", dataType = "String", required = false, name = "address"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "company"), @ApiImplicitParam(paramType = "query", dataType = "String", required = false, name = "company"),
@ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "tel"), @ApiImplicitParam(paramType = "query", dataType = "String", required = false, name = "tel"),
}) })
public Object save(String email, String realname, String address, String company, String tel) { public Object save(String email, String realname, String address, String company, String tel) {
LoginToken loginToken = tokenService.getToken(); LoginToken loginToken = tokenService.getToken();
......
/*
*
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package springfox.documentation.spring.web.readers.parameter;
import static springfox.documentation.schema.Collections.collectionElementType;
import static springfox.documentation.schema.Collections.isContainerType;
import static springfox.documentation.schema.Maps.isMapType;
import static springfox.documentation.schema.ResolvedTypes.modelRefFactory;
import static springfox.documentation.schema.Types.isBaseType;
import static springfox.documentation.schema.Types.typeNameFor;
import static springfox.documentation.spi.schema.contexts.ModelContext.inputParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.TypeResolver;
import com.google.common.base.Optional;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.schema.TypeNameExtractor;
import springfox.documentation.service.ResolvedMethodParameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.contexts.ModelContext;
import springfox.documentation.spi.service.ParameterBuilderPlugin;
import springfox.documentation.spi.service.contexts.ParameterContext;
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ParameterDataTypeReader implements ParameterBuilderPlugin {
private final TypeNameExtractor nameExtractor;
private final TypeResolver resolver;
@Autowired
public ParameterDataTypeReader(TypeNameExtractor nameExtractor, TypeResolver resolver) {
this.nameExtractor = nameExtractor;
this.resolver = resolver;
}
@Override
public boolean supports(DocumentationType delimiter) {
return true;
}
@Override
public void apply(ParameterContext context) {
ResolvedMethodParameter methodParameter = context.resolvedMethodParameter();
ResolvedType parameterType = methodParameter.getParameterType();
parameterType = context.alternateFor(parameterType);
ModelReference modelRef = null;
if (methodParameter.hasParameterAnnotation(PathVariable.class) && treatAsAString(parameterType)) {
parameterType = resolver.resolve(String.class);
modelRef = new ModelRef("string");
} else if (methodParameter.hasParameterAnnotation(RequestParam.class) && isMapType(parameterType)) {
modelRef = new ModelRef("", new ModelRef("string"), true);
} else if (methodParameter.hasParameterAnnotation(RequestParam.class) && treatRequestParamAsString(parameterType)) {
parameterType = resolver.resolve(String.class);
modelRef = new ModelRef("string");
}
if (!methodParameter.hasParameterAnnotations()) {
Class<?> t = parameterType.getErasedType();
String typeName = typeNameFor(t);
if (isBaseType(typeName)) {
modelRef = new ModelRef(typeName);
} else {
//LOG.warn("Trying to infer dataType {}", parameterType);
}
}
ModelContext modelContext = inputParam(parameterType,
context.getDocumentationType(),
context.getAlternateTypeProvider(),
context.getGenericNamingStrategy(),
context.getIgnorableParameterTypes());
context.parameterBuilder()
.type(parameterType)
.modelRef(Optional.fromNullable(modelRef)
.or(modelRefFactory(modelContext, nameExtractor).apply(parameterType)));
}
private boolean treatRequestParamAsString(ResolvedType parameterType) {
return treatAsAString(parameterType) && !isContainerType(parameterType)
|| (isContainerType(parameterType) && treatAsAString(collectionElementType(parameterType)));
}
private boolean treatAsAString(ResolvedType parameterType) {
return !(isBaseType(typeNameFor(parameterType.getErasedType()))
|| parameterType.getErasedType().isEnum());
}
}
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
<logger name="org" level="INFO" /> <logger name="org" level="INFO" />
<logger name="com" level="INFO" /> <logger name="com" level="INFO" />
<logger name="com.egolm" level="INFO" /> <logger name="swagger" level="DEBUG" />
<logger name="com.egolm" level="DEBUG" />
<appender name="siftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender"> <appender name="siftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator> <discriminator>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment