-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test suite for micronaut-openapi with spring-boot application.
Added documentation how to use micronaut-openapi with Spring applications
- Loading branch information
Showing
26 changed files
with
608 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You can use `micronaut-openapi` to build openapi specification for `Spring` / `Spring Boot` applications. In this case, you do not need to change anything in the code. You can continue to use spring, and use micronaut as a replacement for such libraries as `springdoc-openapi`, `springfox`, `swagger` etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
To use micronaut-openapi with spring in gradle add this code to you `build.gradle`: | ||
|
||
.build.gradle | ||
[source,groovy] | ||
---- | ||
dependencies { | ||
// add to annotationProcessor and compileOnly blocks next libraries: | ||
annotationProcessor("io.micronaut:micronaut-inject-java:$micronautCoreVersion") | ||
annotationProcessor("io.micronaut.spring:micronaut-spring-annotation:$micronautSpringVersion") | ||
annotationProcessor("io.micronaut.spring:micronaut-spring-web-annotation:$micronautSpringVersion") | ||
annotationProcessor("io.micronaut.spring:micronaut-spring-boot-annotation:$micronautSpringVersion") | ||
annotationProcessor("io.micronaut.openapi:micronaut-openapi:$micronautOpenapiVersion") | ||
compileOnly("io.micronaut:micronaut-inject-java:$micronautCoreVersion") | ||
compileOnly("io.micronaut.openapi:micronaut-openapi-annotations:$micronautOpenapiVersion") | ||
compileOnly("io.micronaut.serde:micronaut-serde-api:$micronautSerdeVersion") | ||
} | ||
---- | ||
|
||
For kotlin just change block `annotationProcessor` to `kapt` or `ksp`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
To use micronaut-openapi with spring in maven add this code to your `pom.xml` | ||
|
||
.pom.xml | ||
[source,xml] | ||
---- | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.micronaut</groupId> | ||
<artifactId>micronaut-inject-java</artifactId> | ||
<version>${micronaut.core.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micronaut.openapi</groupId> | ||
<artifactId>micronaut-openapi-annotations</artifactId> | ||
<version>${micronaut.openapi.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micronaut.serde</groupId> | ||
<artifactId>micronaut-serde-api</artifactId> | ||
<version>${micronaut.serde.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths combine.children="append"> | ||
<path> | ||
<groupId>io.micronaut</groupId> | ||
<artifactId>micronaut-inject-java</artifactId> | ||
<version>${micronaut.core.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-web-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-boot-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.micronaut.openapi</groupId> | ||
<artifactId>micronaut-openapi</artifactId> | ||
<version>${micronaut.openapi.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
---- | ||
|
||
For kotlin | ||
.pom.xml | ||
[source,xml] | ||
---- | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.micronaut</groupId> | ||
<artifactId>micronaut-inject-java</artifactId> | ||
<version>${micronaut.core.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micronaut.openapi</groupId> | ||
<artifactId>micronaut-openapi-annotations</artifactId> | ||
<version>${micronaut.openapi.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micronaut.serde</groupId> | ||
<artifactId>micronaut-serde-api</artifactId> | ||
<version>${micronaut.serde.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<executions> | ||
<execution> | ||
<id>kapt</id> | ||
<goals> | ||
<goal>kapt</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir> | ||
</sourceDirs> | ||
<annotationProcessorPaths combine.self="override"> | ||
<annotationProcessorPath> | ||
<groupId>io.micronaut</groupId> | ||
<artifactId>micronaut-inject-java</artifactId> | ||
<version>${micronaut.core.version}</version> | ||
</annotationProcessorPath> | ||
<annotationProcessorPath> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</annotationProcessorPath> | ||
<annotationProcessorPath> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-web-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</annotationProcessorPath> | ||
<annotationProcessorPath> | ||
<groupId>io.micronaut.spring</groupId> | ||
<artifactId>micronaut-spring-boot-annotation</artifactId> | ||
<version>${micronaut.spring.version}</version> | ||
</annotationProcessorPath> | ||
<annotationProcessorPath> | ||
<groupId>io.micronaut.openapi</groupId> | ||
<artifactId>micronaut-openapi</artifactId> | ||
<version>${micronaut.openapi.version}</version> | ||
</annotationProcessorPath> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To use micronaut openapi views (Swagger UI, OpenAPi Explorer, Redoc, RapiDoc) you need to add static resources to Spring configuration like this: | ||
|
||
.Example Swagger UI resources routing config | ||
snippet::io.micronaut.openapi.spring.WebConfig[tags="imports,clazz", project-base="test-suite-java-spring"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../io/micronaut/open/jaxrs/Application.java → .../micronaut/openapi/jaxrs/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ronaut/open/jaxrs/OpenApiExposedTest.java → ...aut/openapi/jaxrs/OpenApiExposedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...naut/open/jaxrs/OpenApiGeneratedTest.java → ...t/openapi/jaxrs/OpenApiGeneratedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../micronaut/open/jaxrs/TestController.java → ...cronaut/openapi/jaxrs/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ronaut/open/jaxrs/TestControllerTest.java → ...aut/openapi/jaxrs/TestControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.openapi-test-java") | ||
} | ||
|
||
sourceSets { | ||
test { | ||
java { | ||
srcDirs += "$buildDir/classes/java" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
annotationProcessor(mnSpring.micronaut.spring.annotation) | ||
annotationProcessor(mnSpring.micronaut.spring.web.annotation) | ||
annotationProcessor(mnSpring.micronaut.spring.boot.annotation) | ||
annotationProcessor(mn.micronaut.inject.java) | ||
annotationProcessor(projects.micronautOpenapi) | ||
|
||
compileOnly(projects.micronautOpenapiAnnotations) | ||
compileOnly(mn.jackson.annotations) | ||
compileOnly(mn.micronaut.inject.java) | ||
compileOnly(mnSerde.micronaut.serde.api) | ||
|
||
implementation(spring.spring.springBootStarterWeb) | ||
implementation(spring.spring.springBootStarterValidation) | ||
implementation(spring.spring.springBootStarterDataRest) | ||
|
||
testCompileOnly(projects.micronautOpenapiAnnotations) | ||
testCompileOnly(mn.jackson.annotations) | ||
testCompileOnly(mn.micronaut.inject.java) | ||
testCompileOnly(mnSerde.micronaut.serde.api) | ||
|
||
testImplementation(spring.spring.springBootStarterTest) | ||
testImplementation(mnTest.junit.jupiter.api) | ||
testImplementation(projects.micronautOpenapiCommon) | ||
|
||
testRuntimeOnly(mnLogging.logback.classic) | ||
testRuntimeOnly(mnTest.junit.jupiter.engine) | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
options.encoding = "UTF-8" | ||
options.incremental = true | ||
options.fork = true | ||
options.compilerArgs = [ | ||
'-parameters', | ||
'-Xlint:unchecked', | ||
'-Xlint:deprecation' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
micronaut.openapi.views.spec=swagger-ui.enabled=true |
23 changes: 23 additions & 0 deletions
23
test-suite-java-spring/src/main/java/io/micronaut/openapi/spring/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.micronaut.openapi.spring; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import org.springframework.boot.Banner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@OpenAPIDefinition( | ||
info = @Info( | ||
title = "demo", | ||
version = "0.0" | ||
) | ||
) | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
var application = new SpringApplication(Application.class); | ||
application.setBannerMode(Banner.Mode.OFF); | ||
application.run(args); | ||
} | ||
} |
Oops, something went wrong.