From d349dca8972c78ab35912fb9696c42abf1483f16 Mon Sep 17 00:00:00 2001 From: Sean Kruzel Date: Tue, 21 Apr 2026 16:31:29 -0700 Subject: [PATCH] Add OpenAPI 3.2 type definitions --- packages/openapi-types/README.md | 11 +- packages/openapi-types/index.ts | 236 ++++++++++++++++++++++++++++++- 2 files changed, 241 insertions(+), 6 deletions(-) diff --git a/packages/openapi-types/README.md b/packages/openapi-types/README.md index b17b7c8d..cfea7b22 100644 --- a/packages/openapi-types/README.md +++ b/packages/openapi-types/README.md @@ -1,20 +1,24 @@ # openapi-types [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Coveralls Status][coveralls-image]][coveralls-url] + > Types for OpenAPI documents. ## Usage ```typescript -import { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from "openapi-types"; +import { OpenAPIV2, OpenAPIV3, OpenAPIV3_1, OpenAPIV3_2 } from 'openapi-types'; function processV2(doc: OpenAPIV2.Document) {} function processV3(doc: OpenAPIV3.Document) {} function processV3_1(doc: OpenAPIV3_1.Document) {} + +function processV3_2(doc: OpenAPIV3_2.Document) {} ``` ## LICENSE -`````` + +``` The MIT License (MIT) Copyright (c) 2018 Kogo Software LLC @@ -36,11 +40,10 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -`````` +``` [downloads-image]: http://img.shields.io/npm/dm/openapi-types.svg [npm-url]: https://npmjs.org/package/openapi-types [npm-image]: http://img.shields.io/npm/v/openapi-types.svg - [coveralls-url]: https://coveralls.io/github/kogosoftwarellc/open-api?branch=main [coveralls-image]: https://coveralls.io/repos/github/kogosoftwarellc/open-api/badge.svg?branch=main diff --git a/packages/openapi-types/index.ts b/packages/openapi-types/index.ts index 26cada56..2420dac8 100644 --- a/packages/openapi-types/index.ts +++ b/packages/openapi-types/index.ts @@ -8,12 +8,16 @@ export namespace OpenAPI { export type Document = | OpenAPIV2.Document | OpenAPIV3.Document - | OpenAPIV3_1.Document; + | OpenAPIV3_1.Document + | OpenAPIV3_2.Document; export type Operation = | OpenAPIV2.OperationObject | OpenAPIV3.OperationObject - | OpenAPIV3_1.OperationObject; + | OpenAPIV3_1.OperationObject + | OpenAPIV3_2.OperationObject; export type Parameter = + | OpenAPIV3_2.ReferenceObject + | OpenAPIV3_2.ParameterObject | OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject | OpenAPIV3.ReferenceObject @@ -21,6 +25,7 @@ export namespace OpenAPI { | OpenAPIV2.ReferenceObject | OpenAPIV2.Parameter; export type Parameters = + | (OpenAPIV3_2.ReferenceObject | OpenAPIV3_2.ParameterObject)[] | (OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject)[] | (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[] | (OpenAPIV2.ReferenceObject | OpenAPIV2.Parameter)[]; @@ -33,6 +38,233 @@ export namespace OpenAPI { } } +export namespace OpenAPIV3_2 { + type Modify = Omit & R; + + type OAuthFlowObject = { + authorizationUrl?: string; + deviceAuthorizationUrl?: string; + tokenUrl?: string; + refreshUrl?: string; + scopes: { + [scope: string]: string; + }; + }; + + type PathsWebhooksComponents = { + paths: PathsObject; + webhooks: Record; + components: ComponentsObject; + }; + + export type Document = Modify< + Omit, 'paths' | 'webhooks' | 'components' | 'tags'>, + { + paths?: PathsObject; + webhooks?: Record; + components?: ComponentsObject; + tags?: TagObject[]; + } & ( + | (Pick, 'paths'> & + Omit>, 'paths'>) + | (Pick, 'webhooks'> & + Omit>, 'webhooks'>) + | (Pick, 'components'> & + Omit>, 'components'>) + ) + >; + + export type InfoObject = OpenAPIV3_1.InfoObject; + + export type ContactObject = OpenAPIV3_1.ContactObject; + + export type LicenseObject = OpenAPIV3_1.LicenseObject; + + export type ServerObject = OpenAPIV3_1.ServerObject; + + export type ServerVariableObject = OpenAPIV3_1.ServerVariableObject; + + export type PathsObject = Record< + string, + (PathItemObject & P) | undefined + >; + + export enum HttpMethods { + GET = 'get', + PUT = 'put', + POST = 'post', + DELETE = 'delete', + OPTIONS = 'options', + HEAD = 'head', + PATCH = 'patch', + TRACE = 'trace', + QUERY = 'query', + } + + export type PathItemObject = Modify< + OpenAPIV3_1.PathItemObject, + { + query?: OperationObject; + additionalOperations?: Record>; + } + > & + { + [method in HttpMethods]?: OperationObject; + }; + + export type OperationObject = OpenAPIV3_1.OperationObject< + T + >; + + export type ExternalDocumentationObject = OpenAPIV3_1.ExternalDocumentationObject; + + export type ParameterObject = OpenAPIV3_1.ParameterObject; + + export type HeaderObject = OpenAPIV3_1.HeaderObject; + + export type ParameterBaseObject = OpenAPIV3_1.ParameterBaseObject; + + export type NonArraySchemaObjectType = OpenAPIV3_1.NonArraySchemaObjectType; + + export type ArraySchemaObjectType = OpenAPIV3_1.ArraySchemaObjectType; + + export type SchemaObject = OpenAPIV3_1.SchemaObject; + + export interface ArraySchemaObject extends OpenAPIV3_1.ArraySchemaObject {} + + export interface NonArraySchemaObject + extends OpenAPIV3_1.NonArraySchemaObject {} + + export type BaseSchemaObject = OpenAPIV3_1.BaseSchemaObject; + + export type DiscriminatorObject = OpenAPIV3_1.DiscriminatorObject; + + export type XMLObject = OpenAPIV3_1.XMLObject; + + export type ReferenceObject = OpenAPIV3_1.ReferenceObject; + + export type ExampleObject = OpenAPIV3_1.ExampleObject; + + export type MediaTypeObject = Modify< + OpenAPIV3_1.MediaTypeObject, + { + itemSchema?: SchemaObject | ReferenceObject; + prefixEncoding?: EncodingObject[]; + itemEncoding?: EncodingObject; + } + >; + + export type EncodingObject = OpenAPIV3_1.EncodingObject; + + export type RequestBodyObject = Modify< + OpenAPIV3_1.RequestBodyObject, + { + content: { [media: string]: MediaTypeObject }; + } + >; + + export type ResponsesObject = Record< + string, + ReferenceObject | ResponseObject + >; + + export type ResponseObject = Modify< + OpenAPIV3_1.ResponseObject, + { + summary?: string; + headers?: { [header: string]: ReferenceObject | HeaderObject }; + content?: { [media: string]: MediaTypeObject }; + links?: { [link: string]: ReferenceObject | LinkObject }; + } + >; + + export type LinkObject = Modify< + OpenAPIV3_1.LinkObject, + { + server?: ServerObject; + } + >; + + export type CallbackObject = Record; + + export type SecurityRequirementObject = OpenAPIV3_1.SecurityRequirementObject; + + export type ComponentsObject = Modify< + OpenAPIV3_1.ComponentsObject, + { + schemas?: Record; + responses?: Record; + parameters?: Record; + examples?: Record; + requestBodies?: Record; + headers?: Record; + securitySchemes?: Record; + links?: Record; + callbacks?: Record; + pathItems?: Record; + mediaTypes?: Record; + } + >; + + export type SecuritySchemeObject = + | HttpSecurityScheme + | ApiKeySecurityScheme + | OAuth2SecurityScheme + | OpenIdSecurityScheme + | MutualTLSSecurityScheme; + + export interface MutualTLSSecurityScheme { + type: 'mutualTLS'; + description?: string; + deprecated?: boolean; + } + + export type HttpSecurityScheme = Modify< + OpenAPIV3_1.HttpSecurityScheme, + { + deprecated?: boolean; + } + >; + + export type ApiKeySecurityScheme = Modify< + OpenAPIV3_1.ApiKeySecurityScheme, + { + deprecated?: boolean; + } + >; + + export type OAuth2SecurityScheme = Modify< + OpenAPIV3_1.OAuth2SecurityScheme, + { + oauth2MetadataUrl?: string; + deprecated?: boolean; + flows: { + implicit?: OAuthFlowObject; + password?: OAuthFlowObject; + clientCredentials?: OAuthFlowObject; + authorizationCode?: OAuthFlowObject; + deviceAuthorization?: OAuthFlowObject; + }; + } + >; + + export type OpenIdSecurityScheme = Modify< + OpenAPIV3_1.OpenIdSecurityScheme, + { + deprecated?: boolean; + } + >; + + export type TagObject = Modify< + OpenAPIV3_1.TagObject, + { + summary?: string; + parent?: string; + kind?: string; + } + >; +} + export namespace OpenAPIV3_1 { type Modify = Omit & R;