Springfox – If it is not used in the Controller, is it possible to record a POJO through comments… here is a solution to the problem.
Springfox – If it is not used in the Controller, is it possible to record a POJO through comments
As the title says, if the POJO is not used in the Controller method, is it possible to include it in the swagger documentation?
I tried using the @ApiModel annotation on the POJO class, i.e.:
@ApiModel("POJO")
public class Pojo {
...
}
However, I can’t get it to appear in the generated swagger document unless the POJO is returned by the controller. Is there a way to achieve this?
By the way, I’m using Springfox version 2.9.2.
Solution
Using Springfox is possible. You just need to modify your Docket
. Add the additionalModels
method to your Docket
implementation:
@Autowired
private TypeResolver resolver;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
...
.additionalModels(resolver.resolve(Pojo.class));
}