-
Notifications
You must be signed in to change notification settings - Fork 113
Support GAV coordinates for client generation #1340 #1343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
88fbb63
Support GAV coordinates for client generation #1340
e548895
Support GAV coordinates for client generation #1340
584879d
Merge branch 'quarkiverse:main' into main
michaelsonnleitner a517c47
avoid star imports
9a22578
Merge remote-tracking branch 'origin/main'
10eb296
SUPPORTED_EXTENSIONS refactored for better use
d8e7d8f
add filter for artifactIds & improved config naming(singular/plural) …
c69287e
windows problem with colon in filename & extended test with specific …
3c96030
use verify phase to store artifacts to local mvn repo to get website …
596b261
renaming and javadoc
20bd8c4
use package phase for artifact installation to get codeql action running
0be4068
Merge branch 'quarkiverse:main' into main
michaelsonnleitner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
...arkiverse/openapi/generator/deployment/codegen/GAVCoordinateOpenApiSpecInputProvider.java
This file contains hidden or 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,58 @@ | ||
| package io.quarkiverse.openapi.generator.deployment.codegen; | ||
|
|
||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.*; | ||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.*; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import io.quarkus.bootstrap.prebuild.CodeGenException; | ||
| import io.quarkus.deployment.CodeGenContext; | ||
| import io.quarkus.maven.dependency.ResolvedDependency; | ||
|
|
||
| public class GAVCoordinateOpenApiSpecInputProvider implements OpenApiSpecInputProvider { | ||
| private static final Logger LOG = Logger.getLogger(GAVCoordinateOpenApiSpecInputProvider.class); | ||
|
|
||
| private static final Set<String> SUPPORTED_EXTENSIONS = Set.of("yaml", "yml", "json"); | ||
michaelsonnleitner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public List<SpecInputModel> read(CodeGenContext context) throws CodeGenException { | ||
| if (!context.config().getOptionalValue(getGlobalConfigName(GAV_SCANNING), Boolean.class) | ||
| .orElse(true)) { | ||
| LOG.debug("GAV scanning is disabled."); | ||
| return List.of(); | ||
| } | ||
|
|
||
| // Q: maybe a configuration property to enable GAV scanning (default: true) | ||
| List<String> gavsToExclude = context.config().getOptionalValues(getGlobalConfigName(EXCLUDE_GAV), String.class) | ||
| .orElse(List.of()); | ||
|
|
||
| List<ResolvedDependency> yamlDependencies = context.applicationModel().getDependencies().stream() | ||
| .filter(rd -> SUPPORTED_EXTENSIONS.contains(rd.getType())) | ||
| .filter(rd -> !gavsToExclude.contains(rd.getKey().toGacString())) | ||
| .toList(); | ||
|
|
||
| if (yamlDependencies.isEmpty()) { | ||
| LOG.debug("No suitable GAV dependencies found."); | ||
| return List.of(); | ||
| } | ||
| var inputModels = new ArrayList<SpecInputModel>(); | ||
| for (ResolvedDependency yamlDependency : yamlDependencies) { | ||
| var gacString = yamlDependency.getKey().toGacString(); | ||
| var path = yamlDependency.getResolvedPaths().stream().findFirst() | ||
| .orElseThrow(() -> new CodeGenException("Could not find maven path of %s.".formatted(gacString))); | ||
| try { | ||
| inputModels.add(new SpecInputModel(gacString, Files.newInputStream(path))); | ||
| } catch (IOException e) { | ||
| throw new CodeGenException("Could not open input stream of %s from %s.".formatted(gacString, path.toString()), | ||
| e); | ||
| } | ||
| } | ||
| return inputModels; | ||
| } | ||
| } | ||
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
...INF/services/io.quarkiverse.openapi.generator.deployment.codegen.OpenApiSpecInputProvider
This file contains hidden or 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 @@ | ||
| io.quarkiverse.openapi.generator.deployment.codegen.GAVCoordinateOpenApiSpecInputProvider |
This file contains hidden or 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,53 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>quarkus-openapi-generator-integration-tests</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>quarkus-openapi-generator-gav-source</artifactId> | ||
| <name>Quarkus - OpenAPI Generator - Integration Tests - Client - GAV source</name> | ||
| <description>Example project for OpenAPI with GAV source</description> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-install-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>install-echo1</id> | ||
| <goals> | ||
| <goal>install-file</goal> | ||
| </goals> | ||
| <phase>install</phase> | ||
| <configuration> | ||
| <artifactId>quarkus-openapi-generator-gav-source-echo1</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| <file>src/main/openapi/echo1.yaml</file> | ||
| <packaging>yaml</packaging> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>install-echo2</id> | ||
| <goals> | ||
| <goal>install-file</goal> | ||
| </goals> | ||
| <phase>install</phase> | ||
| <configuration> | ||
| <artifactId>quarkus-openapi-generator-gav-source-echo2</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| <file>src/main/openapi/echo2.yaml</file> | ||
| <packaging>yaml</packaging> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
34 changes: 34 additions & 0 deletions
34
client/integration-tests/gav-source/src/main/openapi/echo1.yaml
This file contains hidden or 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,34 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: echo | ||
| version: '1.0.0' | ||
| description: "" | ||
| paths: | ||
| /echo: | ||
| post: | ||
| summary: Echo | ||
| operationId: echo | ||
| requestBody: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Message" | ||
| responses: | ||
| "200": | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Echo' | ||
| components: | ||
| schemas: | ||
| Echo: | ||
| type: object | ||
| properties: | ||
| echo: | ||
| type: string | ||
| Message: | ||
| type: object | ||
| properties: | ||
| message: | ||
| type: string |
34 changes: 34 additions & 0 deletions
34
client/integration-tests/gav-source/src/main/openapi/echo2.yaml
This file contains hidden or 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,34 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: echo | ||
| version: '1.0.0' | ||
| description: "" | ||
| paths: | ||
| /echo: | ||
| post: | ||
| summary: Echo | ||
| operationId: echo | ||
| requestBody: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Message" | ||
| responses: | ||
| "200": | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Echo' | ||
| components: | ||
| schemas: | ||
| Echo: | ||
| type: object | ||
| properties: | ||
| echo: | ||
| type: string | ||
| Message: | ||
| type: object | ||
| properties: | ||
| message: | ||
| type: string |
This file contains hidden or 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,105 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>quarkus-openapi-generator-integration-tests</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>quarkus-openapi-generator-it-gav</artifactId> | ||
| <name>Quarkus - OpenAPI Generator - Integration Tests - Client - GAV</name> | ||
| <description>Example project for OpenAPI via GAV coordinates</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <artifactId>quarkus-openapi-generator</artifactId> | ||
| </dependency> | ||
| <!-- include yaml GAV coordinates --> | ||
| <!-- echo1 should be generated --> | ||
| <dependency> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <artifactId>quarkus-openapi-generator-gav-source-echo1</artifactId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| <type>yaml</type> | ||
| </dependency> | ||
| <!-- echo2 will be excluded during test --> | ||
| <dependency> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <artifactId>quarkus-openapi-generator-gav-source-echo2</artifactId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| <type>yaml</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-junit5</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-maven-plugin</artifactId> | ||
| <extensions>true</extensions> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>build</goal> | ||
| <goal>generate-code</goal> | ||
| <goal>generate-code-tests</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <profiles> | ||
| <profile> | ||
| <id>native-image</id> | ||
| <activation> | ||
| <property> | ||
| <name>native</name> | ||
| </property> | ||
| </activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <skipTests>${native.surefire.skip}</skipTests> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-failsafe-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>integration-test</goal> | ||
| <goal>verify</goal> | ||
| </goals> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
| <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
| <maven.home>${maven.home}</maven.home> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <properties> | ||
| <quarkus.package.type>native</quarkus.package.type> | ||
| </properties> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| </project> |
3 changes: 3 additions & 0 deletions
3
client/integration-tests/gav/src/main/resources/application.properties
This file contains hidden or 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,3 @@ | ||
| quarkus.keycloak.devservices.enabled=false | ||
|
|
||
| quarkus.openapi-generator.codegen.exclude-gav=io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-echo2 |
23 changes: 23 additions & 0 deletions
23
...on-tests/gav/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusGAVOpenApiTest.java
This file contains hidden or 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.quarkiverse.openapi.generator.it; | ||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class QuarkusGAVOpenApiTest { | ||
| @Test | ||
| void apiIsBeingGenerated() { | ||
| assertThatCode( | ||
| () -> Class.forName( | ||
| "org.openapi.quarkus.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_echo1.api.DefaultApi")) | ||
| .doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void apiIsBeingNotGenerated() { | ||
| assertThatCode( | ||
| () -> Class.forName( | ||
| "org.openapi.quarkus.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_echo2.api.DefaultApi")) | ||
| .isInstanceOf(ClassNotFoundException.class); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.