OpenAPITools / OpenAPITools/openapi-generator
[BUG] Duplicate AdditionalProperties method is getting created
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I'm generating SDKs for two services, Service 1 and Service 2, this is being used in Service 3, using the OpenAPI Generator. Both services share a common DTO class, which is defined in Service 1, and I am using this DTO in my request and response objects of Service 2. When generating the SDK for Service 2, the OpenAPI Generator is recreating this class, resulting in a conflict where additionalProperties is being defined twice. How can I prevent this class from being duplicated in Service 2's SDK and instead reuse the class from Service 1's SDK?
Since in my config I have made the "disallowAdditionalPropertiesIfNotPresent": false
openapi-generator version
7.7.0
OpenAPI declaration file content or url
Generation Details
Service 1 has service 2 sdk implementation added in the build.gradle, Service 1 is using the class present in the service 2 sdk as a Response Object of an API call. Now while generating the SDK of service 1 the additionalProperties is getting duplicate.
openApi-config-service2.json file:
{
"generatorName": "java",
"inputSpec": "http://localhost:8091/v3/api-docs",
"outputDir": "../service2-sdk",
"apiPackage": "com.c.fintech.service2.sdk",
"modelPackage": "com.c.fintech.service2.sdk",
"artifactId": "service2-sdk",
"disallowAdditionalPropertiesIfNotPresent": false,
"dateLibrary": "java8",
"typeMappings": {
"date-time": "String",
"OffsetDateTime": "String",
"LocalDate": "String"
},
"importMappings": {
"java.time.OffsetDateTime": "java.lang.String"
}
}
generator script:
#!/bin/sh
java -jar ~/bin/openapi-generator-cli.jar generate --config openapi-config-service2.json --artifact-version "$1"
cd ../service-2-sdk
- I am using OpenApi Generator 7.7.0
- My Project is in Java - 17 and Spring Boot
Steps to reproduce
- Create two Demo Services 1 and 2, then add some model classes in Service 1.
- Create an SDK of Service 1, and use the response body of service 1 in Service 2 API Request or Response.
- Don't forget to make the disallowedAdditionalProperties as false.
- Now, create the SDK of Service 2, after creation you can observe that same DTO is created again and in that class additional Properties function is duplicated.
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with openApi-config-service2.json and the generator script, then reproduce the Java SDK generation described in the steps using the Service 1 and Service 2 setup. Inspect the generated DTO and verify whether the shared class is recreated and whether additionalProperties is defined twice. Done means the duplicate DTO or duplicate method no longer appears when generating Service 2's SDK.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100