swagger-api / swagger-api/swagger-codegen
[TypeScript] Invalid typescript code is generated for csv int list
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have a parameter declared in swagger.json as comma separated integers. In the generated api.ts no parameter is passed into COLLECTION_FORMATS which results in invalid typescript code.
Swagger-codegen version
version is swagger-codegen-cli.3.0.27
Swagger declaration file content or url
{
"x-generator": "NSwag v13.11.1.0 (NJsonSchema v10.4.3.0 (Newtonsoft.Json v13.0.0.0))",
"openapi": "3.0.0",
"info": {
},
"paths": {
"/test": {
"get": {
"tags": [
"Xs"
],
"operationId": "Xs",
"parameters": [
{
"name": "ids",
"in": "query",
"style": "simple",
"collectionFormat": "csv",
"description": "The comma separated list of configuration ids.",
"schema": {
"type": "array",
"nullable": false,
"items": {
"type": "integer",
"format": "int32"
}
},
"x-position": 1
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
},
"security": [
{
"JWT": []
}
]
}
},
"securitySchemes": {
"JWT": {
"type": "apiKey",
"description": "Copy 'Bearer ' + valid JWT token into field",
"name": "Authorization",
"in": "header"
}
}
}
}
Command line used for generation
java -jar .\build\swagger-codegen-cli.3.0.27.jar generate
-i .\build\swagger.json
-l typescript-fetch
-o .\build\clients\generated\typescript
"-DnpmVersion=$($version)" `
-c .\build\clients\typescript-client-config.json
Steps to reproduce
Run the command line
Related issues/PRs
searched but haven't found
Suggest a fix/enhancement
Line 100 of the generated api.ts is wrong
localVarQueryParameter['ids'] = ids.join(COLLECTION_FORMATS[""]);
It should be
localVarQueryParameter['ids'] = ids.join(COLLECTION_FORMATS["csv"]);
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
Run the provided swagger-codegen command with the example swagger.json and inspect generated api.ts around line 100. Trace that output to the typescript-fetch Mustache template and verify the collection format is retained for the ids parameter. Done when the generated code uses COLLECTION_FORMATS["csv"] and remains valid TypeScript.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100