forked from loafle/openapi-generator-original
[BUG] Multi-Part content type in response ignores properties of composed schema (allOf/oneOf) (#6073)
This commit is contained in:
parent
62e5950799
commit
5b22d08d41
@ -5653,8 +5653,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
|
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
|
||||||
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
|
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
|
||||||
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
||||||
if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
|
List<String> allRequired = new ArrayList<String>();
|
||||||
Map<String, Schema> properties = schema.getProperties();
|
Map<String, Schema> properties = new LinkedHashMap<>();
|
||||||
|
addProperties(properties, allRequired, schema);
|
||||||
|
|
||||||
|
if (!properties.isEmpty()) {
|
||||||
for (Map.Entry<String, Schema> entry : properties.entrySet()) {
|
for (Map.Entry<String, Schema> entry : properties.entrySet()) {
|
||||||
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
||||||
// key => property name
|
// key => property name
|
||||||
|
@ -2162,4 +2162,73 @@ public class DefaultCodegenTest {
|
|||||||
Schema items = ((ArraySchema) openAPI.getComponents().getSchemas().get("CustomOneOfArraySchema")).getItems();
|
Schema items = ((ArraySchema) openAPI.getComponents().getSchemas().get("CustomOneOfArraySchema")).getItems();
|
||||||
Assert.assertEquals(items.getExtensions().get("x-one-of-name"), "CustomOneOfArraySchemaOneOf");
|
Assert.assertEquals(items.getExtensions().get("x-one-of-name"), "CustomOneOfArraySchemaOneOf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormComposedSchema() {
|
||||||
|
OpenAPI openAPI = TestUtils.parseContent("openapi: 3.0.1\n" +
|
||||||
|
"info:\n" +
|
||||||
|
" version: '1.0.0'\n" +
|
||||||
|
" title: the title\n" +
|
||||||
|
"\n" +
|
||||||
|
"paths:\n" +
|
||||||
|
" '/users/me':\n" +
|
||||||
|
" post:\n" +
|
||||||
|
" description: Change user password.\n" +
|
||||||
|
" operationId: changeCurrentUserPassword\n" +
|
||||||
|
" requestBody:\n" +
|
||||||
|
" required: true\n" +
|
||||||
|
" content:\n" +
|
||||||
|
" multipart/form-data:\n" +
|
||||||
|
" schema:\n" +
|
||||||
|
" $ref: '#/components/schemas/ChangePasswordRequest'\n" +
|
||||||
|
" responses:\n" +
|
||||||
|
" '200':\n" +
|
||||||
|
" description: Successful operation\n" +
|
||||||
|
" content: {}\n" +
|
||||||
|
"\n" +
|
||||||
|
"components:\n" +
|
||||||
|
" schemas:\n" +
|
||||||
|
" CommonPasswordRequest:\n" +
|
||||||
|
" type: object\n" +
|
||||||
|
" required: [ password, passwordConfirmation ]\n" +
|
||||||
|
" properties:\n" +
|
||||||
|
" password:\n" +
|
||||||
|
" type: string\n" +
|
||||||
|
" format: password\n" +
|
||||||
|
" passwordConfirmation:\n" +
|
||||||
|
" type: string\n" +
|
||||||
|
" format: password\n" +
|
||||||
|
"\n" +
|
||||||
|
" ChangePasswordRequest:\n" +
|
||||||
|
" type: object\n" +
|
||||||
|
" allOf:\n" +
|
||||||
|
" - $ref: '#/components/schemas/CommonPasswordRequest'\n" +
|
||||||
|
" - type: object\n" +
|
||||||
|
" required: [ oldPassword ]\n" +
|
||||||
|
" properties:\n" +
|
||||||
|
" oldPassword:\n" +
|
||||||
|
" type: string\n" +
|
||||||
|
" format: password\n");
|
||||||
|
|
||||||
|
final DefaultCodegen cg = new DefaultCodegen();
|
||||||
|
cg.setOpenAPI(openAPI);
|
||||||
|
cg.setUseOneOfInterfaces(true);
|
||||||
|
cg.preprocessOpenAPI(openAPI);
|
||||||
|
|
||||||
|
final PathItem path = openAPI.getPaths().get("/users/me");
|
||||||
|
final CodegenOperation operation = cg.fromOperation(
|
||||||
|
"/users/me",
|
||||||
|
"post",
|
||||||
|
path.getPost(),
|
||||||
|
path.getServers());
|
||||||
|
assertEquals(operation.formParams.size(), 3,
|
||||||
|
"The list of parameters should include inherited type");
|
||||||
|
|
||||||
|
final List<String> names = operation.formParams.stream()
|
||||||
|
.map(param -> param.paramName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
assertTrue(names.contains("password"));
|
||||||
|
assertTrue(names.contains("passwordConfirmation"));
|
||||||
|
assertTrue(names.contains("oldPassword"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user