Skip to content

Commit

Permalink
Fix generator client endpoint with single produces content type
Browse files Browse the repository at this point in the history
Fixed #1678
  • Loading branch information
altro3 committed Aug 14, 2024
1 parent 018fd5c commit ed4d5a8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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\")");
}
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ed4d5a8

Please sign in to comment.