Skip to content

[BUG] [typescript-jquery] Code-generator optional array query parameter results in push on undefined array #6692

@Nalaxon

Description

@Nalaxon

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Defining an optional query parameter (configurationRevision in the shown yml) as array, the serialization seems to be wrong, and result in runtime error:
"Cannot read property 'push' of undefined"

Serialized code (api/MeasurementsApi.ts):

if (configurationRevision) {
            configurationRevision.forEach((element: any) => {
                queryParameters['configurationRevision[]'].push(element);
            });
        }

It does not work with https://editor.swagger.io/ either, see Issue: swagger-api/swagger-codegen#10280

openapi-generator version

openapi-generator version: 4.3.1
openjdk build: 10.0.2+13
Windows 10

OpenAPI 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
Command line used for generation

openapi-generator generate -i test.yaml -g typescript-jquery -o out\ts-test\

Steps to reproduce
Suggest a fix

Create an emtpy array, to make push available.

if (configurationRevision) {
  queryParameters['configurationRevision[]'] = new Array<number>();
  configurationRevision.forEach((element: any) => {
    queryParameters['configurationRevision[]'].push(element);
  });
 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions