GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - springdoc/springdoc-openapi-maven-plugin: Library for OpenAPI 3 with spring-boot

BranchesTags
Open more actions menu

Latest commit

 

History

158 Commits
158 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.mvn/wrapper
.mvn/wrapper
 
 
src
src
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.adoc
CONTRIBUTING.adoc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mvnw
mvnw
 
 
mvnw.cmd
mvnw.cmd
 
 
pom.xml
pom.xml
 
 

Repository files navigation

springdoc-openapi

๐Ÿ“ฆ Generate the OpenAPI description of your Spring Boot application at build time, with Maven

Build Maven Central License GitHub stars Stack Overflow

Maven plugin Java 8+ OpenAPI JSON and YAML Swagger UI site report

๐Ÿ“– Documentation ยท ๐Ÿš€ Getting started ยท โš™๏ธ Configuration ยท ๐Ÿ“Š Site report ยท ๐Ÿƒ springdoc-openapi

๐Ÿ’– Sponsored by

Mercedes-Benz    dmTECH    Contrast Security    LVM Versicherung    GDNext

Sponsor on GitHub Support on Open Collective

If you โค๏ธ springdoc-openapi, become a sponsor: it covers the project expenses and helps it grow.


springdoc-openapi-maven-plugin writes the OpenAPI description of your application to a file during the build, so you can commit it, diff it, publish it with your artifacts, or feed it to code generators. โœจ

It works together with the spring-boot-maven-plugin: the application is started before the integration tests, the plugin downloads the description that springdoc-openapi serves at /v3/api-docs, and the application is stopped again. Because the description comes from the running application, it is exactly what springdoc-openapi serves at runtime.

๐Ÿš€ Getting started

Add both plugins to the <build><plugins> section of your pom.xml:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
  </configuration>
  <executions>
    <execution>
      <id>pre-integration-test</id>
      <goals>
        <goal>start</goal>
      </goals>
    </execution>
    <execution>
      <id>post-integration-test</id>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-maven-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Then run:

mvn verify

๐Ÿ‘‰ The description is written to target/openapi.json.

๐Ÿงญ Compatibility

The plugin only calls an HTTP endpoint, so it works with any application that serves an OpenAPI description:

Spring Boot springdoc-openapi
๐Ÿƒ 4.x 3.x
๐Ÿƒ 3.x 2.x
๐Ÿ‚ 2.x and 1.x 1.x

The plugin runs on Java 8 and later, with Maven 3.6.3 and later.

๐ŸŽฏ Goals

Goal Default phase Description
springdoc-openapi:generate integration-test Downloads the OpenAPI description from the running application and writes it to a file
springdoc-openapi:report site Adds a Swagger UI page to the Maven site, see Site report (since 1.6)

โš™๏ธ Configuration

Each parameter of the generate goal can also be set from the command line with its user property, for example mvn verify -Dspringdoc.skip=true.

Parameter User property Default Description
apiDocsUrl springdoc.apiDocsUrl http://localhost:8080/v3/api-docs URL of the OpenAPI description (JSON or YAML)
outputFileName springdoc.outputFileName openapi.json Name of the generated file
outputDir springdoc.outputDir ${project.build.directory} Directory of the generated file
attachArtifact springdoc.attachArtifact false Attach the file to the project, so it is installed and deployed with the other artifacts (classifier openapi)
attachArtifactClassifier springdoc.attachArtifactClassifier openapi Classifier of the attached file
headers none HTTP headers sent with the request, for example for authentication
timeout springdoc.timeout 60 Connect and read timeout of the request, in seconds (0 for none)
skip springdoc.skip false Skip the execution
failOnError springdoc.failOnError false Fail the build if the description cannot be downloaded or written
<plugin>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-maven-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
    <outputFileName>openapi.json</outputFileName>
    <outputDir>${project.build.directory}/openapi</outputDir>
    <attachArtifact>true</attachArtifact>
    <failOnError>true</failOnError>
    <headers>
      <Authorization>Bearer my-token</Authorization>
    </headers>
  </configuration>
</plugin>

Tip

Set failOnError to true on CI. By default, a failure is only logged, and the build goes on without the file.

