From ca455c6a1923da21865e0f967ed9298d0b9de92d Mon Sep 17 00:00:00 2001 From: WilliamKSilva Date: Wed, 25 Sep 2024 19:29:44 -0300 Subject: [PATCH] Use @ConfigMapping annotation instead legacy @ConfigRoot on the client --- client/deployment/pom.xml | 3 - .../generator/deployment/CodegenConfig.java | 130 ++--------------- .../deployment/CodegenConfigMethods.java | 80 ++++++++++ .../deployment/CodegenConfigName.java | 45 ++++++ .../deployment/CommonItemConfig.java | 83 +++++------ .../deployment/GlobalCodegenConfig.java | 24 +-- .../generator/deployment/SpecItemConfig.java | 27 ++-- .../codegen/ClassCodegenConfigParser.java | 4 +- .../codegen/OpenApiConfigValidator.java | 2 +- .../codegen/OpenApiGeneratorCodeGenBase.java | 127 ++++++++-------- .../deployment/codegen/SpecInputModel.java | 12 +- .../OpenApiClientGeneratorWrapper.java | 17 +-- .../deployment/CodegenConfigTest.java | 8 +- client/runtime/pom.xml | 3 - .../openapi/generator/AuthConfig.java | 42 +----- .../openapi/generator/AuthConfigConsts.java | 6 + .../openapi/generator/AuthsConfig.java | 29 ++-- .../generator/OpenApiGeneratorConfig.java | 30 +--- .../OpenApiGeneratorConfigMethods.java | 11 ++ .../openapi/generator/SpecItemConfig.java | 22 +-- .../providers/AbstractAuthProvider.java | 14 +- ...stractCompositeAuthenticationProvider.java | 4 +- .../ApiKeyAuthenticationProvider.java | 6 +- .../BasicAuthenticationProvider.java | 2 +- .../OAuth2AuthenticationProvider.java | 4 +- .../AbstractAuthenticationProviderTest.java | 138 ++++++++++++++++-- .../ApiKeyAuthenticationProviderTest.java | 14 +- .../BasicAuthenticationProviderTest.java | 8 +- .../BearerAuthenticationProviderTest.java | 15 +- 29 files changed, 481 insertions(+), 429 deletions(-) create mode 100644 client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigMethods.java create mode 100644 client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigName.java create mode 100644 client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfigConsts.java create mode 100644 client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfigMethods.java diff --git a/client/deployment/pom.xml b/client/deployment/pom.xml index 1000a5afb..3eb643b3b 100644 --- a/client/deployment/pom.xml +++ b/client/deployment/pom.xml @@ -150,9 +150,6 @@ ${quarkus.version} - - -AlegacyConfigRoot=true - diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java index 2c565c658..8b18b59b4 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java @@ -1,132 +1,26 @@ package io.quarkiverse.openapi.generator.deployment; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.smallrye.config.common.utils.StringUtil; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithName; // This configuration is read in codegen phase (before build time), the annotation is for document purposes and avoiding quarkus warns -@ConfigRoot(name = CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX, phase = ConfigPhase.BUILD_TIME) -public class CodegenConfig extends GlobalCodegenConfig { - - static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen"; - - public static final String API_PKG_SUFFIX = ".api"; - public static final String MODEL_PKG_SUFFIX = ".model"; - - public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED"; - public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected"; - // package visibility for unit tests - static final String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s"; - static final String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s"; - - public static final List SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name) - .collect(Collectors.toList()); - - public enum ConfigName { - //global configs - VERBOSE("verbose"), - INPUT_BASE_DIR("input-base-dir"), - INCLUDE("include"), - EXCLUDE("exclude"), - VALIDATE_SPEC("validateSpec"), - DEFAULT_SECURITY_SCHEME("default-security-scheme"), - - //spec configs only - BASE_PACKAGE("base-package"), - API_NAME_SUFFIX("api-name-suffix"), - MODEL_NAME_SUFFIX("model-name-suffix"), - MODEL_NAME_PREFIX("model-name-prefix"), - - //global & spec configs - SKIP_FORM_MODEL("skip-form-model"), - MUTINY("mutiny"), - MUTINY_RETURN_RESPONSE("mutiny.return-response"), - MUTINY_OPERATION_IDS("mutiny.operation-ids"), - ADDITIONAL_MODEL_TYPE_ANNOTATIONS("additional-model-type-annotations"), - ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER("additional-enum-type-unexpected-member"), - ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME("additional-enum-type-unexpected-member-name"), - ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE("additional-enum-type-unexpected-member-string-value"), - ADDITIONAL_API_TYPE_ANNOTATIONS("additional-api-type-annotations"), - TYPE_MAPPINGS("type-mappings"), - IMPORT_MAPPINGS("import-mappings"), - NORMALIZER("open-api-normalizer"), - RETURN_RESPONSE("return-response"), - ENABLE_SECURITY_GENERATION("enable-security-generation"), - CONFIG_KEY("config-key"), - GENERATE_PART_FILENAME("generate-part-filename"), - PART_FILENAME_VALUE("part-filename-value"), - USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"), - ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"), - ADDITIONAL_REQUEST_ARGS("additional-request-args"), - BEAN_VALIDATION("use-bean-validation"); - - private final String name; - - ConfigName(String name) { - this.name = name; - } - - } - +@ConfigMapping(prefix = "openapi-generator.codegen") +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +public interface CodegenConfig { /** - * OpenAPI Spec details for codegen configuration. + * Common item test. */ - @ConfigItem(name = "spec") - public Map specItem; - - public static String resolveApiPackage(final String basePackage) { - return String.format("%s%s", basePackage, API_PKG_SUFFIX); - } - - public static String resolveModelPackage(final String basePackage) { - return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX); - } - - /** - * Return global config name, openapi-generator.codegen.config-name - */ - public static String getGlobalConfigName(ConfigName configName) { - return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name); - } - - /** - * Return spec config name openapi-generator.codegen.spec.%s.config-name - */ - public static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) { - return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name); - } - - /** - * Return spec config name by config-key (openapi-generator.codegen.spec.%s.config-key) property. - * For example, given a configuration quarkus.openapi.generator.codegen.spec.spec_yaml.config-key=petstore, the - * returned value is - * openapi.generator.codegen.spec.petstore.mutiny. - */ - public static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) { - String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey); - return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name); - } + @WithName("common-item-config") + CommonItemConfig commonItemConfig(); /** - * Gets the config prefix for a given OpenAPI file in the path. - * For example, given a path like /home/luke/projects/petstore.json, the returned value is - * `quarkus.openapi-generator."petstore_json"`. - * Every the periods (.) in the file name will be replaced by underscore (_). + * OpenAPI Spec details for codegen configuration. */ - public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) { - return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath)); - } - - public static String getSanitizedFileName(final Path openApiFilePath) { - return StringUtil - .replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString()); - } + @WithName("spec") + Map specItem(); + // } diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigMethods.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigMethods.java new file mode 100644 index 000000000..2e01c986b --- /dev/null +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigMethods.java @@ -0,0 +1,80 @@ +package io.quarkiverse.openapi.generator.deployment; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths; +import io.smallrye.config.common.utils.StringUtil; + +public class CodegenConfigMethods { + static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen"; + + public static final String API_PKG_SUFFIX = ".api"; + public static final String MODEL_PKG_SUFFIX = ".model"; + + public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED"; + public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected"; + // package visibility for unit tests + static final String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s"; + static final String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s"; + + public static final List SUPPORTED_CONFIGURATIONS = Arrays.stream(CodegenConfigName.values()).map(cn -> cn.name) + .collect(Collectors.toList()); + + /** + * Return spec config name openapi-generator.codegen.spec.%s.config-name + */ + public static String getSpecConfigName(CodegenConfigName configName, final Path openApiFilePath) { + return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name); + } + + /** + * Return spec con fig name by config-key (openapi-generator.codegen.spec.%s.config-key) property. + * For example, given a configuration quarkus.openapi.generator.codegen.spec.spec_yaml.config-key=petstore, the + * returned value is + * openapi.generator.codegen.spec.petstore.mutiny. + */ + public static String getSpecConfigNameByConfigKey(final String configKey, final CodegenConfigName configName) { + String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey); + return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name); + } + + /** + * Gets the config prefix for a given OpenAPI file in the path. + * For example, given a path like /home/luke/projects/petstore.json, the returned value is + * `quarkus.openapi-generator."petstore_json"`. + * Every the periods (.) in the file name will be replaced by underscore (_). + */ + + public static String resolveApiPackage(final String basePackage) { + return String.format("%s%s", basePackage, API_PKG_SUFFIX); + } + + public static String resolveModelPackage(final String basePackage) { + return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX); + } + + /** + * Return global config name, openapi-generator.codegen.config-name + */ + public static String getGlobalConfigName(CodegenConfigName configName) { + return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name); + } + + /** + * Gets the config prefix for a given OpenAPI file in the path. + * For example, given a path like /home/luke/projects/petstore.json, the returned value is + * `quarkus.openapi-generator."petstore_json"`. + * Every the periods (.) in the file name will be replaced by underscore (_). + */ + public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) { + return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath)); + } + + public static String getSanitizedFileName(final Path openApiFilePath) { + return StringUtil + .replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString()); + } +} diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigName.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigName.java new file mode 100644 index 000000000..3234267c3 --- /dev/null +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigName.java @@ -0,0 +1,45 @@ +package io.quarkiverse.openapi.generator.deployment; + +public enum CodegenConfigName { + //global configs + VERBOSE("verbose"), + INPUT_BASE_DIR("input-base-dir"), + INCLUDE("include"), + EXCLUDE("exclude"), + VALIDATE_SPEC("validateSpec"), + DEFAULT_SECURITY_SCHEME("default-security-scheme"), + + //spec configs only + BASE_PACKAGE("base-package"), + API_NAME_SUFFIX("api-name-suffix"), + MODEL_NAME_SUFFIX("model-name-suffix"), + MODEL_NAME_PREFIX("model-name-prefix"), + + //global & spec configs + SKIP_FORM_MODEL("skip-form-model"), + MUTINY("mutiny"), + MUTINY_OPERATION_IDS("mutiny.operation-ids"), + ADDITIONAL_MODEL_TYPE_ANNOTATIONS("additional-model-type-annotations"), + ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER("additional-enum-type-unexpected-member"), + ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME("additional-enum-type-unexpected-member-name"), + ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE("additional-enum-type-unexpected-member-string-value"), + ADDITIONAL_API_TYPE_ANNOTATIONS("additional-api-type-annotations"), + TYPE_MAPPINGS("type-mappings"), + IMPORT_MAPPINGS("import-mappings"), + NORMALIZER("open-api-normalizer"), + RETURN_RESPONSE("return-response"), + ENABLE_SECURITY_GENERATION("enable-security-generation"), + CONFIG_KEY("config-key"), + GENERATE_PART_FILENAME("generate-part-filename"), + PART_FILENAME_VALUE("part-filename-value"), + USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"), + ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"), + ADDITIONAL_REQUEST_ARGS("additional-request-args"), + BEAN_VALIDATION("use-bean-validation"); + + public final String name; + + CodegenConfigName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java index 9a6baed5a..b895bffc5 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java @@ -3,8 +3,7 @@ import java.util.Map; import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithName; /* * Model for the configuration of this extension. @@ -13,85 +12,77 @@ * Not meant to be used outside this scope. * Config items can be applied on spec and globally as well */ -@ConfigGroup -public class CommonItemConfig { +public interface CommonItemConfig { /** * Whether to skip the generation of models for form parameters */ - @ConfigItem(name = "skip-form-model") - public Optional skipFormModel; + @WithName("skip-form-model") + Optional skipFormModel(); /** * Type Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be used for a * given OAS datatype (the keys of this map) */ - @ConfigItem(name = "type-mappings") - public Map typeMappings; + @WithName("type-mappings") + Map typeMappings(); /** * Import Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be * imported when a given OAS datatype (the keys of this map) is used */ - @ConfigItem(name = "import-mappings") - public Map importMappings; + @WithName("import-mappings") + Map importMappings(); /** * The specified annotations will be added to the generated model files */ - @ConfigItem(name = "additional-model-type-annotations") - public Optional additionalModelTypeAnnotations; + @WithName("additional-model-type-annotations") + Optional additionalModelTypeAnnotations(); /** * Defines if the enums should have an `UNEXPECTED` member to convey values that cannot be parsed. Default is * {@code false}. */ - @ConfigItem(name = "additional-enum-type-unexpected-member") - public Optional additionalEnumTypeUnexpectedMemberAnnotations; + @WithName("additional-enum-type-unexpected-member") + Optional additionalEnumTypeUnexpectedMemberAnnotations(); /** * The specified annotations will be added to the generated api files */ - @ConfigItem(name = "additional-api-type-annotations") - public Optional additionalApiTypeAnnotations; + @WithName("additional-api-type-annotations") + Optional additionalApiTypeAnnotations(); /** * Add custom/additional HTTP Headers or other args to every request */ - @ConfigItem(name = "additional-request-args") - public Optional additionalRequestArgs; + @WithName("additional-request-args") + Optional additionalRequestArgs(); /** * Defines if the methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is {@code false}. */ - @ConfigItem(name = "return-response") - public Optional returnResponse; + @WithName("return-response") + Optional returnResponse(); /** * Defines if security support classes should be generated */ - @ConfigItem(name = "enable-security-generation") - public Optional enableSecurityGeneration; + @WithName("enable-security-generation") + Optional enableSecurityGeneration(); /** * Defines the normalizer options. */ - @ConfigItem(name = "open-api-normalizer") - public Map normalizer; + @WithName("open-api-normalizer") + Map normalizer(); /** * Enable SmallRye Mutiny support. If you set this to {@code true}, all return types will be wrapped in * {@link io.smallrye.mutiny.Uni}. */ - @ConfigItem(name = "mutiny") - public Optional supportMutiny; - - /** - * Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is - * {@code false}. - */ - @ConfigItem(name = "mutiny.return-response") - public Optional mutinyReturnResponse; + @WithName("mutiny") + Optional supportMutiny(); /** * Handles the return type for each operation, depending on the configuration. @@ -99,35 +90,35 @@ public class CommonItemConfig { *

