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-node] invalid handling of array param in forms, encoding options ignored #3781

Open
5 of 6 tasks
quezak opened this issue Aug 28, 2019 · 6 comments
Open
5 of 6 tasks

Comments

@quezak
Copy link

quezak commented Aug 28, 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

When using an array POST form parameter, the generated client serializes it improperly, and ignores the encoding settings in the request body specification.

  • parameter: scope, an array of strings
  • sample call: api.test(['scope1', 'scope2'])
  • expected request body with encoding.scope.explode: true: scope=scope1&scope=scope2
  • expected request body with encoding.scope.explode: false: scope=scope1,scope2
  • actual request body: scope%5B0%5D=scope1&scope%5B1%5D=scope2, which is the urlencoded form of scope[0]=scope1&scope[1]=scope2...
openapi-generator version
  • openapi-generator-cli-5.0.0-20190811.165202-11.jar
  • openapi-generator-cli-4.1.1.jar
OpenAPI declaration file content or url
openapi: 3.0.2

info:
  version: 0.0.1
  title: test

servers:
  - url: http://test

paths:
  /test:
    post:
      summary: test
      operationId: test
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required: [scope]
              properties:
                scope:
                  type: array
                  items:
                    type: string
                    enum: [scope1, scope2, scope3]
            encoding:
              scope:
                # btw: what is `contentType` intended to do here for a string param?
                # cli complains if it's not present, but the value seems to be ignored anyway...
                contentType: application/x-www-form-urlencoded
                style: form
                explode: false
      responses:
        '204':
          description: success
Command line used for generation

java -jar $GENERATOR_JAR generate -i test.yml -g typescript-node -p supportsES6=true -o .

Steps to reproduce
  1. Generate the client.
  2. Make the test call to any server, log the error and check the request body.
@auto-labeler
Copy link

auto-labeler bot commented Aug 28, 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.

@quezak
Copy link
Author

quezak commented Aug 28, 2019

Note: I've also tried using other allowed values for encoding.scope.style -- it's completely ignored, the generated code doesn't change at all.

@macjohnny
Copy link
Member

@quezak would you like to implement a fix?

@quezak
Copy link
Author

quezak commented Aug 28, 2019

@macjohnny I'll take a look tomorrow if it's easy enough. For now I've worked around this by directly passing a comma-separated string as the param, but that's not typesafe.

Do you maybe know the expected rough timeline for the typescript generators rewrite (#802)? If the work is already advanced, it might be not feasible to fix issues in the current TS generators.

@macjohnny
Copy link
Member

I don't know when the rewrite will be finished, so for the time being, the current typescript generators are maintained.

@fboucquez
Copy link

fboucquez commented Mar 5, 2020

Any news on this issue? I also have the problem with query params. The style and explode gets ignored. It only renders the [] style query params like id%5B0%5D=1&id%5B1%5D=2 or id[]=1&id[]=2

ids:
      name: type
      in: query
      style: form
      explode: true
      schema:
        type: array
        items:
          type: integer

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

3 participants