Handle custom content type example (#12460)

This commit is contained in:
Oleh Kurpiak
2022-07-06 20:29:55 +03:00
committed by GitHub
parent 92a5544ba0
commit cfebd14c2b
3 changed files with 86 additions and 0 deletions

View File

@@ -170,6 +170,9 @@ public class ExampleGenerator {
kv.put(EXAMPLE, example);
output.add(kv);
}
} else {
kv.put(EXAMPLE, null);
output.add(kv);
}
}
} else {

View File

@@ -1404,6 +1404,30 @@ public class SpringCodegenTest {
.bodyContainsLines("super.putSomeMapItem(key, someMapItem);");
}
@Test
public void shouldHandleCustomResponseType_issue11731() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_11731.yaml", null, new ParseOptions()).getOpenAPI();
SpringCodegen codegen = new SpringCodegen();
codegen.setLibrary(SPRING_BOOT);
codegen.setOutputDir(output.getAbsolutePath());
ClientOptInput input = new ClientOptInput()
.openAPI(openAPI)
.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));
JavaFileAssert.assertThat(files.get("CustomersApi.java"))
.assertMethod("getAllUsingGET1")
.bodyContainsLines("if (mediaType.isCompatibleWith(MediaType.valueOf(\"application/hal+json\"))) {");
}
@Test
public void shouldHandleContentTypeWithSecondWildcardSubtype_issue12457() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();

View File

@@ -0,0 +1,59 @@
openapi: 3.0.2
info:
title: Petstore - OpenAPI 3.0
description: Specification to reproduce issues with mediatypes other than common application/json
termsOfService: http://inss.ch
contact:
email: openapi@inss.ch
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: http://localhost:8080/api/v3
paths:
/customers:
get:
tags:
- customer-controller
summary: getAll
operationId: getAllUsingGET_1
responses:
200:
description: OK
content:
application/hal+json:
schema:
$ref: '#/components/schemas/ResponseObject'
401:
description: Unauthorized
content: {}
403:
description: Forbidden
content: {}
404:
description: Not Found
content: {}
components:
schemas:
ResponseObject:
required:
- name
- photoUrls
type: object
properties:
id:
type: integer
format: int64
example: 10
description: 'Id'
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
example: available