如何从包含Swagger特定注释的java文件生成JSON文件,以便Swagger-UI可以读取它。
答案 0 :(得分:2)
正如您所说“我不想手动执行”,请使用Swagger Maven插件:
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.4</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>true / false</springmvc>
<locations>
<location>com.yourpackage.something</location>
</locations>
<host>yourhost.com</host>
<basePath>/some/path</basePath>
<info>
<title>Your Project Title</title>
<version>${project.version}</version>
<description>Some nice stuff</description>
<termsOfService>...</termsOfService>
<contact>
<email>someone@somewhere.com</email>
<name>Your Name</name>
<url>www.where.to.find.you</url>
</contact>
</info>
<swaggerDirectory>path/to/swagger/output</swaggerDirectory>
<outputFormats>json</outputFormats>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
然后您可以执行mvn compile
并生成swagger.json
文件。