I would like to add the following REST controller to an existing Spring Boot webapp and document it using Swagger:
@RestController
@Api(description="Querying concepts")
public class KnowledgeModelController {
private ConceptService conceptService;
@Autowired
public KnowledgeModelController(ConceptService conceptService) {
this.conceptService = conceptService;
}
@ApiOperation(value = "Returns a concept identified by its URI, optionally restricted by its branch", response = ConceptService.Concept.class)
@RequestMapping(value = "/concept", method = RequestMethod.GET)
public ConceptService.Concept getConcept(Optional<String> branch, String uri) {
return conceptService.getConcept(branch, uri);
}
}
However, simply adding springfox-swagger2 and springfox-swagger-ui dependencies does not work out of the box.
Although both the RestController (and thus the documentation endpoint /v2/api-docs that springfox generates for it) and swagger-ui.html are mapped under the root path /, swagger-ui.html does not find /v2/api-docs. My explanation is that swagger-ui.html navigates to ../v2/api-docs, but .. does not exist when in /.
The problem could obviously solved by moving the entire webapp to a non-root context path. However, I cannot go that route since clients already know and use certain of its endpoints.
How can springfox and swagger be made to work in this scenario?