Skip to content

[BUG][typescript-fetch][possibly other languages] Semi-colon delimited path parameters (style: matrix) results in [object Object] #16153

Open
@dschu-lab

Description

@dschu-lab
Description

When an API resource uses semi-colon to separate query parameters, the generated client code will not concatenate the query parameters correctly.

Instead of https://openapi-typescript-bug.free.mockoapp.net/hello;count=10;start=20 the generated client code will produce https://openapi-typescript-bug.free.mockoapp.net/hello[object Object].

This is caused by the apis.mustache template file, which generates the following code to concatenate the request parameters:

path: `/hello{params}`.replace(`{${"params"}}`, encodeURIComponent(String(requestParameters.params))),

But since requestParameters.params is an object, String will convert it to [object Object].

openapi-generator version

6.3.0 / "@openapitools/openapi-generator-cli": "^2.7.0"

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: My API
  version: 1.0.0
  description: My API
servers:
  - url: https://openapi-typescript-bug.free.mockoapp.net
    description: Mock Server

paths:
  /hello{params}:
    get:
      tags:
        - helloWorld
      operationId: getHello
      summary: Hello
      description: Hello
      parameters:
        - in: path
          name: params
          required: true
          schema:
            type: object
            properties:
              start:
                type: integer
                minimum: 1
              count:
                type: integer
                minimum: 1
                maximum: 100
          style: matrix
          explode: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HelloResponse'
components:
  schemas:
    HelloResponse:
      type: object
      properties:
        count: 
          type: integer
          format: int32
          example: 10
        start: 
          type: integer
          format: int32
          example: 10
        data: 
          type: object
          properties: 
            hello-world: 
              type: boolean
Generation Details
java -jar "./node_modules/@openapitools/openapi-generator-cli/versions/6.3.0.jar" generate --input-spec="./src/schema/swagger.yaml" --generator-name="typescript-fetch" --output="./.generated/" --additional-properties="supportsES6=true,withInterfaces=true"
Steps to reproduce
  1. Clone the example repository: https://github.com/dschu-lab/openapi-typescript-fetch-issue
  2. Run npm install
  3. Run npm run generate to generate the client code
  4. Run npm run execute to execute the example query
  5. Notice the output in the console will contain an incorrect url: https://openapi-typescript-bug.free.mockoapp.net/hello[object Object]

I have also created a Github workflow that runs the necessary steps to reproduce the issue:
https://github.com/dschu-lab/openapi-typescript-fetch-issue/actions/runs/5620936093/job/15230781491#step:6:9

Related issues/PRs

#569

Suggest a fix

I think we have to update the logic in /main/resources/typescript-fetch/apis.mustache, but not sure which approach to follow / how to differentiate between the different cases.

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