1
揚鞭配置:揚鞭includePatterns()
@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",
"",
"[email protected]",
"",
""
);
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不出現在揚鞭輸出頁面,反之,如果 我包括圖案作爲/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是出現在揚鞭。 我不需要把模式作爲/score/.*