Open
Description
openapi-typescript version
7.6.1
Node.js version
v20.17.0
OS + version
Arch Linux
Description
export interface operations {
"mapping.configurations.index": {
parameters: {
query?: {
sort_key?: "created_at" | "updated_at" | null;
};
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
};
}
type ReadonlyArray<T> = [
Exclude<T, undefined>
] extends [
any[]
] ? Readonly<Exclude<T, undefined>> : Readonly<Exclude<T, undefined>[]>;
export const pathsMappingConfigurationsGetParametersQuerySort_keyValues: ReadonlyArray<paths["/mapping/configurations"]["get"]["parameters"]["query"]["sort_key"]> = ["created_at", "updated_at"];
Since query
is optional you won't be able to access sort_key
on paths["/mapping/configurations"]["get"]["parameters"]["query"]
(Property 'sort_key' does not exist on type
).
Reproduction
{
"openapi": "3.1.0",
"info": {
"title": "API Portal",
"version": "1.0.0",
"description": "This is the **mapping API** description"
},
"paths": {
"\/mapping\/configurations": {
"get": {
"operationId": "mapping.configurations.index",
"summary": "Display a listing of the resource",
"tags": [
"MappingConfiguration"
],
"parameters": [
{
"name": "sort_key",
"in": "query",
"schema": {
"type": [
"string",
"null"
],
"enum": [
"created_at",
"updated_at"
]
}
}
],
"responses": {}
},
"post": {}
},
Expected result
We could easily brute force our way into the array type using DeepRequired
:
type DeepRequired<T> = {
[K in keyof T]: Required<DeepRequired<T[K]>>
}
export const pathsMappingConfigurationsGetParametersQuerySort_keyValues: ReadonlyArray<DeepRequired<paths>["/mapping/configurations"]["get"]["parameters"]["query"]["sort_key"]> = ["created_at", "updated_at"];
I guess we could modify oapiRef()
to prefix the base type with DeepRequired<>
and use stringToAST
to inject the helper type to the footer.
I would open open a PR but I'm not familiar enough with the Typescript compiler API to do so quickly, so unless no one else volunteers to do so I would gladly pass.
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint
)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)