-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
To define multipart content you typically do something like that:
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/ChangePasswordRequest'However, if the schema is composed (using allOf) the inherited properties are ignored.
In the provided case, it generates a method without ANY parameters:
void changeCurrentUserPassword();openapi-generator version
4.3.0
OpenAPI declaration file content or url
https://gist.github.com/vvalchev/54a935c0f93c06a184a9eeb1640f96e6#file-api-yml
Command line used for generation
I'm using the following maven pom.xml file to generate the sources:
https://gist.github.com/vvalchev/54a935c0f93c06a184a9eeb1640f96e6#file-pom-xml
Steps to reproduce
- save pom.xml and api.yml
- run
mvn compile - check the generated sources
Related issues/PRs
Suggest a fix
The fix would be to handle correctly if the schema is composed.
I've tried a simple patch:
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
index 82cebbf022..17edf00ddb 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
@@ -5517,8 +5517,11 @@ public class DefaultCodegen implements CodegenConfig {
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 nameAfter the patch, the generated code looks right:
// new code - after the patch has been applied
void changeCurrentUserPassword(@FormParam(value = "password") String password,@FormParam(value = "passwordConfirmation") String passwordConfirmation,@FormParam(value = "oldPassword") String oldPassword);
// old code
void changeCurrentUserPassword();Reactions are currently unavailable