Bug: Enums will not correctly generarted
Hi, i try to generate some enums.
export type AddedRemoveEvent = {
type: EventType.ADDED | EventType.REMOVED;
target: EventUser;
};
export type AssignUnassignEvent = {
type: EventType.ASSIGNED | EventType.UNASSIGNED;
target: EventUser;
};
export type RatedEvent = {
type: EventType.RATED;
rating: number;
};
export type OpenClosedEvent = {
type: EventType.OPENED | EventType.CLOSED;
previousState: TicketStatus;
};
export type CreatedDeletedEvent = {
type: EventType.CREATED | EventType.DELETED;
};
export type EventData =
| AddedRemoveEvent
| AssignUnassignEvent
| RatedEvent
| OpenClosedEvent
| CreatedDeletedEvent;
export enum EventType {
CREATED = "created",
CLOSED = "closed",
OPENED = "opened",
DELETED = "deleted",
RATED = "rated",
ADDED = "added",
REMOVED = "removed",
COMMAND = "command",
ASSIGNED = "assigned",
UNASSIGNED = "unassigned",
OTHER = "other",
}
This will generate:
"EventType.ADDED": {
"enum": [
"added"
],
"type": "string",
"x-enum-varnames": [
"ADDED"
]
},
"EventType.REMOVED": {
"enum": [
"removed"
],
"type": "string",
"x-enum-varnames": [
"REMOVED"
]
},
"AddedRemoveEvent": {
"properties": {
"target": {
"$ref": "#/components/schemas/EventUser"
},
"type": {
"anyOf": [
{
"$ref": "#/components/schemas/EventType.ADDED"
},
{
"$ref": "#/components/schemas/EventType.REMOVED"
}
]
}
},
"required": [
"target",
"type"
],
"type": "object"
},
"EventType.ASSIGNED": {
"enum": [
"assigned"
],
"type": "string",
"x-enum-varnames": [
"ASSIGNED"
]
},
"EventType.UNASSIGNED": {
"enum": [
"unassigned"
],
"type": "string",
"x-enum-varnames": [
"UNASSIGNED"
]
},
"AssignUnassignEvent": {
"properties": {
"target": {
"$ref": "#/components/schemas/EventUser"
},
"type": {
"anyOf": [
{
"$ref": "#/components/schemas/EventType.ASSIGNED"
},
{
"$ref": "#/components/schemas/EventType.UNASSIGNED"
}
]
}
},
"required": [
"target",
"type"
],
"type": "object"
},
I dont post the full swagger file.
You see that tsoa is generating everytime a new enum for each used enum. Is their away to prevent this?
There's a bug in the typeResolver.ts that enums types are resolved to the first element of the enum values list
There's a bug in the typeResolver.ts that enums types are resolved to the first element of the enum values list
I think that might be less of a bug and more of a choice. A lot of tools don't support them.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
As always: TSOA cannot handle interface properties that use already-initialized enums.
How is that a feature, this breaks my whole type validation