使用springfox、swagger和gradle生成静态文档

使用springfox、swagger和gradle生成静态文档,spring,spring-boot,swagger,springfox,Spring,Spring Boot,Swagger,Springfox,我已经评估了springfox在一个简单的springboot应用程序中的集成,该应用程序公开了一些restapi-s。乍一看,一切都很好-当应用程序启动时,我可以在JSON端点看到Swagger规范,我可以连接并使用Swagger UI,考虑到Swagger注释,我可以使用代码生成器生成静态HTML文档,等等 我现在想知道的是一件非常简单的事情:如何在构建过程中生成静态文档?我用gradle。在构建过程中,服务器显然已关闭,而swagger规范所在的JSON端点根本不可用 例如:代码库->构建

我已经评估了
springfox
在一个简单的springboot应用程序中的集成,该应用程序公开了一些restapi-s。乍一看,一切都很好-当应用程序启动时,我可以在JSON端点看到Swagger规范,我可以连接并使用Swagger UI,考虑到Swagger注释,我可以使用代码生成器生成静态HTML文档,等等

我现在想知道的是一件非常简单的事情:如何在构建过程中生成静态文档?我用gradle。在构建过程中,服务器显然已关闭,而swagger规范所在的JSON端点根本不可用


例如:
代码库->构建->(可执行jar+文档+…)

我必须在构建时生成
swagger.json
文件,以便在
Accept
头中传递版本时,API版本控制能够正常工作。虽然是使用
Maven
实现的,但我想它可以作为一个起点帮助您。仅供参考,我已经使用
springboot
Jersey
Swagger
springboot
CXF
Swagger
来记录API,而不是
springmvc
Swagger

使用此插件也可能适用于您:

<properties>
    <swagger-maven-plugin.version>3.1.3</swagger-maven-plugin.version>
</properties>
 ...
<plugin>
  <groupId>com.github.kongchen</groupId>
  <artifactId>swagger-maven-plugin</artifactId>
  <version>${swagger-maven-plugin.version}</version>
  <configuration>
    <apiSources>
      <!-- Version 1 -->
      <apiSource>
        <springmvc>false</springmvc>
        <locations>com.asimio.swaggerexample.rest.v1</locations>
        <schemes>http,https</schemes>
        <basePath>/api</basePath>
        <info>
          <title>Multiversion Spring Boot + Jersey + Swagger Demo (Version 1)</title>
          <version>v1</version>
          <description>A multi-version demo (version 1) of a RESTful service using Spring Boot, Jersey and Swagger.</description>
          <termsOfService>http://www.github.com/kongchen/swagger-maven-plugin</termsOfService>
          <contact>
            <email>xxxx@xxxx.xxx</email>
            <name>Orlando L Otero</name>
            <url>http://tech.asimio.net</url>
          </contact>
          <license>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
            <name>Apache 2.0</name>
          </license>
        </info>
        <outputFormats>json</outputFormats>
        <swaggerDirectory>${basedir}/target/classes/static/v1</swaggerDirectory>
        <swaggerApiReader>com.github.kongchen.swagger.docgen.reader.JaxrsReader</swaggerApiReader>
      </apiSource>
      <!-- Version 2 -->
...

3.1.3
...
com.github.kongchen

pffff。。。可以看来还有很长的路要走。这几天我将尝试一些想法和gradle插件。。。。