OpenAPITools / OpenAPITools/openapi-generator

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

Open
#17,101 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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 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
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked sample project, its build.gradle.kts, and the swagger-no-generation.json and swagger-stackoverflow.json inputs. Run ./gradlew clean openApiGenerate for each case and compare the generated output and failure. Done means the first input generates its Java class and the self-referencing input completes without StackOverflowError.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.