Skip to content

Commit 05456ff

Browse files
author
Michael Sonnleitner
committed
added include-gavs option & docu
1 parent 8e7ccf8 commit 05456ff

File tree

9 files changed

+159
-1
lines changed

9 files changed

+159
-1
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum ConfigName {
4040
INCLUDE("include"),
4141
EXCLUDE("exclude"),
4242
ARTIFACT_ID_FILTER("artifact-id-filter"),
43+
INCLUDE_GAVS("include-gavs"),
4344
EXCLUDE_GAVS("exclude-gavs"),
4445
VALIDATE_SPEC("validateSpec"),
4546
DEFAULT_SECURITY_SCHEME("default-security-scheme"),

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ public interface GlobalCodegenConfig extends CommonItemConfig {
7474
@WithName("exclude-gavs")
7575
Optional<List<String>> excludeGavs();
7676

77+
/**
78+
* Option to specify GAVs for which generation should be executed only.
79+
*
80+
* Depending on the GAV Provider default behavior differs:
81+
* <ul>
82+
* <li>for {@link io.quarkiverse.openapi.generator.deployment.codegen.YamlOrJsonGAVCoordinateOpenApiSpecInputProvider}, all
83+
* suitable GAVs will be considered for generation if config value is not given</li>
84+
* <li>for {@link io.quarkiverse.openapi.generator.deployment.codegen.JarOrZipGAVCoordinateOpenApiSpecInputProvider}, only
85+
* specified GAVs will be considered for generation if config value is available</li>
86+
* </ul>
87+
*/
88+
@WithName("include-gavs")
89+
Optional<List<String>> includeGavs();
90+
7791
/**
7892
* Create security for the referenced security scheme
7993
*/

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/AbstractGAVCoordinateOpenApiSpecInputProvider.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public List<SpecInputModel> read(CodeGenContext context) throws CodeGenException
3737
.filter(rd -> getSupportedExtensions().contains(rd.getType().toLowerCase()))
3838
.filter(rd -> rd.getArtifactId().matches(artifactIdFilter))
3939
.filter(rd -> !gavsToExclude.contains(rd.getKey().toGacString()))
40+
.filter(rd -> specificGAVSpecInputProviderFilter(context, rd.getKey().toGacString()))
4041
.toList();
4142

4243
if (dependencies.isEmpty()) {
@@ -57,8 +58,30 @@ public List<SpecInputModel> read(CodeGenContext context) throws CodeGenException
5758

5859
protected abstract Set<String> getSupportedExtensions();
5960

61+
/**
62+
* Adds input models to the provided list based on the given context, GAC string, and path.
63+
* This method is implemented by subclasses to generate or retrieve the appropriate
64+
* {@code SpecInputModel} instances that will be processed during code generation.
65+
*
66+
* @param context the code generation context, providing access to configuration and utilities
67+
* @param gacString the GAC (Group, Artifact, Classifier) string representing the dependency identifier
68+
* @param path the path to the file or directory containing the input specification(s)
69+
* @param inputModels the list to which the generated {@code SpecInputModel} instances are added
70+
* @throws CodeGenException if an error occurs while processing the input specifications
71+
*/
6072
protected abstract void addInputModels(CodeGenContext context,
6173
String gacString,
6274
Path path,
6375
List<SpecInputModel> inputModels) throws CodeGenException;
76+
77+
/**
78+
* Filters dependencies based on specific criteria defined in the implementing class.
79+
* This method is invoked as part of the dependency resolution process to determine
80+
* whether a dependency identified by its GAC string should be included for further processing.
81+
*
82+
* @param context the code generation context, providing access to configuration and other utilities
83+
* @param gacString the GAC (Group, Artifact, Classifier) string representing the dependency identifier
84+
* @return true if the dependency matches the filter criteria and should be included; false otherwise
85+
*/
86+
protected abstract boolean specificGAVSpecInputProviderFilter(CodeGenContext context, String gacString);
6487
}

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/JarOrZipGAVCoordinateOpenApiSpecInputProvider.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Paths;
1010
import java.util.List;
1111
import java.util.Set;
12+
import java.util.stream.Collectors;
1213

1314
import io.quarkus.bootstrap.prebuild.CodeGenException;
1415
import io.quarkus.deployment.CodeGenContext;
@@ -40,6 +41,7 @@
4041
* <li>Filters dependencies by artifact type (jar/zip)</li>
4142
* <li>Applies artifact ID filtering using a regex pattern</li>
4243
* <li>Excludes specific GAVs based on configuration</li>
44+
* <li>Includes specific GAVs based on configuration if not available no GAVs are used</li>
4345
* <li>Creates {@link ZippedSpecInputModel} instances for each matching dependency and openAPI specification file</li>
4446
* </ol>
4547
*
@@ -95,7 +97,16 @@ protected void addInputModels(CodeGenContext context,
9597
}
9698
}
9799

100+
@Override
98101
protected Set<String> getSupportedExtensions() {
99102
return SUPPORTED_EXTENSIONS;
100103
}
104+
105+
@Override
106+
protected boolean specificGAVSpecInputProviderFilter(final CodeGenContext context, final String gacString) {
107+
return context.config().getOptionalValues(getGlobalConfigName(INCLUDE_GAVS), String.class)
108+
.orElse(List.of()) // default to empty list to disable all if not specified
109+
.stream().collect(Collectors.toSet())
110+
.contains(gacString);
111+
}
101112
}

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/YamlOrJsonGAVCoordinateOpenApiSpecInputProvider.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.quarkiverse.openapi.generator.deployment.codegen;
22

