swagger-api / swagger-api/swagger-codegen
[GENERAL] parameter name seems to be parsed as case insensitive
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
In a paramater, if the case-insensitive form of its name is the same as the schema name (in the example, the parameter name is archiveType, the schema name is ArchiveType), the generator will stuck and give an error after a while:
Exception in thread "Thread-1" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fixUpParentAndInterfaces(DefaultCodegenConfig.java:308)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.postProcessAllCodegenModels(DefaultCodegenConfig.java:279)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.postProcessAllModels(DefaultCodegenConfig.java:271)
at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:405)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:779)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
at java.lang.Thread.run(Unknown Source)
The OpenAPI Specs defined that name should be case-sensitive (https://swagger.io/specification/#parameter-object).
The example specs file works in swagger ui, but not in the generator. I also tested it with swagger validator and it can pass the test.
So I guess the generator parse it as case-insensitive and it's a bug?
Swagger-codegen version
3.0.30 (the eariler versions also have this issue)
Swagger declaration file content or url
https://gist.github.com/tc-imba/76dc7e627a56ac84b5c1c14b08d90f1e
openapi.json
{
"openapi": "3.0.2",
"info": {
"title": "test",
"description": "test",
"version": "0.1.0"
},
"paths": {
"/": {
"get": {
"summary": "test",
"operationId": "test",
"parameters": [
{
"required": false,
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/ArchiveType"
}
],
"default": "zip"
},
"name": "archiveType",
"in": "query"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ArchiveType": {
"title": "ArchiveType",
"enum": [
"zip",
"tar",
"unknown"
],
"type": "string",
"description": "An enumeration."
}
}
}
}
Command line used for generation
java -jar swagger-codegen-cli-3.0.30.jar generate -i openapi.json -o build/client/java -l python
I tried some other languages but the same error occurs. So I think it's a general problem on the parser.
Steps to reproduce
Run the command with openapi.json can reproduce this.
Related issues/PRs
Suggest a fix/enhancement
I'll work on a fix if possible, but I'm not very familiar with Java so it may take some time.
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 by reproducing the failure with the supplied openapi.json and generation command, then inspect DefaultCodegenConfig.fixUpParentAndInterfaces and the surrounding model post-processing calls shown in the stack trace. Done means generation terminates without the OutOfMemoryError while treating the parameter and schema names according to the OpenAPI case-sensitive rule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100