OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Typescript] Application/JSON query parameter not serialized correctly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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? 4.3.0
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I'm trying to generate the SDK with this endpoint definition:
'/entities/{id}/secondentities':
get:
operationId: getSecondEntitiesByEntities
tags:
- channels
parameters:
- in: path
name: id
schema:
type: integer
required: true
- $ref: '#/components/parameters/problematicParameter'
responses:
'200':
$ref: '#/components/responses/data200'
'404':
description: Not found
'500':
description: Internal server error
and the parameter is described as a content/application-json complex object that should be serialized in the query string:
problematicParameter:
in: query
required: false
name: filter
content:
application/json:
schema:
$ref: '#/components/schemas/problematicParameterSchema'
The schema is something like this:
problematicParameterSchema:
type: object
properties:
tags:
type: array
items:
type: string
attributes:
type: array
items:
type: string
The generated typescript code has a signature like this:
public getSecondEntitiesByEntities(id: number, filter?: ProblematicParameterSchema, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<Array<PlacemarkData>>;
The model of ProblematicParameter is correctly generated, but when I call this function with a valid object of type ProblematicParameterSchema the URL is not generated correctly.
For example with:
getSecondEntitiesByEntities(1, {attributes: ['c', 'd'], tags: ['a', 'b']})
the generated URL is:
API_BASE/entities/{id}/secondentities?attributes="c"&attributes="d"&tags="a"&tags="b"
completely ignoring the name filter of the parameter.
The expected result should be something like this:
API_BASE/entities/{id}/secondentities?filter='{"attributes": ["c", "d"], "tags": ["a", "b"]}'
openapi-generator version
4.3.0
OpenAPI declaration file content or url
Command line used for generation
openapi-generator generate -i oas3.json -o sdk -g typescript-angular
Steps to reproduce
- Create the schema described above
- Create the parameter described above
- Run
Related issues/PRs
Suggest a fix
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 running the shown OpenAPI Generator command with the reproduction specification and inspect the generated TypeScript client request for the application/json query parameter. Compare the serialized URL with the expected filter parameter, and consider the issue done when the generated client preserves the parameter name and serializes the object as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100