3+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.*;
4+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.*;
35
import static io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorCodeGenBase.*;
46

57
import java.io.IOException;
68
import java.nio.file.Files;
79
import java.nio.file.Path;
810
import java.util.List;
911
import java.util.Set;
12+
import java.util.stream.Collectors;
1013

1114
import io.quarkus.bootstrap.prebuild.CodeGenException;
1215
import io.quarkus.deployment.CodeGenContext;
@@ -29,6 +32,7 @@
2932
* <li>Filters dependencies by artifact type (yaml/yml/json)</li>
3033
* <li>Applies artifact ID filtering using a regex pattern</li>
3134
* <li>Excludes specific GAVs based on configuration</li>
35+
* <li>Includes specific GAVs based on configuration if available otherwise all GAVs are used</li>
3236
* <li>Creates {@link SpecInputModel} instances for each matching dependency</li>
3337
* </ol>
3438
*
@@ -74,4 +78,16 @@ protected void addInputModels(CodeGenContext context,
7478
protected Set<String> getSupportedExtensions() {
7579
return SUPPORTED_EXTENSIONS;
7680
}
81+
82+
@Override
83+
protected boolean specificGAVSpecInputProviderFilter(final CodeGenContext context, final String gacString) {
84+
List<String> includeGavs = context.config().getOptionalValues(getGlobalConfigName(INCLUDE_GAVS), String.class)
85+
.orElse(null);
86+
if (includeGavs == null) { // default behavior: all GAVs are included
87+
return true;
88+
}
89+
return includeGavs
90+
.stream().collect(Collectors.toSet())
91+
.contains(gacString);
92+
}
7793
}

client/integration-tests/gav/src/it/02-consume-gav/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<type>yaml</type>
6060
</dependency>
6161

62-
<!-- GAV YAML dependencies -->
62+
<!-- GAV JAR dependencies -->
6363
<dependency>
6464
<groupId>io.quarkiverse.openapi.generator</groupId>
6565
<artifactId>quarkus-openapi-generator-gav-source-splitted-echo</artifactId>

client/integration-tests/gav/src/it/02-consume-gav/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ quarkus.keycloak.devservices.enabled=false
22

33
quarkus.openapi-generator.codegen.artifact-id-filter=.*echo.*
44
quarkus.openapi-generator.codegen.exclude-gavs=io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-echo2
5+
quarkus.openapi-generator.codegen.include-gavs=io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-echo1,\
6+
io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-selfcontained-echo,\
7+
io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-splitted-echo
58
quarkus.openapi-generator.codegen.spec.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_echo1.serializable-model=true
69

710
quarkus.openapi-generator.codegen.spec.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_splitted_echo.gav-spec-files=echo.yaml

docs/modules/ROOT/pages/includes/quarkus-openapi-generator.adoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,30 @@ endif::add-copy-button-to-env-var[]
685685
|list of string
686686
|
687687

