OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Typescript] Application/JSON query parameter not serialized correctly

Open
#6,367 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
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
  1. Create the schema described above
  2. Create the parameter described above
  3. Run
Related issues/PRs
Suggest a fix

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.