Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
Dijky opened this issue Feb 25, 2019 · 1 comment
Closed
5 of 6 tasks

Comments

@Dijky
Copy link
Contributor

Dijky commented Feb 25, 2019

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.

@auto-labeler
Copy link

auto-labeler bot commented Feb 25, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant