'How to bundle all swagger files into one using Java and Maven
I'm using Java 8, Spring Boot and Maven.
I have a big OpenAPI file (swagger 2.0 yaml), and I want to split it in multiple files.
But I want to bundle all in one file latter to import into my API Manager.
I know I can do that using the node.js command:
swagger-cli bundle openapi.yaml --outfile _build/openapi.yaml --type yaml
Reference: https://davidgarcia.dev/posts/how-to-split-open-api-spec-into-multiple-files/
Question:
There is a way to do that with Maven? Like some builder plugin to put in pom.xml and generate the bundle at the target folder?
Solution 1:[1]
Swagger Codegen Maven plugin can bundle a multi-file OpenAPI definition into a single file. Use plugin version 2.x for OpenAPI 2.0, and version 3.x for OpenAPI 3.0. Note that the 2.x and 3.x versions have different groupIds and slightly different config values.
Example for OpenAPI 2.0:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.26</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<!-- Use 'swagger-yaml' to get resolved YAML or 'swagger' to get resolved JSON -->
<language>swagger-yaml</language>
<configOptions>
<!-- Default file name is swagger.yaml or swagger.json -->
<outputFile>openapi.yaml</outputFile>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Example for OpenAPI 3.0:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.33</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<!-- Use 'openapi-yaml' to get resolved YAML or 'openapi' to get resolved JSON -->
<language>openapi-yaml</language>
<!-- Default is ${project.build.directory}/generated-sources/swagger -->
<output>_build</output>
<configOptions>
<!-- Default file name is openapi.yaml or openapi.json -->
<outputFile>openapi.yaml</outputFile>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Helen |
