[BUG] [JAVA] [Gradle] '"additionalProperties": false' leads to failing code generation
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have recently updated the openapi-generator gradle plugin from 6.6.0 to 7.1.0. Since then I have two problems, seemingly related to the use of "additionalProperties" in my swagger.json file.
- Case 1: If I have a definition with
"additionalProperties": false, no java class will be generated for this defnition. - Case 2: If I have a definition with
"additionalProperties": falseand a property that references the same definition, it will cause aStackOverflowError.
openapi-generator version
openapi-generator gradle plugin 7.1.0 It worked fine with version 6.6.0
OpenAPI declaration file content or url
- Case 1: https://raw.githubusercontent.com/sandra-thieme/openapi-generate-example/main/src/main/resources/swagger-no-generation.json
- Case2: https://github.com/sandra-thieme/openapi-generate-example/blob/main/src/main/resources/swagger-stackoverflow.json
Generation Details
I have created a minimal sample project to illustrate the issue: https://github.com/sandra-thieme/openapi-generate-example/tree/main. There are three swagger.json files in there: one that works, one that shows that nothing is generated (case 1), one that shows the stackoverflow error (case 2).
Steps to reproduce
In the above sample project:
- Call
./gradlew clean openApiGenerate - Build succeeds but no class will have been generated in
build/generated - Change
swagger-no-generation.jsonin build.gradle.kts toswagger-stackoverflow.json - Call
./gradlew clean openApiGenerate - Build fails with
StackOverflowError
Related issues/PRs
Suggest a fix
I am looking for an issue to contribute. Can I take a look at this (I've already tested that the issue still exists on master)?
I took the liberty of taking a quick look. Case no. 1 is caused by the model being skipped in: https://github.com/OpenAPITools/openapi-generator/blob/a577db895ca42d2f819c679eb91950eae3e9a8c8/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L574
That's because Schema of the model converted by SwaggerConverter (from swagger-parser-v2-converter) is of type MapSchema but
https://github.com/OpenAPITools/openapi-generator/blob/a577db895ca42d2f819c679eb91950eae3e9a8c8/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java#L565
checks if additionalProperties is not false.
+1 We are facing the same issue right now. Passing a map does not work any more.
+1
We are facing t a similar issue when using "additionalProperties": true, passing a map does not work any more.
Similar issue: when using "additionalProperties": true, passing a map does not work any more.