OpenAPITools / OpenAPITools/openapi-generator

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

Open
#16,153 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

https://github.com/OpenAPITools/openapi-generator/pull/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache around the linked path-parameter logic, then reproduce the issue with the provided example repository using npm install, npm run generate, and npm run execute. Done means matrix-style parameters produce the expected semicolon-delimited URL instead of [object Object].

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.