When the build fails, Maven skips spring-boot:stop, so the application keeps running. Stop it before the next build, or it answers the next build's requests instead of the new application.

๐Ÿ’ก Recipes

  • ๐Ÿ“„ YAML: point apiDocsUrl to http://localhost:8080/v3/api-docs.yaml and set outputFileName to openapi.yaml.

  • ๐Ÿ—‚๏ธ Groups: add one <execution> per group, each with its own apiDocsUrl (for example http://localhost:8080/v3/api-docs/admin) and outputFileName, and its own attachArtifactClassifier if the files are attached.

  • โœจ Pretty-printed JSON: the file is saved exactly as served, so enable springdoc.writer-with-default-pretty-printer=true in the application, for example in the spring-boot-maven-plugin configuration:

    <arguments>
      <argument>--springdoc.writer-with-default-pretty-printer=true</argument>
    </arguments>
  • ๐Ÿ”Œ Another port: change the port of the application and apiDocsUrl together, for example -Dspring-boot.run.arguments=--server.port=9090 -Dspringdoc.apiDocsUrl=http://localhost:9090/v3/api-docs.

๐Ÿ“Š Site report

Note

The report goal is available since version 1.6.

The report goal adds an OpenAPI Documentation page, rendered with Swagger UI, under Project Reports in the Maven site. It reads the file written by the generate goal (by default target/openapi.json), and if that file does not exist, it fetches the description from apiDocsUrl.

Add the plugin to the <reporting> section of your pom.xml:

<reporting>
  <plugins>
    <plugin>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-maven-plugin</artifactId>
      <version>1.6</version>
      <reportSets>
        <reportSet>
          <reports>
            <report>report</report>
          </reports>
        </reportSet>
      </reportSets>
    </plugin>
  </plugins>
</reporting>

Then generate the description and the site in the same build:

mvn verify site

๐Ÿ‘‰ The page is written to target/site/springdoc-openapi/index.html.

Parameter User property Default Description
apiDocsFile springdoc.apiDocsFile ${project.build.directory}/openapi.json File written by the generate goal
apiDocsUrl springdoc.apiDocsUrl http://localhost:8080/v3/api-docs URL used when apiDocsFile does not exist
headers none HTTP headers sent with the request to apiDocsUrl
timeout springdoc.timeout 60 Connect and read timeout of the request to apiDocsUrl, in seconds
siteReportName springdoc.report.name OpenAPI Documentation Name in the Project Reports menu
siteReportDescription springdoc.report.description OpenAPI specification rendered with Swagger UI Description in the Project Reports page
siteReportDirectory springdoc.report.directory springdoc-openapi Directory of the page in the site
swaggerUiVersion springdoc.swaggerUiVersion 5.34.1 Swagger UI version, loaded from unpkg.com
skip springdoc.report.skip false Skip the report

Important

The report needs maven-site-plugin 3.9.1 or later. Maven 3.9 uses 3.12.1 by default; with an older Maven, set the version of maven-site-plugin in your pom.xml.

The report only supports a JSON description (/v3/api-docs), not YAML. The Swagger UI files are loaded from unpkg.com, so the page needs internet access when it is viewed.

๐Ÿ’ฌ Getting help

  • ๐Ÿ“– Read the plugin documentation and the springdoc-openapi documentation
  • ๐Ÿ™‹ Ask questions on Stack Overflow with the springdoc tag
  • ๐Ÿ› Report bugs in GitHub issues, with a minimal reproducer

Note

springdoc-openapi is a community project, not maintained by the Spring team.

๐Ÿค Contributing

Contributions are welcome! See CONTRIBUTING.adoc and the Code of Conduct.

To build the plugin and install it in your local Maven repository:

./mvnw install

Thanks to all our contributors ๐Ÿ™

Contributors

Special thanks to JetBrains for their support.

JetBrains logo

๐Ÿ“„ License

springdoc-openapi-maven-plugin is Open Source software released under the Apache 2.0 license.

About

Library for OpenAPI 3 with spring-boot

springdoc.org

Resources

Readme
Apache-2.0 license

Contributing

Contributing
Activity
Custom properties

Stars

168 stars

Watchers

4 watching

Forks

43 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.