招摇配置:
@EnableSwagger
@Configuration
public class SwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin() {
return new SwaggerSpringMvcPlugin(springSwaggerConfig)
.swaggerGroup("sample-app")
.includePatterns(
"/account/*"
)
.apiInfo(apiInfo())
.build();
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
"sample-app",
"sample-app doc",
"",
"support@sample-app",
"",
""
);
return apiInfo;
}
休息控制器
@RestController
@RequestMapping(value = "/account")
@Api(value = "Change Account details", description = "")
public class ChangeAccountController {
@ApiOperation(value = "Change address")
@RequestMapping(value = "/addresschange", method = RequestMethod.POST)
public String addressChange(HttpServletRequest httpRequest, HttpServletResponse httpResponse,
@Valid @RequestBody User user) throws ServletException, IOException {
// logic and return something!
}
}
参考:一些信息已经从这里参考:http://java.dzone.com/articles/how-configure-swagger-generate
问题/问题:
在方法中SwaggerConfig.java
,includePatterns()
当我给出模式时,/account/*
API 不会出现在 Swagger 输出页面中,而如果我包含/account/.*
出现的模式。为什么?/account/*
在这个用例中和有什么区别/account/.*
?
更新:
另一个用例
@RestController
@RequestMapping(value = "/score")
@ApiOperation(value = "All score", notes = "")
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody ActionResult allScores(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) {
}
如果我将模式添加为/score/*
,则 API 将出现在 Swagger 中。我不需要把模式作为/score/.*