open-api
open-api copied to clipboard
Allow openapi-types extensions of other things than `OperationObject`
It seems today extensions such as x-myexension is only possible to pass through to OperationObject<T> by putting it in T of Document<T>. However openapi v3 supports extensions in the following places according to the docs:
- info section
- paths section, individual paths and operations
- operation parameters
- responses
- tags
- security schemes
Specifically I'm trying to extend securitySchemes which does not seem possible today?
As a temporary work-around I made this mapped type which allows for extension of SecuritySchemeObject:
import { OpenAPIV3 } from "openapi-types";
export type DocumentEx<TOperationEx extends {} = {}, TSecuritySchemeEx extends {} = {}> = {
[P in keyof OpenAPIV3.Document<TOperationEx>]: P extends "components"
? MapComponents<OpenAPIV3.Document<TOperationEx>[P], TSecuritySchemeEx>
: OpenAPIV3.Document<TOperationEx>[P];
};
type MapComponents<T, TSecuritySchemeEx extends {}> = {
[P in keyof T]: P extends "securitySchemes" ? MapSecuritySchemes<T[P], TSecuritySchemeEx> : T[P];
};
type MapSecuritySchemes<T, TSecuritySchemeEx extends {}> = {
[P in keyof T]: MapSecuritySchemeObject<T[P], TSecuritySchemeEx>;
};
type MapSecuritySchemeObject<T, TSecuritySchemeEx extends {}> = T extends OpenAPIV3.SecuritySchemeObject
? T & TSecuritySchemeEx
: T;