swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

[JAVA] Bug generating bad enum classes with extra double quotes #6484

Open lightningrob opened 7 years ago

lightningrob commented 7 years ago
Description

I am seeing what appears to be a regression with the swagger codegen releases 2.2.x, compared to 2.1.6 which behaves correctly. If I define enums in the yml file, the generated java classes contain enums that don't compile due to duplicated double-quotes around the constant strings.

Example:

      status:
        type: "string"
        enum:
          - "upToDate"
          - "stale"

produces uncompilable java code:

  public enum StatusEnum {
    UPTODATE(""upToDate""),
    STALE(""stale"");
Swagger-codegen version

Works with 2.1.6, fails (duplicate double-quotes) with 2.2.0 - 2.2.3

Swagger declaration file content or url
definitions:
  Test:
    type: "object"
    properties:
      status:
        type: "string"
        enum:
          - "upToDate"
          - "stale"
Command line used for generation

Gradle task:

import io.swagger.codegen.config.CodegenConfigurator
import io.swagger.codegen.DefaultGenerator

task generateApi {
    def swaggerInput = ".../swagger.yml"
    def swaggerOutputDir = file('generated/swagger')
    inputs.file(swaggerInput)
    outputs.dir(swaggerOutputDir)
    doLast {
        def config = new CodegenConfigurator()
        config.setInputSpec(swaggerInput)
        config.setOutputDir(swaggerOutputDir.path)
        config.setLang('java')
        config.setLibrary('jersey2')
        config.setTemplateDir('src/main/resources/templates')
        config.setModelPackage('...model')
        config.setInvokerPackage('...')
        config.setApiPackage('...')
        config.setAdditionalProperties([
                'dateLibrary'   : 'java8'
        ])
        new DefaultGenerator().opts(config.toClientOptInput()).generate()
    }
Steps to reproduce

Run "gradle generateAPI"

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/3593

Suggest a fix/enhancement

Regression from 2.1 to 2.2 release.

wing328 commented 7 years ago

We do have test cases to cover this. Can you please try the latest master to see if the issue still occurs? Snapshot version available at https://github.com/swagger-api/swagger-codegen#compatibility

lightningrob commented 7 years ago

Will try that and report results.

Jeenal715 commented 9 months ago

Hi Im trying to upgarde to 2.4.39 still see same issue can you help

fpadilhaupgrade commented 1 month ago

I am seeing the same error. Is there a fix for this ?