mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-06 01:26:12 +00:00
Compare commits
2 Commits
ts-angular
...
WannabeSof
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b798dc0cb4 | ||
|
|
f371a91d15 |
@@ -7805,8 +7805,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateRequestBodyForString(CodegenParameter codegenParameter, Schema schema, Set<String> imports, String bodyParameterName) {
|
||||
updateRequestBodyForPrimitiveType(codegenParameter, schema, bodyParameterName, imports);
|
||||
protected void updateRequestBodyForString(CodegenParameter codegenParameter, Schema schema, String name, Set<String> imports, String bodyParameterName) {
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
addBodyModelSchema(codegenParameter, name, schema, imports, bodyParameterName, false);
|
||||
} else {
|
||||
updateRequestBodyForPrimitiveType(codegenParameter, schema, bodyParameterName, imports);
|
||||
}
|
||||
|
||||
if (ModelUtils.isByteArraySchema(schema)) {
|
||||
codegenParameter.setIsString(false);
|
||||
codegenParameter.isByteArray = true;
|
||||
@@ -8007,7 +8012,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// swagger v2 only, type file
|
||||
codegenParameter.isFile = true;
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
updateRequestBodyForString(codegenParameter, schema, imports, bodyParameterName);
|
||||
updateRequestBodyForString(codegenParameter, schema, name, imports, bodyParameterName);
|
||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||
updateRequestBodyForPrimitiveType(codegenParameter, schema, bodyParameterName, imports);
|
||||
codegenParameter.isNumeric = Boolean.TRUE;
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.openapitools.codegen.utils.SemVer;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Ignore;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -5044,4 +5045,40 @@ public class DefaultCodegenTest {
|
||||
if (props == null) return null;
|
||||
return props.stream().map(v -> v.name).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestBodyWithStringEnumSchema() {
|
||||
// Given
|
||||
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_21407.yaml");
|
||||
DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
String path = "/v1/resource-class/send-using-schema";
|
||||
|
||||
// When
|
||||
CodegenOperation codegenOperation = codegen.fromOperation(path, "POST", openAPI.getPaths().get(path).getPost(), null);
|
||||
|
||||
// Then
|
||||
assertThat(codegenOperation.bodyParam).satisfies(bodyParam -> {
|
||||
assertThat(bodyParam).isNotNull();
|
||||
assertThat(bodyParam.getDataType()).isEqualTo("Letter");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestBodyWithStringSchema() {
|
||||
// Given
|
||||
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_21407.yaml");
|
||||
DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
String path = "/v1/resource-class/send-using-string";
|
||||
|
||||
// When
|
||||
CodegenOperation codegenOperation = codegen.fromOperation(path, "POST", openAPI.getPaths().get(path).getPost(), null);
|
||||
|
||||
// Then
|
||||
assertThat(codegenOperation.bodyParam).satisfies(bodyParam -> {
|
||||
assertThat(bodyParam).isNotNull();
|
||||
assertThat(bodyParam.getDataType()).isEqualTo("String");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: sample spec
|
||||
description: "Sample spec"
|
||||
version: 0.0.1
|
||||
tags:
|
||||
- name: ResourceClass
|
||||
paths:
|
||||
/v1/resource-class/send-using-schema:
|
||||
post:
|
||||
tags:
|
||||
- ResourceClass
|
||||
description: Add @Operation annotation to provide a description
|
||||
operationId: send-using-schema
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Letter"
|
||||
responses:
|
||||
"200":
|
||||
description: OK - the request has succeeded.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Letter"
|
||||
/v1/resource-class/send-using-string:
|
||||
post:
|
||||
tags:
|
||||
- ResourceClass
|
||||
description: Add @Operation annotation to provide a description
|
||||
operationId: send-using-string
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"204":
|
||||
description: "No Content - the request has been successfully processed,\
|
||||
\ but there is no additional content."
|
||||
components:
|
||||
schemas:
|
||||
Letter:
|
||||
type: string
|
||||
enum:
|
||||
- A
|
||||
- B
|
||||
Reference in New Issue
Block a user