Reputation: 406
I am currently traing to document my REST interface "/news/rest/v1/articles" using Swagger2 and Spring MVC. It looks like this:
@RestController
@Api(
description = "My News interface",
produces = "application/json; charset=utf-8"
)
public class NewsController {
@RequestMapping(
method = RequestMethod.GET,
value = "/news/rest/v1/articles",
produces = {"application/json; charset=utf-8"}
)
@ApiOperation(
value = "Returns news according to the given limit and language"
)
@ApiResponses(
value = {
@ApiResponse(
code = 503,
message = "in case the news cannot be retrieved"
)
}
)
public String getNews(
@ApiParam(
value = "limitation of news elements",
required = false,
defaultValue = "-1" // -1 means no limitation
)
@RequestParam(defaultValue = "-1")
Integer limit,
@ApiParam(
value = "the language",
required = true,
allowableValues = "de,fr,it,en"
)
@RequestParam(defaultValue = "de")
@Valid
@Pattern(regexp = "de|fr|it|en")
String language
throws HTTPException {
// implementation
}
}
If I deploy my app and navigate to the Swagger-UI, everything looks just fine, except for the fact that I cannot use the "Try it out!"-button. The problem is that the generated URL used by Swagger is somewhat weird...It looks like this:
http://localhost:8080/myApp/api/news/rest/v1/articles{?limit,language}?limit=-1&language=de
I cannot quite get my head around why the string "{?limit,language}" is included into the request URL. If I manually call that very URL without the "{?limit,language}" string, it works just fine...
I'd appreciate it very much if somebody could give me a pointer on this.
Best regards Walter
Upvotes: 0
Views: 540
Reputation: 8057
I had the same problem here: Using @RequestParam annotated method with swagger ui
You need to set
enableUrlTemplating(false)
in Docket
configuration
Upvotes: 2