OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-node] invalid handling of array param in forms, `encoding` options ignored
Nobody has claimed this yet.
- 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?
- 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 ofscope[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
- Generate the client.
- Make the test call to any server, log the error and check the request body.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the typescript-node client with the supplied OpenAPI YAML and command, then inspect the generated form-request handling. Reproduce the call with scope=['scope1','scope2'] for both explode settings and compare the request body with the expected scope=scope1&scope=scope2 or scope=scope1,scope2 output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100