Skip to content

[typscript][jquery] optional array query parameter is not generated correctly #10280

Description

@Nalaxon

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[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions