OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-node] Enum params in form body generated as plain strings
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 a POST form parameter that is an enum, the generated client uses plain string for the argument type.
- form parameter:
scope: { type: string, enum: [scope1, scope2, scope3] } - expected generated method:
public async test (scope: ScopeEnum, options: ...): ..., using either:enum ScopeEnum { scope1,scope2, scope3 }type ScopeType = 'scope1' | 'scope2' | 'scope3'
- actual generated method:
public async test (scope: string, options: ...): ...
Side question out of curiosity: why are form bodies generated as separate method arguments, while all other request bodies are generated as a single argument typed as a generated model?
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: string
enum: [scope1, scope2, scope3]
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.
- Inspect the client code :)
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 running the provided openapi-generator command with the included OpenAPI 3.0.2 YAML and inspect the generated typescript-node client method for the form parameter. Trace how the application/x-www-form-urlencoded schema and its enum are represented during generation; done means the scope argument uses a generated enum or string-union type instead of plain string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100