Swagger Configuration:
@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;
}
Rest Controller
@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!
}
}
Reference: Some of the information has been referred from here: http ://java.dzone.com/articles/how-configure-swagger-generate
Problem/Question:
In the SwaggerConfig.java
, in the includePatterns()
method, when I give the pattern
as /account/*
the API doesn't appear in the Swagger output page, whereas,
if I include the pattern as /account/.*
it appears.
Why? what is the difference between /account/*
and /account/.*
in this use-case?
Update:
Another use-case
@RestController
@RequestMapping(value = "/score")
@ApiOperation(value = "All score", notes = "")
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody ActionResult allScores(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) {
}
If I add the pattern as /score/*
, then the API is appearing in Swagger.
I need not put the pattern as /score/.*
The difference is that if you write /account/* it means take any string that starts with "/account" and then has at least 0 occurrences of character '/' and the second pattern matches string starting with "/account/" followed by at least 0 occurrences of any character.
For more details see e.g. http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html