openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [JAVA] [Gradle] '"additionalProperties": false' leads to failing code generation

Open sandra-thieme opened this issue 3 years ago • 5 comments

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": false and a property that references the same definition, it will cause a StackOverflowError.
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.json in build.gradle.kts to swagger-stackoverflow.json
  • Call ./gradlew clean openApiGenerate
  • Build fails with StackOverflowError
Related issues/PRs
Suggest a fix

sandra-thieme avatar Nov 16 '23 13:11 sandra-thieme

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)?

redzi avatar Nov 18 '23 15:11 redzi

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.

redzi avatar Nov 18 '23 19:11 redzi

+1 We are facing the same issue right now. Passing a map does not work any more.

SimonScholz avatar Nov 20 '23 10:11 SimonScholz

+1 We are facing t a similar issue when using "additionalProperties": true, passing a map does not work any more.

cyberflohr avatar Nov 21 '23 08:11 cyberflohr

Similar issue: when using "additionalProperties": true, passing a map does not work any more.

bauste avatar Nov 21 '23 16:11 bauste