-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[typescript] support for enum #665
Comments
@jmini can you give an example? |
@macjohnny thank you for asking... I wanted to do it but I forgot. I have the feeling our problem is for enum at top level. This is well supported in Java (client/server). My colleague reported it to me as broken in Typescript. openapi: 3.0.1
info:
title: issue 665 test
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/random:
get:
operationId: randomOp
responses:
'201':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/SomeObj"
components:
schemas:
SomeObj:
type: object
properties:
id:
type: integer
format: int64
color:
$ref: "#/components/schemas/Color"
Color:
type: string
enum:
- red
- green
- yellow
- other Generated /**
* issue 665 test
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* OpenAPI spec version: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export class Color {
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
];
static getAttributeTypeMap() {
return Color.attributeTypeMap;
}
} |
This is not solved at all by #569. But this is probably because |
Same problem here. For typescript-node the generator does not correctly generate typescript enums if the enum is defined in OpenApi on the top level. On the other side if it the enum is defined inside an object, everything works fine. The bug seems to be in typescript-node/model.mustache. The template should make a difference between objects and enums, which it doesn't. The fix shouldn't be to difficult, I am trying to fix it and making a pull request. |
@christof-vollrath-spring-media your fix worked for me. Any plans to get a PR merged into this repo? |
Looks like this will be merged for the 4.0.0 milestone #2266 |
That's great! Thanks for your efforts. |
fixed with #2266 |
Description
Enum are not correctly generated in typescript client. Some investigation are requested to understand what is going wrong.
See also: https://www.typescriptlang.org/docs/handbook/enums.html
CC: @kayhuba
openapi-generator version
3.1.2
Command line used for generation
CLI to use the
typescript-node
generator.The text was updated successfully, but these errors were encountered: