Skip to content

Commit

Permalink
[BUG] Multi-Part content type in response ignores properties of compo…
Browse files Browse the repository at this point in the history
…sed schema (allOf/oneOf) (#6073)
  • Loading branch information
vvalchev authored Aug 1, 2020
1 parent 62e5950 commit 5b22d08
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5653,8 +5653,11 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
Map<String, Schema> properties = schema.getProperties();
List<String> allRequired = new ArrayList<String>();
Map<String, Schema> properties = new LinkedHashMap<>();
addProperties(properties, allRequired, schema);

if (!properties.isEmpty()) {
for (Map.Entry<String, Schema> entry : properties.entrySet()) {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
// key => property name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2162,4 +2162,73 @@ public void testUseOneOfInterfaces() {
Schema items = ((ArraySchema) openAPI.getComponents().getSchemas().get("CustomOneOfArraySchema")).getItems();
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"));
}
}

0 comments on commit 5b22d08

Please sign in to comment.