Springfox - Is it possible to document a POJO via annotation if it's not used in a controller

喜欢而已 提交于 2019-12-12 19:12:45

问题


As the title says, is it possible to include a POJO in a swagger doc if it's not used in a controller method?

I've tried using the @ApiModel annotation on the POJO class, i.e.:

@ApiModel("POJO")
public class Pojo {
  ...
}

However, unless the POJO is returned by a controller, I haven't been able to have it appear in the generated swagger docs. Is there a way to accomplish this?

I'm using springfox version 2.9.2, by the way.


回答1:


It is possible with Springfox. You just have to modify your Docket. Add 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));
}


来源:https://stackoverflow.com/questions/52841563/springfox-is-it-possible-to-document-a-pojo-via-annotation-if-its-not-used-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!