Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dschu-lab opened this issue Jul 21, 2023 · 0 comments

Comments

@dschu-lab
Copy link
Contributor

dschu-lab commented Jul 21, 2023

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.

@dschu-lab dschu-lab changed the title [BUG][typescript-fetch][possibly other languages] Semi-colon delimited path parameters matrix results in [object Object] [BUG][typescript-fetch][possibly other languages] Semi-colon delimited path parameters (style: matrix) results in [object Object] Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant