diff --git a/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroup.java b/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroup.java index 2a5d660938..dd5c6f137b 100644 --- a/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroup.java +++ b/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroup.java @@ -40,19 +40,19 @@ public @interface OpenAPIGroup { /** - * @return The names of the OpenAPi groups. + * @return The names of the OpenAPI groups. */ @AliasFor(member = "names") String[] value() default {}; /** - * @return The names of the OpenAPi groups. + * @return The names of the OpenAPI groups. */ @AliasFor(member = "value") String[] names() default {}; /** - * @return The names of the OpenAPi groups to exclude endpoints from. + * @return The names of the OpenAPI groups to exclude endpoints from. */ String[] exclude() default {}; diff --git a/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroupInfo.java b/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroupInfo.java index 82dcc1df1f..41ce1fa78b 100644 --- a/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroupInfo.java +++ b/openapi-annotations/src/main/java/io/micronaut/openapi/annotation/OpenAPIGroupInfo.java @@ -41,13 +41,13 @@ public @interface OpenAPIGroupInfo { /** - * @return The names of the OpenAPi groups. + * @return The names of the OpenAPI groups. */ @AliasFor(member = "names") String[] value() default {}; /** - * @return The names of the OpenAPi groups. + * @return The names of the OpenAPI groups. */ @AliasFor(member = "value") String[] names() default {}; diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java index 76e1f1696c..e237243b34 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java @@ -1282,6 +1282,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation break; } } + op.vendorExtensions.put("hasNotBodyParam", notBodyParamsSize > 0); + op.vendorExtensions.put("hasMultipleParams", hasMultipleParams); for (var param : op.allParams) { param.vendorExtensions.put("hasNotBodyParam", notBodyParamsSize > 0); param.vendorExtensions.put("hasMultipleParams", hasMultipleParams); @@ -1879,6 +1881,13 @@ public boolean getUseInlineModelResolver() { return false; } + public void setGenerateSwaggerAnnotations(boolean generateSwaggerAnnotations) { + this.generateSwaggerAnnotations = Boolean.toString(generateSwaggerAnnotations); + if (generateSwaggerAnnotations) { + additionalProperties.put("generateSwagger2Annotations", true); + } + } + @Override public void postProcess() { // disable output donation suggestion diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java index 2b7308875a..ba430251c5 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java @@ -121,6 +121,8 @@ public abstract class AbstractMicronautKotlinCodegen operationList = operations.getOperation(); for (CodegenOperation op : operationList) { + + handleImplicitHeaders(op); + handleConstantParams(op); + // Set whether body is supported in request op.vendorExtensions.put("methodAllowsBody", op.httpMethod.equals("PUT") || op.httpMethod.equals("POST") @@ -947,6 +968,34 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List copy = new ArrayList<>(operation.allParams); + operation.allParams.clear(); + + for (CodegenParameter p : copy) { + if (p.isHeaderParam && (implicitHeaders || shouldBeImplicitHeader(p))) { + operation.implicitHeadersParams.add(p); + operation.headerParams.removeIf(header -> header.baseName.equals(p.baseName)); + once(log).info("Update operation [{}]. Remove header [{}] because it's marked to be implicit", operation.operationId, p.baseName); + } else { + operation.allParams.add(p); + } + } + operation.hasParams = !operation.allParams.isEmpty(); + } + + private boolean shouldBeImplicitHeader(CodegenParameter parameter) { + return StringUtils.isNotBlank(implicitHeadersRegex) && parameter.baseName.matches(implicitHeadersRegex); + } + @Override public String toEnumValue(String value, String datatype) { if ("Integer".equals(datatype) @@ -1175,6 +1224,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation break; } } + op.vendorExtensions.put("hasNotBodyParam", notBodyParamsSize > 0); + op.vendorExtensions.put("hasMultipleParams", hasMultipleParams); for (var param : op.allParams) { param.vendorExtensions.put("hasNotBodyParam", notBodyParamsSize > 0); param.vendorExtensions.put("hasMultipleParams", hasMultipleParams); @@ -1991,6 +2042,13 @@ public boolean getUseInlineModelResolver() { return false; } + public void setGenerateSwaggerAnnotations(boolean generateSwaggerAnnotations) { + this.generateSwaggerAnnotations = Boolean.toString(generateSwaggerAnnotations); + if (generateSwaggerAnnotations) { + additionalProperties.put("generateSwagger2Annotations", true); + } + } + @Override public void postProcess() { // disable output donation suggestion diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java index a0991a8497..45a463df7e 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java @@ -180,16 +180,21 @@ private void configureOptions() { if (options.modelNameSuffix != null && !options.modelNameSuffix.isBlank()) { javaCodeGen.setModelNameSuffix(options.modelNameSuffix); } + javaCodeGen.setImplicitHeaders(options.implicitHeaders); + if (options.implicitHeadersRegex != null && !options.implicitHeadersRegex.isBlank()) { + javaCodeGen.setImplicitHeadersRegex(options.implicitHeadersRegex); + } - javaCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces()); + javaCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces); javaCodeGen.setReactive(options.reactive); javaCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways); javaCodeGen.setGenerateHttpResponseWhereRequired(options.generateHttpResponseWhereRequired); javaCodeGen.setUseOptional(options.optional); javaCodeGen.setUseBeanValidation(options.beanValidation); javaCodeGen.setTestTool(options.testFramework.value); - javaCodeGen.setSerializationLibrary(options.serializationLibraryKind().name()); - javaCodeGen.setDateTimeLibrary(options.dateTimeFormat().name()); + javaCodeGen.setSerializationLibrary(options.serializationLibraryKind.name()); + javaCodeGen.setGenerateSwaggerAnnotations(options.generateSwaggerAnnotations); + javaCodeGen.setDateTimeLibrary(options.dateTimeFormat.name()); configureJavaServerOptions(); configureJavaClientOptions(); } else if (options.lang == GeneratorLanguage.KOTLIN && codeGenerator instanceof AbstractMicronautKotlinCodegen kotlinCodeGen) { @@ -245,14 +250,19 @@ private void configureOptions() { if (options.modelNameSuffix != null && !options.modelNameSuffix.isBlank()) { kotlinCodeGen.setModelNameSuffix(options.modelNameSuffix); } + kotlinCodeGen.setImplicitHeaders(options.implicitHeaders); + if (options.implicitHeadersRegex != null && !options.implicitHeadersRegex.isBlank()) { + kotlinCodeGen.setImplicitHeadersRegex(options.implicitHeadersRegex); + } kotlinCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces); kotlinCodeGen.setReactive(options.reactive); kotlinCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways); kotlinCodeGen.setGenerateHttpResponseWhereRequired(options.generateHttpResponseWhereRequired); + kotlinCodeGen.setGenerateSwaggerAnnotations(options.generateSwaggerAnnotations); kotlinCodeGen.setUseBeanValidation(options.beanValidation); kotlinCodeGen.setTestTool(options.testFramework.value); - kotlinCodeGen.setSerializationLibrary(options.serializationLibraryKind().name()); - kotlinCodeGen.setDateTimeLibrary(options.dateTimeFormat().name()); + kotlinCodeGen.setSerializationLibrary(options.serializationLibraryKind.name()); + kotlinCodeGen.setDateTimeLibrary(options.dateTimeFormat.name()); configureKotlinServerOptions(); configureKotlinClientOptions(); } @@ -511,11 +521,15 @@ private static class DefaultOptionsBuilder implements MicronautCodeGeneratorOpti private String modelNamePrefix; private String modelNameSuffix; + private boolean implicitHeaders; + private String implicitHeadersRegex; + private boolean optional; private boolean reactive = true; private boolean useOneOfInterfaces = true; private boolean generateHttpResponseAlways; private boolean generateHttpResponseWhereRequired = true; + private boolean generateSwaggerAnnotations; private TestFramework testFramework = TestFramework.JUNIT5; private SerializationLibraryKind serializationLibraryKind = SerializationLibraryKind.MICRONAUT_SERDE_JACKSON; private DateTimeFormat dateTimeFormat = DateTimeFormat.ZONED_DATETIME; @@ -641,6 +655,18 @@ public MicronautCodeGeneratorOptionsBuilder withModelNameSuffix(String modelName return this; } + @Override + public MicronautCodeGeneratorOptionsBuilder withImplicitHeaders(boolean implicitHeaders) { + this.implicitHeaders = implicitHeaders; + return this; + } + + @Override + public MicronautCodeGeneratorOptionsBuilder withImplicitHeadersRegex(String implicitHeadersRegex) { + this.implicitHeadersRegex = implicitHeadersRegex; + return this; + } + @Override public MicronautCodeGeneratorOptionsBuilder withReactive(boolean reactive) { this.reactive = reactive; @@ -659,6 +685,12 @@ public MicronautCodeGeneratorOptionsBuilder withGenerateHttpResponseWhereRequire return this; } + @Override + public MicronautCodeGeneratorOptionsBuilder withGenerateSwaggerAnnotations(boolean generateSwaggerAnnotations) { + this.generateSwaggerAnnotations = generateSwaggerAnnotations; + return this; + } + @Override public MicronautCodeGeneratorOptionsBuilder withBeanValidation(boolean beanValidation) { this.beanValidation = beanValidation; @@ -719,12 +751,16 @@ private Options build() { modelNamePrefix, modelNameSuffix, + implicitHeaders, + implicitHeadersRegex, + beanValidation, optional, reactive, useOneOfInterfaces, generateHttpResponseAlways, generateHttpResponseWhereRequired, + generateSwaggerAnnotations, testFramework, serializationLibraryKind, dateTimeFormat); @@ -771,12 +807,16 @@ private record Options( String modelNamePrefix, String modelNameSuffix, + boolean implicitHeaders, + String implicitHeadersRegex, + boolean beanValidation, boolean optional, boolean reactive, boolean useOneOfInterfaces, boolean generateHttpResponseAlways, boolean generateHttpResponseWhereRequired, + boolean generateSwaggerAnnotations, TestFramework testFramework, SerializationLibraryKind serializationLibraryKind, MicronautCodeGeneratorOptionsBuilder.DateTimeFormat dateTimeFormat diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java index d6431f85d1..72cee45e3f 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java @@ -145,9 +145,9 @@ public interface MicronautCodeGeneratorOptionsBuilder { MicronautCodeGeneratorOptionsBuilder withInlineSchemaOption(Map inlineSchemaOption); /** - * Add the OpenAPi normalizer options. + * Add the OpenAPI normalizer options. * - * @param openapiNormalizer the OpenAPi normalizer options + * @param openapiNormalizer the OpenAPI normalizer options * @return this builder */ MicronautCodeGeneratorOptionsBuilder withOpenapiNormalizer(Map openapiNormalizer); @@ -184,6 +184,22 @@ public interface MicronautCodeGeneratorOptionsBuilder { */ MicronautCodeGeneratorOptionsBuilder withModelNameSuffix(String modelNameSuffix); + /** + * Set the implicit headers flag. + * + * @param implicitHeaders implicit headers + * @return this builder + */ + MicronautCodeGeneratorOptionsBuilder withImplicitHeaders(boolean implicitHeaders); + + /** + * Set the implicit headers regex. + * + * @param implicitHeadersRegex implicit headers regex + * @return this builder + */ + MicronautCodeGeneratorOptionsBuilder withImplicitHeadersRegex(String implicitHeadersRegex); + /** * If set to true, the generator will use reactive types. * @@ -208,6 +224,14 @@ public interface MicronautCodeGeneratorOptionsBuilder { */ MicronautCodeGeneratorOptionsBuilder withGenerateHttpResponseWhereRequired(boolean generateHttpResponseWhereRequired); + /** + * If set to true, controller and client method will be generated with openAPI annotations. + * + * @param generateSwaggerAnnotations the generate swagger annotations flag + * @return this builder + */ + MicronautCodeGeneratorOptionsBuilder withGenerateSwaggerAnnotations(boolean generateSwaggerAnnotations); + /** * If set to true, the generated code will use bean validation. * diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache index 92e2676621..988cc3372e 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache @@ -39,6 +39,7 @@ import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.security.SecurityRequirement; {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache index 37a169fb93..a88ea8317f 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache @@ -83,7 +83,7 @@ {{closebrace}}{{/responses.1}}{{#vendorExtensions.hasNotBodyParam}}, parameters = {{#vendorExtensions.originalParams.1}}{{openbrace}} {{/vendorExtensions.originalParams.1}}{{#vendorExtensions.originalParams}}{{#vendorExtensions.originalParams.1}} - {{/vendorExtensions.originalParams.1}}{{^isBodyParam}}@Parameter(name = "{{paramName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}){{^-last}},{{/-last}}{{/isBodyParam}}{{#vendorExtensions.hasMultipleParams}} + {{/vendorExtensions.originalParams.1}}{{^isBodyParam}}@Parameter(name = "{{paramName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, in = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}}{{/isBodyParam}}{{#vendorExtensions.hasMultipleParams}} {{/vendorExtensions.hasMultipleParams}}{{/vendorExtensions.originalParams}}{{#vendorExtensions.originalParams.1}} {{closebrace}}{{/vendorExtensions.originalParams.1}}{{/vendorExtensions.hasNotBodyParam}}{{#hasAuthMethods}}, security = {{#authMethods.1}}{{openbrace}} @@ -93,23 +93,3 @@ {{closebrace}}{{/authMethods.1}}{{/hasAuthMethods}} ) {{/generateSwagger2Annotations}} - {{#implicitHeadersParams.0}} - {{#generateSwagger2Annotations}} - {{#implicitHeadersParams.1}} - @Parameters({{openbrace}} - {{/implicitHeadersParams.1}} - {{#implicitHeadersParams}} - @Parameter(name = "{{paramName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}){{^-last}},{{/-last}} - {{/implicitHeadersParams}} - {{#implicitHeadersParams.1}} - {{closebrace}}) - {{/implicitHeadersParams.1}} - {{/generateSwagger2Annotations}} - {{#generateSwagger1Annotations}} - @ApiImplicitParams({{openbrace}} - {{#implicitHeadersParams}} - @ApiImplicitParam(name = "{{{baseName}}}", value = "{{{description}}}", {{#required}}required = true,{{/required}} dataType = "{{{dataType}}}", paramType = "header"){{^-last}},{{/-last}} - {{/implicitHeadersParams}} - {{closebrace}}) - {{/generateSwagger1Annotations}} - {{/implicitHeadersParams.0}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache index 55d3f358d1..0e28635342 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache @@ -39,6 +39,7 @@ import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.security.SecurityRequirement; {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache index 81368787f0..830e3a7e2e 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache @@ -31,6 +31,7 @@ import io.swagger.v3.oas.annotations.Parameters import io.swagger.v3.oas.annotations.media.Content import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.responses.ApiResponse +import io.swagger.v3.oas.annotations.enums.ParameterIn import io.swagger.v3.oas.annotations.tags.Tag import io.swagger.v3.oas.annotations.security.SecurityRequirement {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache index 15ee45cf7c..5501b42556 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache @@ -53,7 +53,7 @@ parameters = [ {{#vendorExtensions.originalParams}} {{^isBodyParam}} - Parameter(name = "{{vendorExtensions.realName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}){{^-last}},{{/-last}} + Parameter(name = "{{vendorExtensions.realName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, `in` = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}} {{/isBodyParam}} {{/vendorExtensions.originalParams}} ]{{/vendorExtensions.hasNotBodyParam}}{{#hasAuthMethods}}, @@ -64,10 +64,3 @@ ]{{/hasAuthMethods}} ) {{/generateSwagger2Annotations}} - {{#implicitHeadersParams.0}} - {{#generateSwagger2Annotations}} - {{#implicitHeadersParams}} - @Parameter(name = "{{vendorExtensions.realName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}) - {{/implicitHeadersParams}} - {{/generateSwagger2Annotations}} - {{/implicitHeadersParams.0}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache index 07203a0578..ba9ee798d8 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache @@ -28,6 +28,7 @@ import io.swagger.v3.oas.annotations.Parameters import io.swagger.v3.oas.annotations.media.Content import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.responses.ApiResponse +import io.swagger.v3.oas.annotations.enums.ParameterIn import io.swagger.v3.oas.annotations.tags.Tag import io.swagger.v3.oas.annotations.security.SecurityRequirement {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java index 308124e068..de1d4fb485 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java @@ -587,4 +587,30 @@ void testLombok() { "@AllArgsConstructor", "@Data"); } + + @Test + void testImplicitHeaders() { + + var codegen = new JavaMicronautClientCodegen(); + codegen.setImplicitHeaders(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/params-with-default-value.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileNotContains(path + "api/DefaultApi.java", "@Header(\"X-Favor-Token\") @Nullable String xFavorToken", + "@Header(name = \"Content-Type\", defaultValue = \"application/json\") @Nullable String contentType" + ); + } + + @Test + void testImplicitHeadersRegex() { + + var codegen = new JavaMicronautClientCodegen(); + codegen.setImplicitHeadersRegex(".*"); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/params-with-default-value.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileNotContains(path + "api/DefaultApi.java", "@Header(\"X-Favor-Token\") @Nullable String xFavorToken", + "@Header(name = \"Content-Type\", defaultValue = \"application/json\") @Nullable String contentType" + ); + } } diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java index b68b5bb3e5..1fd8754318 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java @@ -624,4 +624,30 @@ void testSingleProduceContentType() { assertFileContains(path + "api/FilesApi.kt", "@Produces(\"application/octet-stream\")"); } + + @Test + void testImplicitHeaders() { + + var codegen = new KotlinMicronautClientCodegen(); + codegen.setImplicitHeaders(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/params-with-default-value.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileNotContains(path + "api/DefaultApi.kt", "@Header(\"X-Favor-Token\") @Nullable xFavorToken: String? = null,", + "@Header(name = \"Content-Type\", defaultValue = \"application/json\") @Nullable contentType: String? = \"application/json\"" + ); + } + + @Test + void testImplicitHeadersRegex() { + + var codegen = new KotlinMicronautClientCodegen(); + codegen.setImplicitHeadersRegex(".*"); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/params-with-default-value.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileNotContains(path + "api/DefaultApi.kt", "@Header(\"X-Favor-Token\") @Nullable xFavorToken: String? = null,", + "@Header(name = \"Content-Type\", defaultValue = \"application/json\") @Nullable contentType: String? = \"application/json\"" + ); + } }