OpenAPITools / OpenAPITools/openapi-generator
[BUG][Typescript] Invalid type for the enum array
- 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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Array of enums causes compilation error:
index:
type: array
items:
type: string
enum:
- "1"
- "1"
- "-1"
error:
public property ''index'' of exported class has or is using private name 'InnerEnum'.
31 'index'?: Array<{ [key: InnerEnum]: InnerEnum; }>;
openapi-generator version
both master and latest release.
OpenAPI declaration file content or url
Generation Details
Generator typescript.
Steps to reproduce
Run generator for schema above.
Related issues/PRs
Suggest a fix
datatypeWithEnum is not set properly in model:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript/model/model.mustache#L22
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 with modules/openapi-generator/src/main/resources/typescript/model/model.mustache at the referenced line, then generate a TypeScript model from the enum-array schema in the issue. Check the generated declaration and run the relevant generator tests or compilation checks. Done means the generated model compiles without the private-name error and represents the enum array correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100