OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch][possibly other languages] Semi-colon delimited path parameters (style: matrix) results in [object Object]
Nobody has claimed this yet.
- 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
- Clone the example repository: https://github.com/dschu-lab/openapi-typescript-fetch-issue
- Run
npm install - Run
npm run generateto generate the client code - Run
npm run executeto execute the example query - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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