首页 文章

使用springfox,swagger和gradle生成静态文档[重复]

提问于
浏览
0

这个问题在这里已有答案:

我已经在一个简单的Spring Boot应用程序中评估了 springfox 的集成,暴露了一些REST API . 乍看之下一切正常 - 当应用程序启动时,我可以在JSON endpoints 看到Swagger规范,我可以连接并使用Swagger UI,Swagger注释被考虑在内,我可以使用代码生成静态HTML文档gen等等等

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

例如: code base -> build -> (executable jar + documentation + ... )

1 回答

  • 1

    我必须在构建时生成 swagger.json 文件,以便在传递 Accept 标头中的版本时处理API版本以正常工作 . 尽管如此使用 Maven 但我想它可以帮助你作为一个起点 . 仅供参考,我已经完成了使用 Spring BootJerseySwaggerSpring BootCXFSwagger 而不是 Spring MVCSwaggerspringfox 来记录API .

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

    <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 -->
    ...
    

    更多详情请访问:Documenting multiple REST API versions using Spring Boot, Jersey and Swagger

相关问题