swagger-api / swagger-api/swagger-codegen
[JAVA] Bug generating bad enum classes with extra double quotes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Gradle generateAPI task and the custom templates under src/main/resources/templates. Reproduce the supplied Test definition with swagger-codegen 2.2.x and compare it with 2.1.6. Done when the generated Java enum contains single-quoted values and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100