Skip to content
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

--enum-values tries to access array props like if they were objects in order to define the array type #2140

Open
2 tasks done
darkbasic opened this issue Feb 5, 2025 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@darkbasic
Copy link

openapi-typescript version

7.6.1

Node.js version

v20.17.0

OS + version

Arch Linux

Description

Image

Image

export interface components {
    schemas: {
        BatchMappingItemRequest: {
            data: {
                /** @enum {string} */
                mode?: "create" | "update" | "delete";
            }[];
        };
}

export const batchMappingItemRequestDataModeValues: ReadonlyArray<components["schemas"]["BatchMappingItemRequest"]["data"]["mode"]> = ["create", "update", "delete"];

Since data is an array you won't be able to access mode on components["schemas"]["BatchMappingItemRequest"]["data"]["mode"] (Property 'mode' does not exist on type).

Reproduction

See description.

Expected result

type FlattenedDeepRequired<T> = {
    [K in keyof T]: Required<FlattenedDeepRequired<T[K] extends unknown[] ? T[K][number] : T[K]>>;
};

type ReadonlyArray<T> = [
    Exclude<T, undefined>
] extends [
    any[]
] ? Readonly<Exclude<T, undefined>> : Readonly<Exclude<T, undefined>[]>;

export const batchMappingItemRequestDataModeValues: ReadonlyArray<FlattenedDeepRequired<components>["schemas"]["BatchMappingItemRequest"]["data"]["mode"]> = ["create", "update", "delete"];

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

@darkbasic darkbasic added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Feb 5, 2025
darkbasic added a commit to darkbasic/openapi-typescript that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant