OpenAPI Flashcards
OpenApi specification generation (code first )
OpenUse Springdoc v2 for Spring framwork 6 (via reflection)
https://springdoc.org/
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-common</artifactId>
<version>2.2.0</version>
</dependency>
In order to use this functionality, you need to add the plugin declaration on the plugins section of your pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
<configuration>
<jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Testing
Atlassian Swagger Request Validator - a rich library for testing HTTP requests and responses against an OpenApi specs
–> doesn not support SpringFramework6((delivered in Q1 2023??)) or WebFLux????
–> verifies specs in integration tests, Pact contracts or with RestAssured
For code generation
- there is a maven plugin
- usefull for consuming 3rd party APis with OpenAPI specs
- can be used generate client side code(the quality depends on the quality of the specs)
- generate server stubs
- generate request/response POJO(usefull to generate in a common module that is shared across other projects)