Skip to content

Commit d8e7d8f

Browse files
author
Michael Sonnleitner
committed
add filter for artifactIds & improved config naming(singular/plural) & tests simplicity & add config options to GlobalCodegenConfig
1 parent 10eb296 commit d8e7d8f

File tree

10 files changed

+190
-47
lines changed

10 files changed

+190
-47
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Arrays;
55
import java.util.List;
66
import java.util.Map;
7-
import java.util.stream.Collectors;
87

98
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
109
import io.quarkus.runtime.annotations.ConfigPhase;
@@ -30,7 +29,7 @@ public interface CodegenConfig extends GlobalCodegenConfig {
3029
String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
3130

3231
List<String> SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
33-
.collect(Collectors.toList());
32+
.toList();
3433

3534
enum ConfigName {
3635
//global configs
@@ -40,7 +39,8 @@ enum ConfigName {
4039
TEMPLATE_BASE_DIR("template-base-dir"),
4140
INCLUDE("include"),
4241
EXCLUDE("exclude"),
43-
EXCLUDE_GAV("exclude-gav"),
42+
ARTIFACT_ID_FILTER("artifact-id-filter"),
43+
EXCLUDE_GAVS("exclude-gavs"),
4444
VALIDATE_SPEC("validateSpec"),
4545
DEFAULT_SECURITY_SCHEME("default-security-scheme"),
4646

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkiverse.openapi.generator.deployment;
22

3+
import java.util.List;
34
import java.util.Optional;
45

56
import io.smallrye.config.WithDefault;
@@ -27,6 +28,13 @@ public interface GlobalCodegenConfig extends CommonItemConfig {
2728
@WithName("input-base-dir")
2829
Optional<String> inputBaseDir();
2930

31+
/**
32+
* Whether or not to skip gav scanning.
33+
*/
34+
@WithName("gav-scanning")
35+
@WithDefault("true")
36+
boolean gavScanning();
37+
3038
/**
3139
* Option to change the directory where template files must be found.
3240
*/
@@ -53,6 +61,19 @@ public interface GlobalCodegenConfig extends CommonItemConfig {
5361
@WithName("exclude")
5462
Optional<String> exclude();
5563

64+
/**
65+
* Option to filter artifactId from generation
66+
*/
67+
@WithName("artifact-id-filter")
68+
@WithDefault(".*openapi.*")
69+
Optional<String> artifactIdFilter();
70+
71+
/**
72+
* Option to exclude GAVs from generation
73+
*/
74+
@WithName("exclude-gavs")
75+
Optional<List<String>> excludeGavs();
76+
5677
/**
5778
* Create security for the referenced security scheme
5879
*/

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

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

33
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getGlobalConfigName;
4-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.EXCLUDE_GAV;
4+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.ARTIFACT_ID_FILTER;
5+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.EXCLUDE_GAVS;
56
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.GAV_SCANNING;
7+
import static io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorCodeGenBase.SUPPORTED_EXTENSIONS;
68

79
import java.io.IOException;
810
import java.nio.file.Files;
911
import java.util.ArrayList;
1012
import java.util.List;
13+
import java.util.function.Predicate;
1114

1215
import org.jboss.logging.Logger;
1316

@@ -26,17 +29,21 @@ public List<SpecInputModel> read(CodeGenContext context) throws CodeGenException
2629
return List.of();
2730
}
2831

29-
// Q: maybe a configuration property to enable GAV scanning (default: true)
30-
List<String> gavsToExclude = context.config().getOptionalValues(getGlobalConfigName(EXCLUDE_GAV), String.class)
32+
List<String> gavsToExclude = context.config().getOptionalValues(getGlobalConfigName(EXCLUDE_GAVS), String.class)
3133
.orElse(List.of());
34+
String artifactIdFilter = context.config().getOptionalValue(getGlobalConfigName(ARTIFACT_ID_FILTER), String.class)
35+
.filter(Predicate.not(String::isBlank))
36+
.orElse(".*openapi.*");
3237

3338
List<ResolvedDependency> yamlDependencies = context.applicationModel().getDependencies().stream()
34-
.filter(rd -> OpenApiGeneratorCodeGenBase.SUPPORTED_EXTENSIONS.contains(rd.getType()))
39+
.filter(rd -> SUPPORTED_EXTENSIONS.contains(rd.getType()))
40+
.filter(rd -> rd.getArtifactId().matches(artifactIdFilter))
3541
.filter(rd -> !gavsToExclude.contains(rd.getKey().toGacString()))
3642
.toList();
3743

3844
if (yamlDependencies.isEmpty()) {
39-
LOG.debug("No suitable GAV dependencies found.");
45+
LOG.debug("No suitable GAV dependencies found. ArtifactIdFilter was %s and gavsToExclude were %s."
46+
.formatted(artifactIdFilter, gavsToExclude));
4047
return List.of();
4148
}
4249
var inputModels = new ArrayList<SpecInputModel>();

client/integration-tests/gav-source/pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<artifactId>quarkus-openapi-generator-gav-source-echo1</artifactId>
2828
<groupId>io.quarkiverse.openapi.generator</groupId>
2929
<version>3.0.0-SNAPSHOT</version>
30-
<file>src/main/openapi/echo1.yaml</file>
30+
<file>src/main/openapi/echo.yaml</file>
3131
<packaging>yaml</packaging>
3232
</configuration>
3333
</execution>
@@ -41,7 +41,21 @@
4141
<artifactId>quarkus-openapi-generator-gav-source-echo2</artifactId>
4242
<groupId>io.quarkiverse.openapi.generator</groupId>
4343
<version>3.0.0-SNAPSHOT</version>
44-
<file>src/main/openapi/echo2.yaml</file>
44+
<file>src/main/openapi/echo.yaml</file>
45+
<packaging>yaml</packaging>
46+
</configuration>
47+
</execution>
48+
<execution>
49+
<id>install-other</id>
50+
<goals>
51+
<goal>install-file</goal>
52+
</goals>
53+
<phase>install</phase>
54+
<configuration>
55+
<artifactId>quarkus-openapi-generator-gav-source-other</artifactId>
56+
<groupId>io.quarkiverse.openapi.generator</groupId>
57+
<version>3.0.0-SNAPSHOT</version>
58+
<file>src/main/openapi/echo.yaml</file>
4559
<packaging>yaml</packaging>
4660
</configuration>
4761
</execution>

client/integration-tests/gav-source/src/main/openapi/echo2.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
quarkus.keycloak.devservices.enabled=false
22

3-
quarkus.openapi-generator.codegen.exclude-gav=io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-echo2
3+
quarkus.openapi-generator.codegen.artifact-id-filter=.*echo.*
4+
quarkus.openapi-generator.codegen.exclude-gavs=io.quarkiverse.openapi.generator:quarkus-openapi-generator-gav-source-echo2

client/integration-tests/gav/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusGAVOpenApiTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@
66

77
class QuarkusGAVOpenApiTest {
88
@Test
9-
void apiIsBeingGenerated() {
9+
void echo1IsBeingGenerated() {
1010
assertThatCode(
1111
() -> Class.forName(
1212
"org.openapi.quarkus.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_echo1.api.DefaultApi"))
1313
.doesNotThrowAnyException();
1414
}
1515

1616
@Test
17-
void apiIsBeingNotGenerated() {
17+
void echo2IsBeingNotGenerated() {
1818
assertThatCode(
1919
() -> Class.forName(
2020
"org.openapi.quarkus.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_echo2.api.DefaultApi"))
2121
.isInstanceOf(ClassNotFoundException.class);
2222
}
23+
24+
@Test
25+
void otherIsBeingNotGenerated() {
26+
assertThatCode(
27+
() -> Class.forName(
28+
"org.openapi.quarkus.io_quarkiverse_openapi_generator_quarkus_openapi_generator_gav_source_other.api.DefaultApi"))
29+
.isInstanceOf(ClassNotFoundException.class);
30+
}
2331
}

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,27 @@ endif::add-copy-button-to-env-var[]
538538
|string
539539
|
540540

541+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-gav-scanning]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-gav-scanning[`quarkus.openapi-generator.codegen.gav-scanning`]##
542+
ifdef::add-copy-button-to-config-props[]
543+
config_property_copy_button:+++quarkus.openapi-generator.codegen.gav-scanning+++[]
544+
endif::add-copy-button-to-config-props[]
545+
546+
547+
[.description]
548+
--
549+
Whether or not to skip gav scanning.
550+
551+
552+
ifdef::add-copy-button-to-env-var[]
553+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_GAV_SCANNING+++[]
554+
endif::add-copy-button-to-env-var[]
555+
ifndef::add-copy-button-to-env-var[]
556+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_GAV_SCANNING+++`
557+
endif::add-copy-button-to-env-var[]
558+
--
559+
|boolean
560+
|`+++true+++`
561+
541562
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-template-base-dir]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-template-base-dir[`quarkus.openapi-generator.codegen.template-base-dir`]##
542563
ifdef::add-copy-button-to-config-props[]
543564
config_property_copy_button:+++quarkus.openapi-generator.codegen.template-base-dir+++[]
@@ -622,6 +643,48 @@ endif::add-copy-button-to-env-var[]
622643
|string
623644
|
624645

646+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-artifact-id-filter]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-artifact-id-filter[`quarkus.openapi-generator.codegen.artifact-id-filter`]##
647+
ifdef::add-copy-button-to-config-props[]
648+
config_property_copy_button:+++quarkus.openapi-generator.codegen.artifact-id-filter+++[]
649+
endif::add-copy-button-to-config-props[]
650+
651+
652+
[.description]
653+
--
654+
Option to filter artifactId from generation
655+
656+
657+
ifdef::add-copy-button-to-env-var[]
658+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_ARTIFACT_ID_FILTER+++[]
659+
endif::add-copy-button-to-env-var[]
660+
ifndef::add-copy-button-to-env-var[]
661+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_ARTIFACT_ID_FILTER+++`
662+
endif::add-copy-button-to-env-var[]
663+
--
664+
|string
665+
|`+++.*openapi.*+++`
666+
667+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-exclude-gavs]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-exclude-gavs[`quarkus.openapi-generator.codegen.exclude-gavs`]##
668+
ifdef::add-copy-button-to-config-props[]
669+
config_property_copy_button:+++quarkus.openapi-generator.codegen.exclude-gavs+++[]
670+
endif::add-copy-button-to-config-props[]
671+
672+
673+
[.description]
674+
--
675+
Option to exclude GAVs from generation
676+
677+
678+
ifdef::add-copy-button-to-env-var[]
679+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_EXCLUDE_GAVS+++[]
680+
endif::add-copy-button-to-env-var[]
681+
ifndef::add-copy-button-to-env-var[]
682+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_EXCLUDE_GAVS+++`
683+
endif::add-copy-button-to-env-var[]
684+
--
685+
|list of string
686+
|
687+
625688
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`]##
626689
ifdef::add-copy-button-to-config-props[]
627690
config_property_copy_button:+++quarkus.openapi-generator.codegen.default-security-scheme+++[]

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,27 @@ endif::add-copy-button-to-env-var[]
538538
|string
539539
|
540540

541+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-gav-scanning]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-gav-scanning[`quarkus.openapi-generator.codegen.gav-scanning`]##
542+
ifdef::add-copy-button-to-config-props[]
543+
config_property_copy_button:+++quarkus.openapi-generator.codegen.gav-scanning+++[]
544+
endif::add-copy-button-to-config-props[]
545+
546+
547+
[.description]
548+
--
549+
Whether or not to skip gav scanning.
550+
551+
552+
ifdef::add-copy-button-to-env-var[]
553+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_GAV_SCANNING+++[]
554+
endif::add-copy-button-to-env-var[]
555+
ifndef::add-copy-button-to-env-var[]
556+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_GAV_SCANNING+++`
557+
endif::add-copy-button-to-env-var[]
558+
--
559+
|boolean
560+
|`+++true+++`
561+
541562
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-template-base-dir]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-template-base-dir[`quarkus.openapi-generator.codegen.template-base-dir`]##
542563
ifdef::add-copy-button-to-config-props[]
543564
config_property_copy_button:+++quarkus.openapi-generator.codegen.template-base-dir+++[]
@@ -622,6 +643,48 @@ endif::add-copy-button-to-env-var[]
622643
|string
623644
|
624645

646+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-artifact-id-filter]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-artifact-id-filter[`quarkus.openapi-generator.codegen.artifact-id-filter`]##
647+
ifdef::add-copy-button-to-config-props[]
648+
config_property_copy_button:+++quarkus.openapi-generator.codegen.artifact-id-filter+++[]
649+
endif::add-copy-button-to-config-props[]
650+
651+
652+
[.description]
653+
--
654+
Option to filter artifactId from generation
655+
656+
657+
ifdef::add-copy-button-to-env-var[]
658+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_ARTIFACT_ID_FILTER+++[]
659+
endif::add-copy-button-to-env-var[]
660+
ifndef::add-copy-button-to-env-var[]
661+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_ARTIFACT_ID_FILTER+++`
662+
endif::add-copy-button-to-env-var[]
663+
--
664+
|string
665+
|`+++.*openapi.*+++`
666+
667+
a|icon:lock[title=Fixed at build time] [[quarkus-openapi-generator_quarkus-openapi-generator-codegen-exclude-gavs]] [.property-path]##link:#quarkus-openapi-generator_quarkus-openapi-generator-codegen-exclude-gavs[`quarkus.openapi-generator.codegen.exclude-gavs`]##
668+
ifdef::add-copy-button-to-config-props[]
669+
config_property_copy_button:+++quarkus.openapi-generator.codegen.exclude-gavs+++[]
670+
endif::add-copy-button-to-config-props[]
671+
672+
673+
[.description]
674+
--
675+
Option to exclude GAVs from generation
676+
677+
678+
ifdef::add-copy-button-to-env-var[]
679+
Environment variable: env_var_with_copy_button:+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_EXCLUDE_GAVS+++[]
680+
endif::add-copy-button-to-env-var[]
681+
ifndef::add-copy-button-to-env-var[]
682+
Environment variable: `+++QUARKUS_OPENAPI_GENERATOR_CODEGEN_EXCLUDE_GAVS+++`
683+
endif::add-copy-button-to-env-var[]
684+
--
685+
|list of string
686+
|
687+
625688
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`]##
626689
ifdef::add-copy-button-to-config-props[]
627690
config_property_copy_button:+++quarkus.openapi-generator.codegen.default-security-scheme+++[]

0 commit comments

Comments
 (0)