Enum of object in array uses union types
If a schema response definition consists of:
- an array
- containing an object
- which contains an enum field
This enum will be generated using union types, not an enum.
This does not happen for objects not nested in an array.
A minimal reproduction can be found here: https://github.com/tommilligan/openapi-typescript-codegen-861-reproduction
Actual output:
export type GetAllAnimalsResponse = {
animals: Array<{
type: 'frog' | 'badger',
}>;
}
Expected output:
export type GetAllAnimalsResponse = {
animals: Array<{
type: GetAllAnimalsResponse.type,
}>;
}
export namespace GetAllAnimalsResponse {
export enum type {
FROG = 'frog',
BADGER = 'badger',
}
}
I'll look to see if I can submit a PR, any hint of where to start would be appreciated.
After some poking, I suspect that this is due to this case here: https://github.com/ferdikoomen/openapi-typescript-codegen/blob/b532279969308937b879106fb41c372fbb24c90b/src/utils/registerHandlebarHelpers.ts#L44
I see that we only refer to parent when nesting as part of an interface - it seems logical that we'd also need to do some sort of parent referencing when nesting in arrays?