Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle custom content type example #12460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public List<Map<String, String>> generate(Map<String, Object> examples, List<Str
kv.put(EXAMPLE, example);
output.add(kv);
}
} else {
kv.put(EXAMPLE, null);
output.add(kv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. We've merged the following PRs to prevent NPE:

#12836
#12841

}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,30 @@ public void testPutItemsMethodContainsKeyInSuperClassMethodCall_issue12494() thr
.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();
Expand Down
59 changes: 59 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_11731.yaml
Original file line number Diff line number Diff line change
@@ -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