swagger-api / swagger-api/swagger-codegen
[typscript][jquery] optional array query parameter is not generated correctly
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Defining an optional query parameter (configurationRevision in the shown yml) as array, the serialization seems to be wrong, and result in error:
"Cannot read property 'push' of undefined"
Serialized code (api/MeasurementsApi.ts):
if (configurationRevision) {
configurationRevision.forEach((element: any) => {
queryParameters['configurationRevision[]'].push(element);
});
}
Swagger-codegen version
I am using https://editor.swagger.io/ - Generate Client - typescript-jquery
Swagger declaration file content or url
swagger: '2.0'
info:
description: Interface of REST Service for the Webclient
version: 2.0.0
title: REST Interface for Webclient
basePath: /api
tags:
- name: configurations
paths:
/measurements:
get:
tags:
- measurements
description: Returns all measurements
parameters:
- name: configurationId
in: query
description: Configuration ID
required: false
type: integer
format: int32
- name: configurationRevision[]
in: query
description: Configuration Revision
required: false
type: array
items:
type: integer
format: int32
collectionFormat: multi
operationId: measurements
produces:
- application/json
responses:
'200':
description: All available measurements
schema:
type: array
items:
type: integer
'901':
description: No valid licence
Command line used for generation
Steps to reproduce
Use above yml and generate typescript-jquery client code with: https://editor.swagger.io/
Related issues/PRs
Suggest a fix/enhancement
Create an emtpy array, to make push available.
if (configurationRevision) {
queryParameters['configurationRevision[]'] = new Array<number>();
configurationRevision.forEach((element: any) => {
queryParameters['configurationRevision[]'].push(element);
});
}
[edit] insert collectionFormat: multi, change configurationRevision to configurationRevision[]
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
Reproduce the issue from the supplied Swagger YAML using the typescript-jquery generator and inspect the template responsible for api/MeasurementsApi.ts. Confirm the generated client safely handles the optional array query parameter, then regenerate and verify that the configurationRevision request no longer fails when values are supplied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jquery, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100