Skip to content

[BUG][typescript-fetch] deepObject serialization not supported in query string #2233

@Dijky

Description

@Dijky

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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

A query parameter of type: object using additionalProperties produces Typescript code that fails to compile.

A similar parameter without additionalProperties that instead specifies properties compiles properly, but serializes the parameter improperly.

Typescript compiler error with additionalProperties
api/test/apis/DefaultApi.ts
Type error: Type '{ [key: string]: number; }' is not assignable to type 'string | number | boolean | (string | number | boolean)[]'.
  Type '{ [key: string]: number; }' is not assignable to type 'string'.  TS2322

    30 | 
    31 |         if (requestParameters.foffset !== undefined) {
  > 32 |             queryParameters['foffset'] = requestParameters.foffset;
       |             ^
    33 |         }
    34 | 
    35 |         const headerParameters: runtime.HTTPHeaders = {};
Invalid serialization with specified properties

The parameter is decoded to the string representation of an object in Javascript:

foffset=%5Bobject%20Object%5D (URL encoded)
foffset=[object Object] (URL decoded)

openapi-generator version

v4.0.0-beta2

As far as I can tell, there have been no relevant changes on master.

OpenAPI declaration file
openapi: 3.0.0
info:
  title: Test API
  version: 0.0.1
paths:
  /search:
    get:
      parameters:
        - name: foffset
          in: query
          required: false
          schema:
            type: object
            additionalProperties:
              type: integer
      responses:
        '200':
          description: OK
Command line used for generation

openapi-generator generate -g typescript-fetch -i ./test.openapi.yml -o api/

Steps to reproduce
  1. Specify a query parameter of type: object.
  2. Generate typescript-fetch client code.
  3. Include/compile the generated API typescript file (additionalProperties variant fails here).
  4. Perform an API request providing an object for the parameter.
Related issues/PRs

Possibly related to PR #569 and Issue #802.

Suggest a fix

I'm working on a first pull request.
The idea is to allow nested HTTPQuery objects that are recursively serialized.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions