Skip to content

[BUG][JAVA][native] Generated model java files contain import for non-existent invoker JSON class (supporting files were not generated) #8027

@dowy

Description

@dowy

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

The generated Java model files contain an import for ...invoker.JSON but this class does not exist because option generateSupportingFiles=false
(Also, there is no reference to the JSON class in the body of the code so the import can safely be removed.)

openapi-generator version

5.0.0-SNAPSHOT git revision 4dc8d2a
This is a regression. This error does not occur in 4.3.1

OpenAPI declaration file content or url
openapi: 3.0.1

info:
  title: Bug Report
  description: Demonstration of bug in openapi-generator 5.0.0-SNAPSHOT git revision 4dc8d2a3514af15ac13624d4dc8e2e179749e5bd
  version: 1

paths: {}

components:
  schemas:
    Pojo:
      type: object
      additionalProperties: false
      properties:
        Dummy:
          type: string
Generation Details

Config file:

generatorName: java
outputDir: bug
library: native
inputSpec: bug.yaml
templateDir: modules/openapi-generator/src/main/resources/Java

apiPackage: bug.api
modelPackage: bug.model
invokerPackage: bug.invoker
packageName: bug.openapi

generateModelDocs: false
generateModelTests: false
generateApiTests: false
generateAliasAsModel: false
generateSupportingFiles: false
generateModelDocumentation: false
generateApiDocumentation: false
generateModels: true
generateApis: false

additionalProperties:
  java8: true
  dateLibrary: java8
  serializationLibrary: jackson
Steps to reproduce

Store the OpenApi declaration file pasted above into bug.yaml
Store the generator config file pasted above into bug-config.yaml
Run openapi-generator:

$ mkdir -p bug
$ bin/generate-samples.sh bug-config.yaml
Related issues/PRs

Somewhat similar but different: #8016

Suggest a fix

The following line needs some decision logic so that it is only included if the supporting files have been generated:

modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache:49:import {{invokerPackage}}.JSON;

There are about 7 repetitions of this in other mustache files.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions