forked from loafle/openapi-generator-original
handle wildcard sub content-type (#12469)
This commit is contained in:
@@ -6194,7 +6194,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// skip as it implies `consumes` in OAS2 is not defined
|
||||
continue;
|
||||
} else {
|
||||
mediaType.put("mediaType", escapeText(escapeQuotationMark(key)));
|
||||
mediaType.put("mediaType", escapeQuotationMark(key));
|
||||
}
|
||||
mediaTypeList.add(mediaType);
|
||||
}
|
||||
@@ -6260,7 +6260,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
for (String key : produces) {
|
||||
// escape quotation to avoid code injection, "*/*" is a special case, do nothing
|
||||
String encodedKey = "*/*".equals(key) ? key : escapeText(escapeQuotationMark(key));
|
||||
String encodedKey = "*/*".equals(key) ? key : escapeQuotationMark(key);
|
||||
//Only unique media types should be added to "produces"
|
||||
if (!existingMediaTypes.contains(encodedKey)) {
|
||||
Map<String, String> mediaType = new HashMap<>();
|
||||
|
||||
@@ -1403,4 +1403,33 @@ public class SpringCodegenTest {
|
||||
.assertMethod("putSomeMapItem")
|
||||
.bodyContainsLines("super.putSomeMapItem(key, someMapItem);");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleContentTypeWithSecondWildcardSubtype_issue12457() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
OpenAPI openAPI = new OpenAPIParser()
|
||||
.readLocation("src/test/resources/bugs/issue_12457.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
SpringCodegen codegen = new SpringCodegen();
|
||||
codegen.setLibrary(SPRING_BOOT);
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true");
|
||||
|
||||
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("UsersApi.java"))
|
||||
.assertMethod("wildcardSubTypeForContentType")
|
||||
.assertMethodAnnotations()
|
||||
.containsWithNameAndAttributes("RequestMapping", ImmutableMap.of(
|
||||
"produces", "{ \"application/json\", \"application/*\" }",
|
||||
"consumes", "{ \"application/octet-stream\", \"application/*\" }"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: OpenAPI Petstore
|
||||
description: "sample to vet integer handling"
|
||||
version: 1.0.0
|
||||
tags: []
|
||||
paths:
|
||||
/request:
|
||||
get:
|
||||
operationId: wildcardSubTypeForContentType
|
||||
tags:
|
||||
- users
|
||||
requestBody:
|
||||
description: The attachment
|
||||
content:
|
||||
application/octet-stream:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
application/*:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
responses:
|
||||
'200':
|
||||
description: response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
application/*:
|
||||
schema:
|
||||
type: string
|
||||
Reference in New Issue
Block a user