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 8b5365ab9d..92e2676621 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 @@ -58,12 +58,12 @@ public interface {{classname}} { {{#formatNoEmptyLines}} {{>common/operationAnnotations}}{{! }} @{{#lambda.pascalcase}}{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}{{/lambda.pascalcase}}("{{{path}}}") - {{^vendorExtensions.onlyDefaultConsumeOrEmpty}} - {{#produces}}{{#-first}}@Consumes({{#produces.1}}{{openbrace}}{{/produces.1}}{{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}{{#produces.1}}{{closebrace}}{{/produces.1}}){{/-last}}{{/produces}} - {{/vendorExtensions.onlyDefaultConsumeOrEmpty}} {{^vendorExtensions.onlyDefaultProduceOrEmpty}} - {{#consumes}}{{#-first}}@Produces({{#consumes.1}}{{openbrace}}{{/consumes.1}}{{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}{{#consumes.1}}{{closebrace}}{{/consumes.1}}){{/-last}}{{/consumes}} + {{#produces}}{{#-first}}@Consumes({{#produces.1}}{{openbrace}}{{/produces.1}}{{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}{{#produces.1}}{{closebrace}}{{/produces.1}}){{/-last}}{{/produces}} {{/vendorExtensions.onlyDefaultProduceOrEmpty}} + {{^vendorExtensions.onlyDefaultConsumeOrEmpty}} + {{#consumes}}{{#-first}}@Produces({{#consumes.1}}{{openbrace}}{{/consumes.1}}{{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}{{#consumes.1}}{{closebrace}}{{/consumes.1}}){{/-last}}{{/consumes}} + {{/vendorExtensions.onlyDefaultConsumeOrEmpty}} {{!auth methods}} {{#configureAuth}} {{#authMethods}} 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 3c8a0c8d1b..81368787f0 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 @@ -50,12 +50,12 @@ interface {{classname}} { {{#formatNoEmptyLines}} {{>common/operationAnnotations}}{{! }} @{{#lambda.pascalcase}}{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}{{/lambda.pascalcase}}("{{{path}}}") - {{^vendorExtensions.onlyDefaultConsumeOrEmpty}} - {{#produces}}{{#-first}}@Consumes({{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/produces}} - {{/vendorExtensions.onlyDefaultConsumeOrEmpty}} {{^vendorExtensions.onlyDefaultProduceOrEmpty}} - {{#consumes}}{{#-first}}@Produces({{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/consumes}} + {{#produces}}{{#-first}}@Consumes({{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/produces}} {{/vendorExtensions.onlyDefaultProduceOrEmpty}} + {{^vendorExtensions.onlyDefaultConsumeOrEmpty}} + {{#consumes}}{{#-first}}@Produces({{/-first}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/consumes}} + {{/vendorExtensions.onlyDefaultConsumeOrEmpty}} {{!auth methods}} {{#configureAuth}} {{#authMethods}} 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 24c5138a52..1945ac5276 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 @@ -504,4 +504,14 @@ void testOneOfWithoutDiscriminator() { "@JsonTypeInfo" ); } + + @Test + void testSingleProduceContentType() { + + var codegen = new JavaMicronautClientCodegen(); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/client-produces-content-type.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileContains(path + "api/FilesApi.java", "@Produces(\"application/octet-stream\")"); + } } 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 e18671819e..1e096ec02c 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 @@ -550,4 +550,14 @@ void testOneOfWithoutDiscriminator() { "@JsonTypeInfo" ); } + + @Test + void testSingleProduceContentType() { + + var codegen = new KotlinMicronautClientCodegen(); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/client-produces-content-type.yml", CodegenConstants.APIS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileContains(path + "api/FilesApi.kt", "@Produces(\"application/octet-stream\")"); + } } diff --git a/openapi-generator/src/test/resources/3_0/client-produces-content-type.yml b/openapi-generator/src/test/resources/3_0/client-produces-content-type.yml new file mode 100644 index 0000000000..b620ab3cbc --- /dev/null +++ b/openapi-generator/src/test/resources/3_0/client-produces-content-type.yml @@ -0,0 +1,63 @@ +openapi: 3.0.3 +info: + title: File Upload + version: 1.0.0 +tags: + - name: files +paths: + /: + post: + tags: + - files + summary: Upload new file to server + operationId: uploadFile + parameters: + - name: X-file-crc32 + in: header + description: Decimal CRC32B representation of the file + required: true + schema: + type: string + nullable: false + requestBody: + content: + application/octet-stream: + schema: + format: binary + type: string + responses: + "200": + description: File was saved on server. Returns serverfilename (UUID) of + the file. + content: + application/json: + schema: + $ref: '#/components/schemas/File' + "202": + description: File was already available on server. Returns serverfilename + (UUID) of the file. + content: + application/json: + schema: + $ref: '#/components/schemas/File' + "400": + description: "Provided checksum, size or file was not provided or uploaded\ + \ file did not match given values" + "401": + description: User is not authorized to request this resource +components: + schemas: + File: + type: object + properties: + serverFileName: + type: string + checksum: + type: string + mimeType: + type: string + size: + format: int64 + type: integer + shaHash: + type: string