Skip to content

Instantly share code, notes, and snippets.

@dehidehidehi
Created July 3, 2024 12:41
Show Gist options
  • Save dehidehidehi/a2a4673459ed9c229498d4210309ebb8 to your computer and use it in GitHub Desktop.
Save dehidehidehi/a2a4673459ed9c229498d4210309ebb8 to your computer and use it in GitHub Desktop.
Maven - Autogeneration of OpenAPI specification in Json format after integration test phase
<profiles>
<profile>
<!-- Profil dédié pour la génération du json OpenAPI -->
<id>springdocs</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<springdocs.host>http://localhost</springdocs.host>
<springdocs.port>9191</springdocs.port>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-starter-webmvc-ui.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Dserver.port=${springdocs.port} -Dspring.profiles.active=test -Dspring.application.admin.enabled=true -Dspring.banner.location=classpath:banners/banner-openapi.txt</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>
<!-- Ensure generation of OpenAPI json specification -->
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>${org.springdoc-version}</version>
<configuration>
<apiDocsUrl>
${springdocs.host}:${springdocs.port}/v3/api-docs
</apiDocsUrl>
<outputFileName>openapi.json</outputFileName>
<outputDir>${project.build.directory}/springdoc</outputDir>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment