Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2233
Closed
Open
Issue created Feb 25, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: 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 (closed).

Suggest a fix

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

Assignee
Assign to
Time tracking