从JSON生成Swagger以保持干净的.java类 [英] Generate Swagger from a JSON to keep clean my .java classes
问题描述
我正在使用Springfox v 2.7,我想从JSON文件生成Swagger UI,以保持控制器类整洁,并且没有Swawgger(@ Api,@ ApiDocs)的注释,或者我的模型类没有任何注释(@ApiModelProperty等)。...
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)....
致谢!
PD:这是Spring Boot 1.5 .8版本的应用程序。
PD: This is a Spring boot 1.5.8 version App.
推荐答案
以下是您需要进行的更改:
Here are the changes you need to make:
-
仅需要Springfox JAR是
springfox-swagger-ui
JAR,其中包含所有静态UI工件。
Only Springfox JAR needed is
springfox-swagger-ui
JAR which contains all the static UI artifacts.
一个 swagger.json
文件,其中包含位于资源$下的所有JSON定义。 c $ c>文件夹。
A swagger.json
file containing all the JSON definition located under the resources
folder.
具有以下端点的自定义控制器,可以满足来自 swagger-ui.html <的所有请求/ code>:
A custom controller having the following endpoints to meet all the requests from the swagger-ui.html
:
-
/ swagger-resources
端点它返回springfox.documentation.swag的JSON字符串表示形式ger.web.SwaggerResource
对象。
/ swagger-resources / configuration / ui
端点,它返回 springfox.documentation.swagger.web.UiConfiguration
对象的JSON字符串表示形式。
/swagger-resources/configuration/ui
endpoint which returns a JSON string representation of a springfox.documentation.swagger.web.UiConfiguration
object.
/ swagger-resources / configuration / security
端点,该端点返回 springfox.documentation.swagger.web.SecurityConfiguration <的JSON字符串表示形式/ code>对象。
/swagger-resources/configuration/security
endpoint which returns a JSON string representation of a springfox.documentation.swagger.web.SecurityConfiguration
object.
/ v2 / api-docs
端点,该端点返回JSON Swagger API定义的表示形式。
/v2/api-docs
endpoint which returns a JSON representation of a Swagger API definition.
您可以找到一个有效的示例此处。
You can find a working example here.
这篇关于从JSON生成Swagger以保持干净的.java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!