OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][GRADLE] Generator produces uncompilable code unless run incrementally

Open
#15,909 1 comment 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
  1. When generating several classes used in 'MessageToSend' are missing causing the code to not compile afterwards
    When placing the properties in comments and generating the code in multiple steps, taking out 1 comment each time, causes the code to be compilable.
  2. After the code is generated and compilable, there is 1 missing entry in the creation of the GsonBuilder in JSON.java
    gsonBuilder.registerTypeAdapterFactory(new PaperDeliveryData.CustomTypeAdapterFactory());
openapi-generator version

6.6.0

OpenAPI declaration file content or url

https://gist.github.com/SnakeSVx/d6e1b7c96a7d4dd85aa0d4d705d74afd

Generation Details
openApiGenerate {
    generatorName = "java"
    inputSpec = "$rootDir/api/magda/documentendienst.yaml".toString()
    outputDir = "$buildDir/generated".toString()
    generateApiTests = false
    generateModelTests = false
    skipOverwrite = false
    modelPackage = "be.vaph.sparta.api.client.magda.documenten.controller"
    configOptions = [
        dateLibrary: "java8"
    ]
    globalProperties = [
        verbose: "true"
    ]
}
Steps to reproduce
  1. Generate with supplies yaml
  2. Try to build code: build fails
  3. In model MessageToSend: comment eboxDeliveryData, paperDeliveryData, emailDeliveryData, signingWorkflowData, businessData
  4. Try to build code: build succeeds, but is incomplete
  5. Remove comment from eboxDeliveryData
  6. Try to build code: build succeeds, but is incomplete (eboxDeliveryData is added)
  7. Remove comment from paperDeliveryData
  8. Try to build code: build succeeds, but is incomplete (paperDeliveryData is added)
  9. Remove comment from emailDeliveryData
  10. Try to build code: build succeeds, but is incomplete (emailDeliveryData is added)
  11. Remove comment from emailDeliveryData, businessData
  12. Try to build code: build succeeds, but is incomplete (emailDeliveryData, businessData are added)
  13. In JSON.java, near GsonBuilder gsonBuilder = createGson();, all adapters get registered apart from gsonBuilder.registerTypeAdapterFactory(new PaperDeliveryData.CustomTypeAdapterFactory());
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

Reproduce the generation using the linked OpenAPI declaration and the Gradle openApiGenerate configuration. Inspect the generated MessageToSend model and JSON.java, especially the GsonBuilder registrations, and compare the initial output with the incremental workaround. Done means the generated Java code compiles and includes all required model classes and type-adapter registrations on the first run.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, 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.