* 1. If {@code mutiny} is enabled and the operation ID is specified to return {@code Multi}: * - The return type will be wrapped in {@link io.smallrye.mutiny.Multi}. - * - If {@code mutiny.return-response} is enabled, the return type will be + * - If {@code return-response} is enabled, the return type will be * {@link io.smallrye.mutiny.Multi}. * - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Multi}. * - Otherwise, it will return {@link io.smallrye.mutiny.Multi}. *

* 2. If {@code mutiny} is enabled and the operation ID is specified to return {@code Uni}: * - The return type will be wrapped in {@link io.smallrye.mutiny.Uni}. - * - If {@code mutiny.return-response} is enabled, the return type will be + * - If {@code return-response} is enabled, the return type will be * {@link io.smallrye.mutiny.Uni}. * - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni}. * - Otherwise, it will return {@link io.smallrye.mutiny.Uni}. *

* 3. If {@code mutiny} is enabled but no specific operation ID is configured for {@code Multi} or {@code Uni}: * - The return type defaults to {@code Uni}. - * - If {@code mutiny.return-response} is enabled, the return type will be + * - If {@code return-response} is enabled, the return type will be * {@link io.smallrye.mutiny.Uni}. * - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni}. * - Otherwise, it will return {@link io.smallrye.mutiny.Uni}`. */ - @ConfigItem(name = "mutiny.operation-ids") - public Optional> mutinyMultiOperationIds; + @WithName("mutiny.operation-ids") + Map mutinyMultiOperationIds(); /** * Defines, whether the `PartFilename` ({@link org.jboss.resteasy.reactive.PartFilename} or * {@link org.jboss.resteasy.annotations.providers.multipart.PartFilename}) annotation should be generated for * MultipartForm POJOs. By setting to {@code false}, the annotation will not be generated. */ - @ConfigItem(name = "generate-part-filename") - public Optional generatePartFilename; + @WithName("generate-part-filename") + Optional generatePartFilename(); /** * Defines the filename for a part in case the `PartFilename` annotation @@ -136,21 +127,21 @@ public class CommonItemConfig { * In case no value is set, the default one is `<fieldName>File` or `file`, depending on the * {@link CommonItemConfig#useFieldNameInPartFilename} configuration. */ - @ConfigItem(name = "part-filename-value") - public Optional partFilenameValue; + @WithName("part-filename-value") + Optional partFilenameValue(); /** * Defines, whether the filename should also include the property name in case the `PartFilename` annotation * ({@link org.jboss.resteasy.reactive.PartFilename} or * {@link org.jboss.resteasy.annotations.providers.multipart.PartFilename}) is generated. */ - @ConfigItem(name = "use-field-name-in-part-filename") - public Optional useFieldNameInPartFilename; + @WithName("use-field-name-in-part-filename") + Optional useFieldNameInPartFilename(); /** * Enable bean validation. If you set this to {@code true}, validation annotations are added to generated sources E.g. * {@code @Size}. */ - @ConfigItem(name = "use-bean-validation") - public Optional useBeanValidation; + @WithName("use-bean-validation") + Optional useBeanValidation(); } diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java index d47384318..cfea68800 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java @@ -2,9 +2,6 @@ import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; - /* * Model for the configuration of this extension. * It's used for documentation purposes only. @@ -12,44 +9,37 @@ * Not meant to be used outside this scope. * Config items can be applied only globally */ -@ConfigGroup -public class GlobalCodegenConfig extends CommonItemConfig { +public interface GlobalCodegenConfig { /** * Whether to log the internal generator codegen process in the default output or not. */ - @ConfigItem(name = "verbose", defaultValue = "false") - public boolean verbose; + boolean verbose(); /** * Option to change the directory where OpenAPI files must be found. */ - @ConfigItem(name = "input-base-dir") - public Optional inputBaseDir; + Optional inputBaseDir(); /** * Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in * an error. */ - @ConfigItem(name = "validateSpec", defaultValue = "true") - public boolean validateSpec; + boolean validateSpec(); /** * Option to specify files for which generation should be executed only */ - @ConfigItem(name = "include") - public Optional include; + Optional include(); /** * Option to exclude file from generation */ - @ConfigItem(name = "exclude") - public Optional exclude; + Optional exclude(); /** * Create security for the referenced security scheme */ - @ConfigItem(name = "default-security-scheme") - public Optional defaultSecuritySchema; + Optional defaultSecuritySchema(); } diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java index 36a42cbb4..958af19fe 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java @@ -2,8 +2,7 @@ import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithName; /* * Model for the configuration of this extension. @@ -12,30 +11,34 @@ * Not meant to be used outside this scope. * Config items can be applied only on spec */ -@ConfigGroup -public class SpecItemConfig extends CommonItemConfig { +public interface SpecItemConfig { + /** + * Common item test. + */ + @WithName("common-item-config") + CommonItemConfig commonItemConfig(); /** * Base package for where the generated code for the given OpenAPI specification will be added. */ - @ConfigItem(name = "base-package") - public Optional basePackage; + @WithName("base-package") + Optional basePackage(); /** * Suffix name for generated api classes */ - @ConfigItem(name = "api-name-suffix") - public Optional apiNameSuffix; + @WithName("api-name-suffix") + Optional apiNameSuffix(); /** * Suffix name for generated model classes */ - @ConfigItem(name = "model-name-suffix") - public Optional modelNameSuffix; + @WithName("model-name-suffix") + Optional modelNameSuffix(); /** * Prefix name for generated model classes */ - @ConfigItem(name = "model-name-prefix") - public Optional modelNamePrefix; + @WithName("model-name-prefix") + Optional modelNamePrefix(); } diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/ClassCodegenConfigParser.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/ClassCodegenConfigParser.java index 3cfeee48c..a3ffba5c7 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/ClassCodegenConfigParser.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/ClassCodegenConfigParser.java @@ -1,7 +1,7 @@ package io.quarkiverse.openapi.generator.deployment.codegen; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveApiPackage; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveModelPackage; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.resolveApiPackage; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.resolveModelPackage; import java.util.HashMap; import java.util.List; diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiConfigValidator.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiConfigValidator.java index e6cf62dd6..2a044b90e 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiConfigValidator.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiConfigValidator.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.deployment.codegen; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.SUPPORTED_CONFIGURATIONS; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.SUPPORTED_CONFIGURATIONS; import java.util.HashSet; import java.util.List; diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java index b6d671753..6ee15ae7a 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java @@ -1,19 +1,19 @@ package io.quarkiverse.openapi.generator.deployment.codegen; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getGlobalConfigName; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSanitizedFileName; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSpecConfigName; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.API_NAME_SUFFIX; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.BASE_PACKAGE; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.DEFAULT_SECURITY_SCHEME; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.EXCLUDE; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INCLUDE; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INPUT_BASE_DIR; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_PREFIX; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_SUFFIX; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.VALIDATE_SPEC; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.getGlobalConfigName; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.getSanitizedFileName; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.getSpecConfigName; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.API_NAME_SUFFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.BASE_PACKAGE; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.DEFAULT_SECURITY_SCHEME; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.EXCLUDE; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.INCLUDE; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.INPUT_BASE_DIR; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.MODEL_NAME_PREFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.MODEL_NAME_SUFFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.VALIDATE_SPEC; import java.io.IOException; import java.nio.file.Files; @@ -30,7 +30,8 @@ import org.eclipse.microprofile.config.Config; import org.openapitools.codegen.config.GlobalSettings; -import io.quarkiverse.openapi.generator.deployment.CodegenConfig; +import io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods; +import io.quarkiverse.openapi.generator.deployment.CodegenConfigName; import io.quarkiverse.openapi.generator.deployment.circuitbreaker.CircuitBreakerConfigurationParser; import io.quarkiverse.openapi.generator.deployment.wrapper.OpenApiClassicClientGeneratorWrapper; import io.quarkiverse.openapi.generator.deployment.wrapper.OpenApiClientGeneratorWrapper; @@ -169,9 +170,9 @@ private static String determineRestClientReactiveJacksonCapabilityId() { // TODO: do not generate if the output dir has generated files and the openapi file has the same checksum of the previous run protected void generate(final Config config, final Path openApiFilePath, final Path outDir, - Path templateDir, boolean isRestEasyReactive) { + Path templateDir, boolean isRestEasyReactive) { final String basePackage = getBasePackage(config, openApiFilePath); - final Boolean verbose = config.getOptionalValue(getGlobalConfigName(CodegenConfig.ConfigName.VERBOSE), Boolean.class) + final Boolean verbose = config.getOptionalValue(getGlobalConfigName(CodegenConfigName.VERBOSE), Boolean.class) .orElse(false); final Boolean validateSpec = config.getOptionalValue(getGlobalConfigName(VALIDATE_SPEC), Boolean.class).orElse(true); GlobalSettings.setProperty(OpenApiClientGeneratorWrapper.DEFAULT_SECURITY_SCHEME, @@ -195,34 +196,34 @@ protected void generate(final Config config, final Path openApiFilePath, final P getModelNamePrefix(config, openApiFilePath) .ifPresent(generator::withModelNamePrefix); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY, Boolean.class) + getValues(config, openApiFilePath, CodegenConfigName.MUTINY, Boolean.class) .ifPresent(generator::withMutiny); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.SKIP_FORM_MODEL, String.class) + getValues(config, openApiFilePath, CodegenConfigName.SKIP_FORM_MODEL, String.class) .ifPresent(generator::withSkipFormModelConfig); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, String.class) + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, String.class) .ifPresent(generator::withAdditionalModelTypeAnnotationsConfig); generator.withAdditionalEnumTypeUnexpectedMemberConfig( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER, + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER, Boolean.class) .orElse(false)); generator.withAdditionalEnumTypeUnexpectedMemberNameConfig( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME, + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME, String.class) .orElse(ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT)); generator.withAdditionalEnumTypeUnexpectedMemberStringValueConfig( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE, + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE, String.class) .orElse(ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT)); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_API_TYPE_ANNOTATIONS, String.class) + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_API_TYPE_ANNOTATIONS, String.class) .ifPresent(generator::withAdditionalApiTypeAnnotationsConfig); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ADDITIONAL_REQUEST_ARGS, String.class) + getValues(config, openApiFilePath, CodegenConfigName.ADDITIONAL_REQUEST_ARGS, String.class) .ifPresent(generator::withAdditionalRequestArgs); getConfigKeyValue(config, openApiFilePath) @@ -230,47 +231,43 @@ protected void generate(final Config config, final Path openApiFilePath, final P () -> generator.withConfigKey(getSanitizedFileName(openApiFilePath))); generator.withReturnResponse( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.RETURN_RESPONSE, Boolean.class).orElse(false)); - - generator.withMutinyReturnResponse( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, Boolean.class) - .orElse(false)); + getValues(config, openApiFilePath, CodegenConfigName.RETURN_RESPONSE, Boolean.class).orElse(false)); generator.withEnabledSecurityGeneration( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.ENABLE_SECURITY_GENERATION, Boolean.class) + getValues(config, openApiFilePath, CodegenConfigName.ENABLE_SECURITY_GENERATION, Boolean.class) .orElse(true)); generator.withGeneratePartFilenameConfig( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_PART_FILENAME, Boolean.class) + getValues(config, openApiFilePath, CodegenConfigName.GENERATE_PART_FILENAME, Boolean.class) .orElse(true)); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.PART_FILENAME_VALUE, String.class) + getValues(config, openApiFilePath, CodegenConfigName.PART_FILENAME_VALUE, String.class) .ifPresent(generator::withPartFilenameValueConfig); generator.withUseFieldNameInPartFilenameConfig( - getValues(config, openApiFilePath, CodegenConfig.ConfigName.USE_FIELD_NAME_IN_PART_FILENAME, + getValues(config, openApiFilePath, CodegenConfigName.USE_FIELD_NAME_IN_PART_FILENAME, Boolean.class) .orElse(true)); - getValues(config, openApiFilePath, CodegenConfig.ConfigName.BEAN_VALIDATION, Boolean.class) + getValues(config, openApiFilePath, CodegenConfigName.BEAN_VALIDATION, Boolean.class) .ifPresent(generator::withUseBeanValidation); SmallRyeConfig smallRyeConfig = config.unwrap(SmallRyeConfig.class); - getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.TYPE_MAPPINGS, String.class, String.class) + getValues(smallRyeConfig, openApiFilePath, CodegenConfigName.TYPE_MAPPINGS, String.class, String.class) .ifPresent(generator::withTypeMappings); - getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.IMPORT_MAPPINGS, String.class, String.class) + getValues(smallRyeConfig, openApiFilePath, CodegenConfigName.IMPORT_MAPPINGS, String.class, String.class) .ifPresent(generator::withImportMappings); - getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.NORMALIZER, String.class, String.class) + getValues(smallRyeConfig, openApiFilePath, CodegenConfigName.NORMALIZER, String.class, String.class) .ifPresent(generator::withOpenApiNormalizer); Boolean additionalPropertiesAsAttribute = getValues(smallRyeConfig, openApiFilePath, - CodegenConfig.ConfigName.ADDITIONAL_PROPERTIES_AS_ATTRIBUTE, Boolean.class) + CodegenConfigName.ADDITIONAL_PROPERTIES_AS_ATTRIBUTE, Boolean.class) .orElse(Boolean.FALSE); - getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.MUTINY_OPERATION_IDS, String.class, String.class) + getValues(smallRyeConfig, openApiFilePath, CodegenConfigName.MUTINY_OPERATION_IDS, String.class, String.class) .ifPresent(generator::withMutinyReturnTypes); generator.withAdditionalPropertiesAsAttribute(additionalPropertiesAsAttribute); @@ -282,7 +279,7 @@ protected void generate(final Config config, final Path openApiFilePath, final P } private static OpenApiClientGeneratorWrapper createGeneratorWrapper(Path openApiFilePath, Path outDir, - boolean isRestEasyReactive, Boolean verbose, Boolean validateSpec) { + boolean isRestEasyReactive, Boolean verbose, Boolean validateSpec) { if (isRestEasyReactive) { return new OpenApiReactiveClientGeneratorWrapper( openApiFilePath.normalize(), @@ -299,7 +296,8 @@ private static OpenApiClientGeneratorWrapper createGeneratorWrapper(Path openApi } private String getBasePackage(final Config config, final Path openApiFilePath) { - return getValues(config, openApiFilePath, BASE_PACKAGE, String.class) + return config + .getOptionalValue(getSpecConfigName(BASE_PACKAGE, openApiFilePath), String.class) .orElse(String.format("%s.%s", DEFAULT_PACKAGE, getSanitizedFileName(openApiFilePath))); } @@ -324,49 +322,49 @@ private Optional getInputBaseDirRelativeToModule(final Path sourceDir, f }); } - private Optional getValues(final Config config, final Path openApiFilePath, CodegenConfig.ConfigName configName, - Class propertyType) { + private Optional getValues(final Config config, final Path openApiFilePath, CodegenConfigName configName, + Class propertyType) { return getConfigKeyValues(config, openApiFilePath, configName, propertyType) .or(() -> getValuesBySpecConfigName(config, openApiFilePath, configName, propertyType)); } private Optional> getValues(final SmallRyeConfig config, final Path openApiFilePath, - CodegenConfig.ConfigName configName, - Class kClass, Class vClass) { + CodegenConfigName configName, + Class kClass, Class vClass) { return getConfigKeyValues(config, openApiFilePath, configName, kClass, vClass) .or(() -> getValuesBySpecConfigName(config, openApiFilePath, configName, kClass, vClass)); } private static Optional getValuesBySpecConfigName(Config config, Path openApiFilePath, - CodegenConfig.ConfigName configName, - Class propertyType) { + CodegenConfigName configName, + Class propertyType) { return config - .getOptionalValue(CodegenConfig.getSpecConfigName(configName, openApiFilePath), propertyType) - .or(() -> config.getOptionalValue(CodegenConfig.getGlobalConfigName(configName), propertyType)); + .getOptionalValue(CodegenConfigMethods.getSpecConfigName(configName, openApiFilePath), propertyType) + .or(() -> config.getOptionalValue(CodegenConfigMethods.getGlobalConfigName(configName), propertyType)); } private static Optional> getValuesBySpecConfigName(SmallRyeConfig config, Path openApiFilePath, - CodegenConfig.ConfigName configName, Class kClass, Class vClass) { + CodegenConfigName configName, Class kClass, Class vClass) { return config - .getOptionalValues(CodegenConfig.getSpecConfigName(configName, openApiFilePath), kClass, vClass) - .or(() -> config.getOptionalValues(CodegenConfig.getGlobalConfigName(configName), kClass, vClass)); + .getOptionalValues(CodegenConfigMethods.getSpecConfigName(configName, openApiFilePath), kClass, vClass) + .or(() -> config.getOptionalValues(CodegenConfigMethods.getGlobalConfigName(configName), kClass, vClass)); } private static Optional getValuesByConfigKey(Config config, String configName, Class propertyType, - CodegenConfig.ConfigName codegenConfigName) { + CodegenConfigName codegenConfigName) { return config .getOptionalValue(configName, propertyType) - .or(() -> config.getOptionalValue(CodegenConfig.getGlobalConfigName(codegenConfigName), propertyType)); + .or(() -> config.getOptionalValue(CodegenConfigMethods.getGlobalConfigName(codegenConfigName), propertyType)); } - private static Optional> getValuesByConfigKey(SmallRyeConfig config, CodegenConfig.ConfigName configName, - Class kClass, Class vClass, String configKey) { + private static Optional> getValuesByConfigKey(SmallRyeConfig config, CodegenConfigName configName, + Class kClass, Class vClass, String configKey) { return config - .getOptionalValues(CodegenConfig.getSpecConfigNameByConfigKey(configKey, configName), kClass, + .getOptionalValues(CodegenConfigMethods.getSpecConfigNameByConfigKey(configKey, configName), kClass, vClass) - .or(() -> config.getOptionalValues(CodegenConfig.getGlobalConfigName(configName), kClass, vClass)); + .or(() -> config.getOptionalValues(CodegenConfigMethods.getGlobalConfigName(configName), kClass, vClass)); } private static Optional getConfigKeyValue(Config config, Path openApiFilePath) { @@ -377,12 +375,13 @@ private static Optional getConfigKeyValue(Config config, Path openApiFil } private Optional getConfigKeyValues(final Config config, final Path openApiFilePath, - CodegenConfig.ConfigName configName, - Class propertyType) { + CodegenConfigName configName, + Class propertyType) { Optional possibleConfigKey = getConfigKeyValue(config, openApiFilePath); if (possibleConfigKey.isPresent()) { - return getValuesByConfigKey(config, CodegenConfig.getSpecConfigNameByConfigKey(possibleConfigKey.get(), configName), + return getValuesByConfigKey(config, + CodegenConfigMethods.getSpecConfigNameByConfigKey(possibleConfigKey.get(), configName), propertyType, configName); } @@ -390,8 +389,8 @@ private Optional getConfigKeyValues(final Config config, final Path openA } private Optional> getConfigKeyValues(final SmallRyeConfig config, final Path openApiFilePath, - CodegenConfig.ConfigName configName, - Class kClass, Class vClass) { + CodegenConfigName configName, + Class kClass, Class vClass) { Optional possibleConfigKey = getConfigKeyValue(config, openApiFilePath); if (possibleConfigKey.isPresent()) { diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/SpecInputModel.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/SpecInputModel.java index 6f9de7a57..03880210c 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/SpecInputModel.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/SpecInputModel.java @@ -1,10 +1,10 @@ package io.quarkiverse.openapi.generator.deployment.codegen; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSpecConfigName; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.API_NAME_SUFFIX; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.BASE_PACKAGE; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_PREFIX; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_SUFFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.getSpecConfigName; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.API_NAME_SUFFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.BASE_PACKAGE; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.MODEL_NAME_PREFIX; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigName.MODEL_NAME_SUFFIX; import static java.util.Objects.requireNonNull; import java.io.InputStream; @@ -49,7 +49,7 @@ public SpecInputModel(final String filename, final InputStream inputStream, fina * @param modelNamePrefix the prefix name for generated model classes */ public SpecInputModel(final String filename, final InputStream inputStream, final String basePackageName, - final String apiNameSuffix, final String modelNameSuffix, final String modelNamePrefix) { + final String apiNameSuffix, final String modelNameSuffix, final String modelNamePrefix) { this(filename, inputStream, basePackageName); Path openApiFilePath = Path.of(filename); this.codegenProperties.put(getSpecConfigName(API_NAME_SUFFIX, openApiFilePath), apiNameSuffix); diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java index f7aa635c0..08efbb3ac 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java @@ -1,8 +1,8 @@ package io.quarkiverse.openapi.generator.deployment.wrapper; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSanitizedFileName; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveApiPackage; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveModelPackage; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.getSanitizedFileName; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.resolveApiPackage; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.resolveModelPackage; import static io.quarkiverse.openapi.generator.deployment.wrapper.QuarkusJavaClientCodegen.QUARKUS_GENERATOR_NAME; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; @@ -53,8 +53,8 @@ public abstract class OpenApiClientGeneratorWrapper { private String modelPackage = ""; OpenApiClientGeneratorWrapper(final QuarkusCodegenConfigurator configurator, final Path specFilePath, final Path outputDir, - final boolean verbose, - final boolean validateSpec) { + final boolean verbose, + final boolean validateSpec) { // do not generate docs nor tests GlobalSettings.setProperty(CodegenConstants.API_DOCS, FALSE.toString()); GlobalSettings.setProperty(CodegenConstants.API_TESTS, FALSE.toString()); @@ -118,13 +118,6 @@ public OpenApiClientGeneratorWrapper withMutiny(final Boolean config) { return this; } - public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final Boolean config) { - if (config != null) { - configurator.addAdditionalProperty("mutiny-return-response", config); - } - return this; - } - public OpenApiClientGeneratorWrapper withMutinyReturnTypes(final Map returnTypeMappings) { if (returnTypeMappings != null && !returnTypeMappings.isEmpty()) { Map mutinyOperationIdsMap = new HashMap<>(returnTypeMappings); diff --git a/client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigTest.java b/client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigTest.java index e0af2202f..c27583910 100644 --- a/client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigTest.java +++ b/client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/CodegenConfigTest.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.deployment; -import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.BUILD_TIME_SPEC_PREFIX_FORMAT; +import static io.quarkiverse.openapi.generator.deployment.CodegenConfigMethods.BUILD_TIME_SPEC_PREFIX_FORMAT; import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.file.Path; @@ -11,21 +11,21 @@ class CodegenConfigTest { @Test void verifyStreamUri() { - final String resolvedPrefix = CodegenConfig + final String resolvedPrefix = CodegenConfigMethods .getBuildTimeSpecPropertyPrefix(Path.of("/home/myuser/open-api-stream/luke/my test openapi.json")); assertEquals(String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, "luke_my_test_openapi_json"), resolvedPrefix); } @Test void verifySpaceEncoding() { - final String resolvedPrefix = CodegenConfig + final String resolvedPrefix = CodegenConfigMethods .getBuildTimeSpecPropertyPrefix(Path.of("/home/myuser/luke/my test openapi.json")); assertEquals(String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, "my_test_openapi_json"), resolvedPrefix); } @Test void withSingleFileName() { - final String resolvedPrefix = CodegenConfig.getBuildTimeSpecPropertyPrefix(Path.of("my test openapi.json")); + final String resolvedPrefix = CodegenConfigMethods.getBuildTimeSpecPropertyPrefix(Path.of("my test openapi.json")); assertEquals(String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, "my_test_openapi_json"), resolvedPrefix); } diff --git a/client/runtime/pom.xml b/client/runtime/pom.xml index 24dd902af..26931507a 100644 --- a/client/runtime/pom.xml +++ b/client/runtime/pom.xml @@ -94,9 +94,6 @@ ${quarkus.version} - - -AlegacyConfigRoot=true - diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfig.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfig.java index 5a1e57987..e69070f33 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfig.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfig.java @@ -6,19 +6,15 @@ import io.quarkiverse.openapi.generator.providers.ApiKeyAuthenticationProvider; import io.quarkiverse.openapi.generator.providers.BasicAuthenticationProvider; import io.quarkiverse.openapi.generator.providers.BearerAuthenticationProvider; -import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; /** * This class represents the runtime authentication related configuration for an individual securityScheme present * on an OpenApi spec definition, i.e. the provided files. */ -@ConfigGroup -public class AuthConfig { - - public static final String TOKEN_PROPAGATION = "token-propagation"; - public static final String HEADER_NAME = "header-name"; - +public interface AuthConfig { /** * Enables the authentication token propagation for this particular securityScheme. *

@@ -31,8 +27,8 @@ public class AuthConfig { * @see SpecItemConfig * @see OpenApiGeneratorConfig */ - @ConfigItem(defaultValue = "false") - public Optional tokenPropagation; + @WithDefault("false") + Optional tokenPropagation(); /** * Configures a particular http header attribute from were to take the security token from when the token propagation @@ -47,8 +43,7 @@ public class AuthConfig { * @see SpecItemConfig * @see OpenApiGeneratorConfig */ - @ConfigItem - public Optional headerName; + Optional headerName(); /** * Configures a particular parameter value to be used by any of the different internal authentication filters @@ -68,27 +63,6 @@ public class AuthConfig { * @see BearerAuthenticationProvider * @see ApiKeyAuthenticationProvider */ - @ConfigItem(name = ConfigItem.PARENT) - public Map authConfigParams; - - public Optional getTokenPropagation() { - return tokenPropagation; - } - - public Optional getHeaderName() { - return headerName; - } - - public Optional getConfigParam(String paramName) { - return Optional.ofNullable(authConfigParams.get(paramName)); - } - - @Override - public String toString() { - return "AuthConfig{" + - "tokenPropagation=" + tokenPropagation + - ", headerName=" + headerName + - ", authConfigParams=" + authConfigParams + - '}'; - } + @WithName(ConfigItem.PARENT) + Map> authConfigParams(); } diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfigConsts.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfigConsts.java new file mode 100644 index 000000000..09bcd1d3b --- /dev/null +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthConfigConsts.java @@ -0,0 +1,6 @@ +package io.quarkiverse.openapi.generator; + +public class AuthConfigConsts { + public static final String TOKEN_PROPAGATION = "token-propagation"; + public static final String HEADER_NAME = "header-name"; +} diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthsConfig.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthsConfig.java index a02f00c11..220cfa0b3 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthsConfig.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/AuthsConfig.java @@ -3,11 +3,10 @@ import java.util.Map; import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithName; -@ConfigGroup -public class AuthsConfig { +public interface AuthsConfig { /** * Configurations for the individual securitySchemes present on a given OpenApi spec definition file. @@ -21,17 +20,17 @@ public class AuthsConfig { * @see SpecItemConfig * @see AuthConfig */ - @ConfigItem(name = ConfigItem.PARENT) - public Map authConfigs; + @WithName(ConfigItem.PARENT) + Map> authConfigs(); - public Optional getItemConfig(String authConfig) { - return Optional.ofNullable(authConfigs.get(authConfig)); - } - - @Override - public String toString() { - return "AuthsConfig{" + - "authConfigs=" + authConfigs + - '}'; - } + // public Optional getItemConfig(String authConfig) { + // return Optional.ofNullable(authConfigs.get(authConfig)); + // } + // + // @Override + // public String toString() { + // return "AuthsConfig{" + + // "authConfigs=" + authConfigs + + // '}'; + // } } diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfig.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfig.java index 6b297f577..e603cf6e0 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfig.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfig.java @@ -6,16 +6,15 @@ import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.smallrye.config.common.utils.StringUtil; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithName; /** * This class represents the runtime configurations for the openapi-generator extension. */ -@ConfigRoot(name = OpenApiGeneratorConfig.RUNTIME_TIME_CONFIG_PREFIX, phase = ConfigPhase.RUN_TIME) -public class OpenApiGeneratorConfig { - - public static final String RUNTIME_TIME_CONFIG_PREFIX = "openapi-generator"; - +@ConfigMapping(prefix = OpenApiGeneratorConfigMethods.RUNTIME_TIME_CONFIG_PREFIX) +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface OpenApiGeneratorConfig { /** * Configurations of the individual OpenApi spec definitions, i.e. the provided files. *

@@ -23,21 +22,6 @@ public class OpenApiGeneratorConfig { * For example, a file named petstore.json is sanitized into the name petstore_json, and thus the specific * configurations this file must start with the prefix quarkus.openapi-generator.petstore_json */ - @ConfigItem(name = ConfigItem.PARENT) - public Map itemConfigs; - - public Optional getItemConfig(String specItem) { - return Optional.ofNullable(itemConfigs.get(specItem)); - } - - @Override - public String toString() { - return "OpenApiGeneratorConfig{" + - "itemConfigs=" + itemConfigs + - '}'; - } - - public static String getSanitizedSecuritySchemeName(final String securitySchemeName) { - return StringUtil.replaceNonAlphanumericByUnderscores(securitySchemeName); - } + @WithName(ConfigItem.PARENT) + Map> itemConfigs(); } diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfigMethods.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfigMethods.java new file mode 100644 index 000000000..b164c6f92 --- /dev/null +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/OpenApiGeneratorConfigMethods.java @@ -0,0 +1,11 @@ +package io.quarkiverse.openapi.generator; + +import io.smallrye.config.common.utils.StringUtil; + +public class OpenApiGeneratorConfigMethods { + public static final String RUNTIME_TIME_CONFIG_PREFIX = "openapi-generator"; + + public static String getSanitizedSecuritySchemeName(final String securitySchemeName) { + return StringUtil.replaceNonAlphanumericByUnderscores(securitySchemeName); + } +} diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/SpecItemConfig.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/SpecItemConfig.java index 91c79b656..ddbf0f6f7 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/SpecItemConfig.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/SpecItemConfig.java @@ -2,15 +2,11 @@ import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; - /** * This class represents the runtime authentication related configurations for the individual OpenApi spec definitions, * i.e. the provided files. */ -@ConfigGroup -public class SpecItemConfig { +public interface SpecItemConfig { /** * Authentication related configurations for the different securitySchemes present on a given OpenApi spec @@ -21,17 +17,5 @@ public class SpecItemConfig { * * @see AuthsConfig */ - @ConfigItem - public AuthsConfig auth; - - public Optional getAuth() { - return Optional.ofNullable(auth); - } - - @Override - public String toString() { - return "SpecItemConfig{" + - "auth=" + auth + - '}'; - } -} \ No newline at end of file + Optional auth(); +} diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java index 5cea1954b..d101d284f 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.providers; -import static io.quarkiverse.openapi.generator.OpenApiGeneratorConfig.RUNTIME_TIME_CONFIG_PREFIX; +import static io.quarkiverse.openapi.generator.OpenApiGeneratorConfigMethods.RUNTIME_TIME_CONFIG_PREFIX; import static io.quarkiverse.openapi.generator.providers.AbstractAuthenticationPropagationHeadersFactory.propagationHeaderName; import java.util.ArrayList; @@ -46,11 +46,11 @@ protected void init(String name, String openApiSpecId) { private void setOpenApiSpecId(String openApiSpecId) { this.openApiSpecId = openApiSpecId; Optional specItemConfig = Objects.requireNonNull(generatorConfig, "generatorConfig can't be null.") - .getItemConfig(openApiSpecId); + .itemConfigs().get(openApiSpecId); if (specItemConfig.isPresent()) { - Optional authsConfig = specItemConfig.get().getAuth(); + Optional authsConfig = specItemConfig.get().auth(); authsConfig.ifPresent( - specItemAuthsConfig -> authConfig = specItemAuthsConfig.getItemConfig(name).orElse(null)); + specItemAuthsConfig -> authConfig = specItemAuthsConfig.authConfigs().get(name).orElse(null)); } } @@ -68,7 +68,7 @@ public OpenApiGeneratorConfig getGeneratorConfig() { } public boolean isTokenPropagation() { - return authConfig != null && authConfig.getTokenPropagation().orElse(false); + return authConfig != null && authConfig.tokenPropagation().orElse(false); } public String getTokenForPropagation(MultivaluedMap httpHeaders) { @@ -79,7 +79,7 @@ public String getTokenForPropagation(MultivaluedMap httpHeaders) public String getHeaderName() { if (authConfig != null) { - return authConfig.getHeaderName().orElse(null); + return authConfig.headerName().orElse(null); } return null; } @@ -97,7 +97,7 @@ public AuthProvider addOperation(OperationAuthInfo operationAuthInfo) { public String getAuthConfigParam(String paramName, String defaultValue) { if (authConfig != null) { - return authConfig.getConfigParam(paramName).orElse(defaultValue); + return authConfig.authConfigParams().get(paramName).orElse(defaultValue); } return defaultValue; } diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractCompositeAuthenticationProvider.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractCompositeAuthenticationProvider.java index a7ce09ff2..b02acdc41 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractCompositeAuthenticationProvider.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractCompositeAuthenticationProvider.java @@ -11,7 +11,7 @@ import jakarta.ws.rs.client.ClientRequestContext; import jakarta.ws.rs.client.ClientRequestFilter; -import io.quarkiverse.openapi.generator.OpenApiGeneratorConfig; +import io.quarkiverse.openapi.generator.OpenApiGeneratorConfigMethods; /** * Composition of supported {@link ClientRequestFilter} defined by a given OpenAPI interface. @@ -54,7 +54,7 @@ private boolean canFilter(final AuthProvider authProvider, final ClientRequestCo } protected static String sanitizeAuthName(String schemeName) { - return OpenApiGeneratorConfig.getSanitizedSecuritySchemeName(schemeName); + return OpenApiGeneratorConfigMethods.getSanitizedSecuritySchemeName(schemeName); } /** diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProvider.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProvider.java index e949fb3ff..2ebb7655b 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProvider.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProvider.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.providers; -import static io.quarkiverse.openapi.generator.AuthConfig.TOKEN_PROPAGATION; +import static io.quarkiverse.openapi.generator.AuthConfigConsts.TOKEN_PROPAGATION; import java.io.IOException; @@ -29,8 +29,8 @@ public class ApiKeyAuthenticationProvider extends AbstractAuthProvider { private final String apiKeyName; public ApiKeyAuthenticationProvider(final String openApiSpecId, final String name, final ApiKeyIn apiKeyIn, - final String apiKeyName, - final OpenApiGeneratorConfig generatorConfig) { + final String apiKeyName, + final OpenApiGeneratorConfig generatorConfig) { super(generatorConfig); init(name, openApiSpecId); this.apiKeyIn = apiKeyIn; diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProvider.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProvider.java index 5f9742e5c..dbd186934 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProvider.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProvider.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.providers; -import static io.quarkiverse.openapi.generator.AuthConfig.TOKEN_PROPAGATION; +import static io.quarkiverse.openapi.generator.AuthConfigConsts.TOKEN_PROPAGATION; import java.io.IOException; diff --git a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/OAuth2AuthenticationProvider.java b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/OAuth2AuthenticationProvider.java index 2a8915b14..8fe3d4bcc 100644 --- a/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/OAuth2AuthenticationProvider.java +++ b/client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/OAuth2AuthenticationProvider.java @@ -1,6 +1,6 @@ package io.quarkiverse.openapi.generator.providers; -import static io.quarkiverse.openapi.generator.AuthConfig.TOKEN_PROPAGATION; +import static io.quarkiverse.openapi.generator.AuthConfigConsts.TOKEN_PROPAGATION; import java.io.IOException; @@ -52,7 +52,7 @@ public void filter(ClientRequestContext requestContext) throws IOException { private void validateConfig() { if (isTokenPropagation()) { LOGGER.warn("Token propagation was enabled for a the oauth2: {} securityScheme in the specification file: {}. " + - "This configuration can be done by using the property: {} and is not necessary a problem if the configuration is intentional.", + "This configuration can be done by using the property: {} and is not necessary a problem if the configuration is intentional.", getName(), getOpenApiSpecId(), getCanonicalAuthConfigPropertyName(TOKEN_PROPAGATION)); } } diff --git a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/AbstractAuthenticationProviderTest.java b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/AbstractAuthenticationProviderTest.java index dc5f89583..a87c2ed24 100644 --- a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/AbstractAuthenticationProviderTest.java +++ b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/AbstractAuthenticationProviderTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.lenient; -import java.util.HashMap; +import java.util.Map; import java.util.Optional; import jakarta.ws.rs.client.ClientRequestContext; @@ -26,7 +26,12 @@ abstract class AbstractAuthenticationProviderTest> itemConfigs() { + return Map.of(); + } + }; protected AuthConfig authConfig; @@ -44,20 +49,125 @@ void setUp() { } protected abstract T createProvider(String openApiSpecId, String authSchemeName, - OpenApiGeneratorConfig openApiGeneratorConfig); + OpenApiGeneratorConfig openApiGeneratorConfig); protected void createConfiguration() { - generatorConfig = new OpenApiGeneratorConfig(); - generatorConfig.itemConfigs = new HashMap<>(); - SpecItemConfig specItemConfig = new SpecItemConfig(); - specItemConfig.auth = new AuthsConfig(); - specItemConfig.auth.authConfigs = new HashMap<>(); - authConfig = new AuthConfig(); - authConfig.headerName = Optional.empty(); - authConfig.tokenPropagation = Optional.of(false); - authConfig.authConfigParams = new HashMap<>(); - specItemConfig.auth.authConfigs.put(AUTH_SCHEME_NAME, authConfig); - generatorConfig.itemConfigs.put(OPEN_API_FILE_SPEC_ID, specItemConfig); + authConfig = new AuthConfig() { + @Override + public Optional tokenPropagation() { + return Optional.empty(); + } + + @Override + public Optional headerName() { + return Optional.empty(); + } + + @Override + public Map> authConfigParams() { + return Map.of(); + } + }; + + SpecItemConfig specItemConfig = new SpecItemConfig() { + @Override + public Optional auth() { + return Optional.empty(); + } + }; + + specItemConfig.auth().isPresent().put(AUTH_SCHEME_NAME, authConfig); + generatorConfig.itemConfigs().put(OPEN_API_FILE_SPEC_ID, specItemConfig); + headers = new MultivaluedHashMap<>(); + lenient().doReturn(headers).when(requestContext).getHeaders(); + } + + protected void assertHeader(MultivaluedMap headers, String headerName, String value) { + assertThat(headers.getFirst(headerName)) + .isNotNull() + .isEqualTo(value); + } +} +package io.quarkiverse.openapi.generator.providers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.lenient; + +import java.util.Map; +import java.util.Optional; + +import jakarta.ws.rs.client.ClientRequestContext; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import io.quarkiverse.openapi.generator.AuthConfig; +import io.quarkiverse.openapi.generator.AuthsConfig; +import io.quarkiverse.openapi.generator.OpenApiGeneratorConfig; +import io.quarkiverse.openapi.generator.SpecItemConfig; + +@ExtendWith(MockitoExtension.class) +abstract class AbstractAuthenticationProviderTest { + + protected static final String OPEN_API_FILE_SPEC_ID = "open_api_file_spec_id_json"; + protected static final String AUTH_SCHEME_NAME = "auth_scheme_name"; + + protected OpenApiGeneratorConfig generatorConfig = new OpenApiGeneratorConfig() { + @Override + public Map> itemConfigs() { + return Map.of(); + } + }; + + protected AuthConfig authConfig; + + @Mock + protected ClientRequestContext requestContext; + + protected MultivaluedMap headers; + + protected T provider; + + @BeforeEach + void setUp() { + createConfiguration(); + provider = createProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, generatorConfig); + } + + protected abstract T createProvider(String openApiSpecId, String authSchemeName, + OpenApiGeneratorConfig openApiGeneratorConfig); + + protected void createConfiguration() { + authConfig = new AuthConfig() { + @Override + public Optional tokenPropagation() { + return Optional.empty(); + } + + @Override + public Optional headerName() { + return Optional.empty(); + } + + @Override + public Map> authConfigParams() { + return Map.of(); + } + }; + + SpecItemConfig specItemConfig = new SpecItemConfig() { + @Override + public Optional auth() { + return Optional.empty(); + } + }; + + specItemConfig.auth().isPresent().put(AUTH_SCHEME_NAME, authConfig); + generatorConfig.itemConfigs().put(OPEN_API_FILE_SPEC_ID, specItemConfig); headers = new MultivaluedHashMap<>(); lenient().doReturn(headers).when(requestContext).getHeaders(); } diff --git a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProviderTest.java b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProviderTest.java index 992cf65d6..026a194cc 100644 --- a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProviderTest.java +++ b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/ApiKeyAuthenticationProviderTest.java @@ -9,7 +9,6 @@ import java.net.URI; import java.util.List; import java.util.Objects; -import java.util.Optional; import jakarta.ws.rs.core.Cookie; import jakarta.ws.rs.core.HttpHeaders; @@ -37,12 +36,12 @@ class ApiKeyAuthenticationProviderTest extends AbstractAuthenticationProviderTes @Override protected void createConfiguration() { super.createConfiguration(); - authConfig.authConfigParams.put(ApiKeyAuthenticationProvider.API_KEY, API_KEY_VALUE); + authConfig.authConfigParams().put(ApiKeyAuthenticationProvider.API_KEY, API_KEY_VALUE); } @Override protected ApiKeyAuthenticationProvider createProvider(String openApiSpecId, String authSchemeName, - OpenApiGeneratorConfig openApiGeneratorConfig) { + OpenApiGeneratorConfig openApiGeneratorConfig) { return new ApiKeyAuthenticationProvider(openApiSpecId, authSchemeName, ApiKeyIn.header, API_KEY_NAME, openApiGeneratorConfig); } @@ -56,20 +55,20 @@ void filterHeaderFromAuthorizationHeaderDefaultCase() throws IOException { @Test void filterHeaderFromAuthorizationHeaderCase() throws IOException { - authConfig.authConfigParams.put(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE, "true"); + authConfig.authConfigParams().put(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE, "true"); doReturn(API_KEY_AUTH_HEADER_VALUE).when(requestContext).getHeaderString("Authorization"); provider.filter(requestContext); assertHeader(headers, API_KEY_NAME, API_KEY_AUTH_HEADER_VALUE); - authConfig.authConfigParams.remove(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE); + authConfig.authConfigParams().remove(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE); } @Test void filterHeaderNotFromAuthorizationHeaderCase() throws IOException { - authConfig.authConfigParams.put(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE, "false"); + authConfig.authConfigParams().put(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE, "false"); doReturn(API_KEY_AUTH_HEADER_VALUE).when(requestContext).getHeaderString("Authorization"); provider.filter(requestContext); assertHeader(headers, API_KEY_NAME, API_KEY_VALUE); - authConfig.authConfigParams.remove(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE); + authConfig.authConfigParams().remove(ApiKeyAuthenticationProvider.USE_AUTHORIZATION_HEADER_VALUE); } @Test @@ -125,7 +124,6 @@ void filterCookieCaseExisting() throws IOException { @Test void tokenPropagationNotSupported() { - authConfig.tokenPropagation = Optional.of(true); assertThatThrownBy(() -> new ApiKeyAuthenticationProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, ApiKeyIn.header, API_KEY_NAME, generatorConfig)) .hasMessageContaining("quarkus.openapi-generator.%s.auth.%s.token-propagation", OPEN_API_FILE_SPEC_ID, diff --git a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProviderTest.java b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProviderTest.java index 8b388b64c..59f6bf93a 100644 --- a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProviderTest.java +++ b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProviderTest.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.util.Base64; -import java.util.Optional; import jakarta.ws.rs.core.HttpHeaders; @@ -22,21 +21,20 @@ class BasicAuthenticationProviderTest extends AbstractAuthenticationProviderTest @Override protected BasicAuthenticationProvider createProvider(String openApiSpecId, String authSchemeName, - OpenApiGeneratorConfig openApiGeneratorConfig) { + OpenApiGeneratorConfig openApiGeneratorConfig) { return new BasicAuthenticationProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, openApiGeneratorConfig); } @Test void filter() throws IOException { - authConfig.authConfigParams.put(BasicAuthenticationProvider.USER_NAME, USER); - authConfig.authConfigParams.put(BasicAuthenticationProvider.PASSWORD, PASSWORD); + authConfig.authConfigParams().put(BasicAuthenticationProvider.USER_NAME, USER); + authConfig.authConfigParams().put(BasicAuthenticationProvider.PASSWORD, PASSWORD); provider.filter(requestContext); assertHeader(requestContext.getHeaders(), HttpHeaders.AUTHORIZATION, EXPECTED_BASIC_TOKEN); } @Test void tokenPropagationNotSupported() { - authConfig.tokenPropagation = Optional.of(true); assertThatThrownBy(() -> new BasicAuthenticationProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, generatorConfig)) .hasMessageContaining("quarkus.openapi-generator.%s.auth.%s.token-propagation", OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME); diff --git a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProviderTest.java b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProviderTest.java index bf5b2036f..0f874b7e6 100644 --- a/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProviderTest.java +++ b/client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProviderTest.java @@ -3,7 +3,6 @@ import static io.quarkiverse.openapi.generator.providers.AbstractAuthenticationPropagationHeadersFactory.propagationHeaderName; import java.io.IOException; -import java.util.Optional; import java.util.stream.Stream; import jakarta.ws.rs.core.HttpHeaders; @@ -26,7 +25,7 @@ class BearerAuthenticationProviderTest extends AbstractAuthenticationProviderTes @Override protected BearerAuthenticationProvider createProvider(String openApiSpecId, String authSchemeName, - OpenApiGeneratorConfig openApiGeneratorConfig) { + OpenApiGeneratorConfig openApiGeneratorConfig) { return new BearerAuthenticationProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, null, openApiGeneratorConfig); } @@ -47,7 +46,7 @@ void filterCustomSchemaCase() throws IOException { private void filter(String bearerScheme, String currentToken, String expectedAuthorizationHeader) throws IOException { provider = new BearerAuthenticationProvider(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, bearerScheme, generatorConfig); - authConfig.authConfigParams.put(BearerAuthenticationProvider.BEARER_TOKEN, currentToken); + authConfig.authConfigParams().put(BearerAuthenticationProvider.BEARER_TOKEN, currentToken); provider.filter(requestContext); assertHeader(headers, HttpHeaders.AUTHORIZATION, expectedAuthorizationHeader); } @@ -55,9 +54,9 @@ private void filter(String bearerScheme, String currentToken, String expectedAut @ParameterizedTest @MethodSource("filterWithPropagationTestValues") void filterWithPropagation(String headerName, - String currentToken, - String bearerScheme, - String expectedAuthorizationHeader) throws IOException { + String currentToken, + String bearerScheme, + String expectedAuthorizationHeader) throws IOException { String propagatedHeaderName; if (headerName == null) { propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, @@ -67,8 +66,8 @@ void filterWithPropagation(String headerName, HEADER_NAME); } headers.putSingle(propagatedHeaderName, INCOMING_TOKEN); - authConfig.tokenPropagation = Optional.of(true); - authConfig.headerName = Optional.ofNullable(headerName); + // authConfig.tokenPropagation() = Optional.of(true); + // authConfig.headerName( = Optional.ofNullable(headerName); filter(bearerScheme, currentToken, expectedAuthorizationHeader); }