-
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 all 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
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
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
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
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
109 changes: 109 additions & 0 deletions
109
...openapi/generator/deployment/codegen/YamlOrJsonGAVCoordinateOpenApiSpecInputProvider.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,109 @@ | ||
| package io.quarkiverse.openapi.generator.deployment.codegen; | ||
|
|
||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getGlobalConfigName; | ||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.ARTIFACT_ID_FILTER; | ||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.EXCLUDE_GAVS; | ||
| import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.GAV_SCANNING; | ||
| import static io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorCodeGenBase.SUPPORTED_EXTENSIONS; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import io.quarkus.bootstrap.prebuild.CodeGenException; | ||
| import io.quarkus.deployment.CodeGenContext; | ||
| import io.quarkus.maven.dependency.ResolvedDependency; | ||
| import io.smallrye.config.common.utils.StringUtil; | ||
|
|
||
| /** | ||
| * Provides OpenAPI specification input from Maven GAV (GroupId:ArtifactId:Version) coordinates. | ||
| * <p> | ||
| * This provider scans the application's dependencies for YAML or JSON files that match | ||
| * specific criteria and provides them as input for OpenAPI code generation. It implements | ||
| * the {@link OpenApiSpecInputProvider} interface to integrate with the OpenAPI Generator's | ||
| * code generation pipeline. | ||
| * </p> | ||
| * | ||
| * <h2>Scanning Behavior</h2> | ||
| * <p> | ||
| * The provider performs the following steps: | ||
| * </p> | ||
| * <ol> | ||
| * <li>Checks if GAV scanning is enabled via configuration (enabled by default)</li> | ||
| * <li>Filters dependencies by artifact type (yaml/yml/json)</li> | ||
| * <li>Applies artifact ID filtering using a regex pattern</li> | ||
| * <li>Excludes specific GAVs based on configuration</li> | ||
| * <li>Creates {@link SpecInputModel} instances for each matching dependency</li> | ||
| * </ol> | ||
| * | ||
| * <h2>Configuration</h2> | ||
| * <p> | ||
| * The provider respects the following configuration properties: | ||
| * </p> | ||
| * <ul> | ||
| * <li>{@code quarkus.openapi-generator.codegen.gav-scanning} - Enable/disable GAV scanning</li> | ||
| * <li>{@code quarkus.openapi-generator.codegen.artifact-id-filter} - Regex pattern for artifact ID filtering</li> | ||
| * <li>{@code quarkus.openapi-generator.codegen.exclude-gavs} - List of GAV coordinates to exclude | ||
| * (format: groupId:artifactId:classifier)</li> | ||
| * </ul> | ||
| * | ||
| * <h2>Example Usage</h2> | ||
| * | ||
| * <pre> | ||
| * # application.properties | ||
| * quarkus.openapi-generator.codegen.gav-scanning=true | ||
| * quarkus.openapi-generator.codegen.artifact-id-filter=.*api.* | ||
| * quarkus.openapi-generator.codegen.exclude-gavs=com.example:old-api | ||
| * </pre> | ||
| * | ||
| * @see OpenApiSpecInputProvider | ||
| * @see SpecInputModel | ||
| * @see CodeGenContext | ||
| */ | ||
| public class YamlOrJsonGAVCoordinateOpenApiSpecInputProvider implements OpenApiSpecInputProvider { | ||
| private static final Logger LOG = Logger.getLogger(YamlOrJsonGAVCoordinateOpenApiSpecInputProvider.class); | ||
|
|
||
| @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(); | ||
| } | ||
|
|
||
| List<String> gavsToExclude = context.config().getOptionalValues(getGlobalConfigName(EXCLUDE_GAVS), String.class) | ||
| .orElse(List.of()); | ||
| String artifactIdFilter = context.config().getOptionalValue(getGlobalConfigName(ARTIFACT_ID_FILTER), String.class) | ||
| .filter(Predicate.not(String::isBlank)) | ||
| .orElse(".*openapi.*"); | ||
|
|
||
| List<ResolvedDependency> yamlDependencies = context.applicationModel().getDependencies().stream() | ||
| .filter(rd -> SUPPORTED_EXTENSIONS.contains(rd.getType().toLowerCase())) | ||
| .filter(rd -> rd.getArtifactId().matches(artifactIdFilter)) | ||
| .filter(rd -> !gavsToExclude.contains(rd.getKey().toGacString())) | ||
| .toList(); | ||
|
|
||
| if (yamlDependencies.isEmpty()) { | ||
| LOG.debug("No suitable GAV dependencies found. ArtifactIdFilter was %s and gavsToExclude were %s." | ||
| .formatted(artifactIdFilter, gavsToExclude)); | ||
| return List.of(); | ||
| } | ||
| var inputModels = new ArrayList<SpecInputModel>(); | ||
| for (ResolvedDependency yamlDependency : yamlDependencies) { | ||
| var gacString = StringUtil.replaceNonAlphanumericByUnderscores(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; | ||
| } | ||
| } | ||
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.YamlOrJsonGAVCoordinateOpenApiSpecInputProvider |
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,67 @@ | ||
| <?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>package</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/echo.yaml</file> | ||
| <packaging>yaml</packaging> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>install-echo2</id> | ||
| <goals> | ||
| <goal>install-file</goal> | ||
| </goals> | ||
| <phase>package</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/echo.yaml</file> | ||
| <packaging>yaml</packaging> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>install-other</id> | ||
| <goals> | ||
| <goal>install-file</goal> | ||
| </goals> | ||
| <phase>package</phase> | ||
| <configuration> | ||
| <artifactId>quarkus-openapi-generator-gav-source-other</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| <file>src/main/openapi/echo.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/echo.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 |
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.