688+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-include-gavs]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-include-gavs[`quarkus.openapi-generator.codegen.include-gavs`]##
689+
ifdef::add-copy-button-to-config-props[]
690+
config_property_copy_button:+++quarkus.openapi-generator.codegen.include-gavs+++[]
691+
endif::add-copy-button-to-config-props[]
692+
693+
694+
[.description]
695+
--
696+
Option to specify GAVs for which generation should be executed only. Depending on the GAV Provider default behavior differs:
697+
698+
- for `io.quarkiverse.openapi.generator.deployment.codegen.YamlOrJsonGAVCoordinateOpenApiSpecInputProvider`, all suitable GAVs will be considered for generation if config value is not given
699+
- for `io.quarkiverse.openapi.generator.deployment.codegen.JarOrZipGAVCoordinateOpenApiSpecInputProvider`, only specified GAVs will be considered for generation if config value is available
700+
701+
702+
ifdef::add-copy-button-to-env-var[]
703+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_INCLUDE_GAVS+++[]
704+
endif::add-copy-button-to-env-var[]
705+
ifndef::add-copy-button-to-env-var[]
706+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_INCLUDE_GAVS+++`
707+
endif::add-copy-button-to-env-var[]
708+
--
709+
|list of string
710+
|
711+
688712
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-default-security-scheme]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-default-security-scheme[`quarkus.openapi-generator.codegen.default-security-scheme`]##
689713
ifdef::add-copy-button-to-config-props[]
690714
config_property_copy_button:+++quarkus.openapi-generator.codegen.default-security-scheme+++[]
@@ -1405,6 +1429,27 @@ endif::add-copy-button-to-env-var[]
14051429
|boolean
14061430
|`+++false+++`
14071431

1432+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-spec-spec-item-gav-spec-files]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-spec-spec-item-gav-spec-files[`quarkus.openapi-generator.codegen.spec."spec-item".gav-spec-files`]##
1433+
ifdef::add-copy-button-to-config-props[]
1434+
config_property_copy_button:+++quarkus.openapi-generator.codegen.spec."spec-item".gav-spec-files+++[]
1435+
endif::add-copy-button-to-config-props[]
1436+
1437+
1438+
[.description]
1439+
--
1440+
List of OpenAPI spec files in GAV to be generated
1441+
1442+
1443+
ifdef::add-copy-button-to-env-var[]
1444+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_SPEC__SPEC_ITEM__GAV_SPEC_FILES+++[]
1445+
endif::add-copy-button-to-env-var[]
1446+
ifndef::add-copy-button-to-env-var[]
1447+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_SPEC__SPEC_ITEM__GAV_SPEC_FILES+++`
1448+
endif::add-copy-button-to-env-var[]
1449+
--
1450+
|list of string
1451+
|`+++openapi.yaml+++`
1452+
14081453
a| [[quarkus-openapi-generator_quarkus-openapi-generator-item-configs-auth-auth-configs-token-propagation]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-item-configs-auth-auth-configs-token-propagation[`quarkus.openapi-generator."item-configs".auth."auth-configs".token-propagation`]##
14091454
ifdef::add-copy-button-to-config-props[]
14101455
config_property_copy_button:+++quarkus.openapi-generator."item-configs".auth."auth-configs".token-propagation+++[]

docs/modules/ROOT/pages/includes/quarkus-openapi-generator_quarkus.openapi-generator.adoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,30 @@ endif::add-copy-button-to-env-var[]
685685
|list of string
686686
|
687687

688+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-include-gavs]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-include-gavs[`quarkus.openapi-generator.codegen.include-gavs`]##
689+
ifdef::add-copy-button-to-config-props[]
690+
config_property_copy_button:+++quarkus.openapi-generator.codegen.include-gavs+++[]
691+
endif::add-copy-button-to-config-props[]
692+
693+
694+
[.description]
695+
--
696+
Option to specify GAVs for which generation should be executed only. Depending on the GAV Provider default behavior differs:
697+
698+
- for `io.quarkiverse.openapi.generator.deployment.codegen.YamlOrJsonGAVCoordinateOpenApiSpecInputProvider`, all suitable GAVs will be considered for generation if config value is not given
699+
- for `io.quarkiverse.openapi.generator.deployment.codegen.JarOrZipGAVCoordinateOpenApiSpecInputProvider`, only specified GAVs will be considered for generation if config value is available
700+
701+
702+
ifdef::add-copy-button-to-env-var[]
703+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_INCLUDE_GAVS+++[]
704+
endif::add-copy-button-to-env-var[]
705+
ifndef::add-copy-button-to-env-var[]
706+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_INCLUDE_GAVS+++`
707+
endif::add-copy-button-to-env-var[]
708+
--
709+
|list of string
710+
|
711+
688712
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-default-security-scheme]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-default-security-scheme[`quarkus.openapi-generator.codegen.default-security-scheme`]##
689713
ifdef::add-copy-button-to-config-props[]
690714
config_property_copy_button:+++quarkus.openapi-generator.codegen.default-security-scheme+++[]
@@ -1405,6 +1429,27 @@ endif::add-copy-button-to-env-var[]
14051429
|boolean
14061430
|`+++false+++`
14071431

1432+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-spec-spec-item-gav-spec-files]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-spec-spec-item-gav-spec-files[`quarkus.openapi-generator.codegen.spec."spec-item".gav-spec-files`]##
1433+
ifdef::add-copy-button-to-config-props[]
1434+
config_property_copy_button:+++quarkus.openapi-generator.codegen.spec."spec-item".gav-spec-files+++[]
1435+
endif::add-copy-button-to-config-props[]
1436+
1437+
1438+
[.description]
1439+
--
1440+
List of OpenAPI spec files in GAV to be generated
1441+
1442+
1443+
ifdef::add-copy-button-to-env-var[]
1444+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_SPEC__SPEC_ITEM__GAV_SPEC_FILES+++[]
1445+
endif::add-copy-button-to-env-var[]
1446+
ifndef::add-copy-button-to-env-var[]
1447+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_SPEC__SPEC_ITEM__GAV_SPEC_FILES+++`
1448+
endif::add-copy-button-to-env-var[]
1449+
--
1450+
|list of string
1451+
|`+++openapi.yaml+++`
1452+
14081453
a| [[quarkus-openapi-generator_quarkus-openapi-generator-item-configs-auth-auth-configs-token-propagation]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-item-configs-auth-auth-configs-token-propagation[`quarkus.openapi-generator."item-configs".auth."auth-configs".token-propagation`]##
14091454
ifdef::add-copy-button-to-config-props[]
14101455
config_property_copy_button:+++quarkus.openapi-generator."item-configs".auth."auth-configs".token-propagation+++[]

0 commit comments

Comments
 (0)