Generate Swagger from a JSON to keep clean my .java classes

ⅰ亾dé卋堺 提交于 2019-12-11 07:44:33

问题


I am using Springfox v 2.7 and I'd like to generate my Swagger UI from a JSON file, to keep my Controller classes clean, and without annotations from Swawgger (@Api, @ApiDocs) either my model classes without any annotation (@ApiModelProperty, etc)....

Regards!

PD: This is a Spring boot 1.5.8 version App.


回答1:


Here are the changes you need to make:

  • Only Springfox JAR needed is springfox-swagger-ui JAR which contains all the static UI artifacts.

  • A swagger.json file containing all the JSON definition located under the resources folder.

  • A custom controller having the following endpoints to meet all the requests from the swagger-ui.html:

    1. /swagger-resources endpoint which returns a JSON string representation of a springfox.documentation.swagger.web.SwaggerResource object.

    2. /swagger-resources/configuration/ui endpoint which returns a JSON string representation of a springfox.documentation.swagger.web.UiConfiguration object.

    3. /swagger-resources/configuration/security endpoint which returns a JSON string representation of a springfox.documentation.swagger.web.SecurityConfiguration object.

    4. /v2/api-docs endpoint which returns a JSON representation of a Swagger API definition.

You can find a working example here.



来源:https://stackoverflow.com/questions/47439776/generate-swagger-from-a-json-to-keep-clean-my-java-classes

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