fork of hey-api/openapi-ts because I need some additional things

Merge pull request #3119 from hey-api/copilot/add-extension-fields-support

feat: Propagate OpenAPI extension fields (x-*) to IR and plugins

authored by

Lubos and committed by
GitHub
facca401 e6a4e483

+352 -202
+5
.changeset/every-coins-sell.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + **parser**: expose OpenAPI extension keywords
+32 -21
packages/openapi-ts/src/ir/types.d.ts
··· 8 8 9 9 import type { IRMediaType } from './mediaType'; 10 10 11 + /** 12 + * OpenAPI Specification Extensions. 13 + * 14 + * See {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}. 15 + */ 16 + export interface SpecificationExtensions { 17 + [extension: `x-${string}`]: unknown; 18 + } 19 + 11 20 interface IRBodyObject { 12 21 mediaType: string; 13 22 /** ··· 26 35 schemas?: Record<string, IRSchemaObject>; 27 36 } 28 37 29 - export interface IROperationObject { 38 + export interface IROperationObject extends SpecificationExtensions { 30 39 body?: IRBodyObject; 31 40 deprecated?: boolean; 32 41 description?: string; ··· 50 59 } 51 60 52 61 interface IRParameterObject 53 - extends Pick<JsonSchemaDraft2020_12, 'deprecated' | 'description'> { 62 + extends Pick<JsonSchemaDraft2020_12, 'deprecated' | 'description'>, 63 + SpecificationExtensions { 54 64 /** 55 65 * Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of `contentType` (implicit or explicit) SHALL be ignored. 56 66 */ ··· 124 134 125 135 interface IRSchemaObject 126 136 extends Pick< 127 - JsonSchemaDraft2020_12, 128 - | '$ref' 129 - | 'const' 130 - | 'default' 131 - | 'deprecated' 132 - | 'description' 133 - | 'exclusiveMaximum' 134 - | 'exclusiveMinimum' 135 - | 'maximum' 136 - | 'maxItems' 137 - | 'maxLength' 138 - | 'minimum' 139 - | 'minItems' 140 - | 'minLength' 141 - | 'pattern' 142 - | 'required' 143 - | 'title' 144 - | 'example' 145 - > { 137 + JsonSchemaDraft2020_12, 138 + | '$ref' 139 + | 'const' 140 + | 'default' 141 + | 'deprecated' 142 + | 'description' 143 + | 'exclusiveMaximum' 144 + | 'exclusiveMinimum' 145 + | 'maximum' 146 + | 'maxItems' 147 + | 'maxLength' 148 + | 'minimum' 149 + | 'minItems' 150 + | 'minLength' 151 + | 'pattern' 152 + | 'required' 153 + | 'title' 154 + | 'example' 155 + >, 156 + SpecificationExtensions { 146 157 /** 147 158 * If the schema is intended to be used as an object property, it can be 148 159 * marked as read-only or write-only. This value controls whether the schema
+1 -4
packages/openapi-ts/src/openApi/2.0.x/parser/index.ts
··· 84 84 parseServers({ context }); 85 85 86 86 for (const path in context.spec.paths) { 87 - if (path.startsWith('x-')) { 88 - continue; 89 - } 90 - 87 + if (path.startsWith('x-')) continue; 91 88 const pathItem = context.spec.paths[path as PathKeys]!; 92 89 93 90 const finalPathItem = pathItem.$ref
+6 -1
packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts
··· 13 13 } from '../types/spec'; 14 14 import { contentToSchema, mediaTypeObjects } from './mediaType'; 15 15 import { paginationField } from './pagination'; 16 - import { schemaToIrSchema } from './schema'; 16 + import { parseExtensions, schemaToIrSchema } from './schema'; 17 17 18 18 interface Operation 19 19 extends Omit<OperationObject, 'parameters'>, ··· 75 75 parseOperationJsDoc({ 76 76 irOperation, 77 77 operation, 78 + }); 79 + 80 + parseExtensions({ 81 + source: operation, 82 + target: irOperation, 78 83 }); 79 84 80 85 return irOperation;
+6 -1
packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts
··· 8 8 SchemaObject, 9 9 } from '../types/spec'; 10 10 import { paginationField } from './pagination'; 11 - import { schemaToIrSchema } from './schema'; 11 + import { parseExtensions, schemaToIrSchema } from './schema'; 12 12 13 13 type Parameter = Exclude<ParameterObject, { in: 'body' }>; 14 14 ··· 164 164 if (parameter.required) { 165 165 irParameter.required = parameter.required; 166 166 } 167 + 168 + parseExtensions({ 169 + source: parameter, 170 + target: irParameter, 171 + }); 167 172 168 173 return irParameter; 169 174 };
+21
packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts
··· 270 270 return irSchema; 271 271 }; 272 272 273 + export const parseExtensions = ({ 274 + source, 275 + target, 276 + }: { 277 + source: object; 278 + target: object; 279 + }) => { 280 + for (const key in source) { 281 + if (key.startsWith('x-')) { 282 + (target as Record<string, unknown>)[key] = ( 283 + source as Record<string, unknown> 284 + )[key]; 285 + } 286 + } 287 + }; 288 + 273 289 const initIrSchema = ({ 274 290 schema, 275 291 }: { ··· 280 296 parseSchemaJsDoc({ 281 297 irSchema, 282 298 schema, 299 + }); 300 + 301 + parseExtensions({ 302 + source: schema, 303 + target: irSchema, 283 304 }); 284 305 285 306 return irSchema;
+5 -2
packages/openapi-ts/src/openApi/3.0.x/parser/index.ts
··· 120 120 parseServers({ context }); 121 121 122 122 for (const path in context.spec.paths) { 123 - const pathItem = context.spec.paths[path as keyof PathsObject]!; 123 + if (path.startsWith('x-')) continue; 124 + const pathItem = context.spec.paths[ 125 + path as keyof PathsObject 126 + ]! as PathItemObject; 124 127 125 128 const finalPathItem = pathItem.$ref 126 129 ? { ··· 149 152 servers: finalPathItem.servers, 150 153 summary: finalPathItem.summary, 151 154 }, 152 - path: path as keyof PathsObject, 155 + path: path as `/${string}`, 153 156 securitySchemesMap, 154 157 state, 155 158 };
+12 -2
packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
··· 6 6 import type { 7 7 OperationObject, 8 8 PathItemObject, 9 + ReferenceObject, 9 10 RequestBodyObject, 10 11 ResponseObject, 11 12 SecuritySchemeObject, 12 13 } from '../types/spec'; 13 14 import { contentToSchema, mediaTypeObjects } from './mediaType'; 14 15 import { paginationField } from './pagination'; 15 - import { schemaToIrSchema } from './schema'; 16 + import { parseExtensions, schemaToIrSchema } from './schema'; 16 17 17 18 interface Operation 18 19 extends Omit<OperationObject, 'parameters'>, ··· 72 73 parseOperationJsDoc({ 73 74 irOperation, 74 75 operation, 76 + }); 77 + 78 + parseExtensions({ 79 + source: operation, 80 + target: irOperation, 75 81 }); 76 82 77 83 return irOperation; ··· 166 172 } 167 173 168 174 for (const name in operation.responses) { 175 + if (name.startsWith('x-')) continue; 176 + 169 177 if (!irOperation.responses) { 170 178 irOperation.responses = {}; 171 179 } 172 180 173 - const response = operation.responses[name]!; 181 + const response = operation.responses[name]! as 182 + | ResponseObject 183 + | ReferenceObject; 174 184 const responseObject = 175 185 '$ref' in response 176 186 ? context.resolveRef<ResponseObject>(response.$ref)
+6 -1
packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts
··· 9 9 } from '../types/spec'; 10 10 import { mediaTypeObjects } from './mediaType'; 11 11 import { paginationField } from './pagination'; 12 - import { schemaToIrSchema } from './schema'; 12 + import { parseExtensions, schemaToIrSchema } from './schema'; 13 13 14 14 /** 15 15 * Returns default parameter `allowReserved` based on value of `in`. ··· 172 172 if (parameter.required) { 173 173 irParameter.required = parameter.required; 174 174 } 175 + 176 + parseExtensions({ 177 + source: parameter, 178 + target: irParameter, 179 + }); 175 180 176 181 return irParameter; 177 182 };
+21
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
··· 368 368 return irSchema; 369 369 }; 370 370 371 + export const parseExtensions = ({ 372 + source, 373 + target, 374 + }: { 375 + source: object; 376 + target: object; 377 + }) => { 378 + for (const key in source) { 379 + if (key.startsWith('x-')) { 380 + (target as Record<string, unknown>)[key] = ( 381 + source as Record<string, unknown> 382 + )[key]; 383 + } 384 + } 385 + }; 386 + 371 387 const initIrSchema = ({ 372 388 schema, 373 389 }: { ··· 378 394 parseSchemaJsDoc({ 379 395 irSchema, 380 396 schema, 397 + }); 398 + 399 + parseExtensions({ 400 + source: schema, 401 + target: irSchema, 381 402 }); 382 403 383 404 return irSchema;
+90 -77
packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts
··· 1 1 import type { EnumExtensions } from '~/openApi/shared/types/openapi-spec-extensions'; 2 2 3 3 /** 4 + * OpenAPI Specification Extensions. 5 + * 6 + * See {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#specification-extensions Specification Extensions}. 7 + */ 8 + export interface SpecificationExtensions { 9 + [extension: `x-${string}`]: unknown; 10 + } 11 + 12 + /** 4 13 * This is the root object of the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#openapi-description OpenAPI Description}. 5 14 * 6 15 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#specification-extensions Specification Extensions}. 7 16 */ 8 - export interface OpenApiV3_0_X { 17 + export interface OpenApiV3_0_X extends SpecificationExtensions { 9 18 /** 10 19 * An element to hold various Objects for the OpenAPI Description. 11 20 */ ··· 47 56 * 48 57 * TODO: examples 49 58 */ 50 - export interface CallbackObject { 59 + export interface CallbackObject extends SpecificationExtensions { 51 60 /** 52 61 * A Path Item Object used to define a callback request and expected responses. A {@link https://learn.openapis.org/examples/v3.0/callback-example.html complete example} is available. 53 62 */ 54 - [expression: string]: PathItemObject | ReferenceObject; 63 + [expression: string]: PathItemObject | ReferenceObject | unknown; 55 64 } 56 65 57 66 /** ··· 63 72 * 64 73 * TODO: examples 65 74 */ 66 - export interface ComponentsObject { 75 + export interface ComponentsObject extends SpecificationExtensions { 67 76 /** 68 77 * An object to hold reusable {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#callback-object Callback Objects}. 69 78 */ ··· 113 122 * email: support@example.com 114 123 * ``` 115 124 */ 116 - export interface ContactObject { 125 + export interface ContactObject extends SpecificationExtensions { 117 126 /** 118 127 * The email address of the contact person/organization. This MUST be in the form of an email address. 119 128 */ ··· 160 169 * TODO: default values examples 161 170 * TODO: examples 162 171 */ 163 - export interface EncodingObject { 172 + export interface EncodingObject extends SpecificationExtensions { 164 173 /** 165 174 * When this is true, parameter values are serialized using reserved expansion, as defined by {@link https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.3 RFC6570}, which allows {@link https://datatracker.ietf.org/doc/html/rfc3986#section-2.2 RFC3986's reserved character set}, as well as percent-encoded triples, to pass through unchanged, while still percent-encoding all other disallowed characters (including `%` outside of percent-encoded triples). Applications are still responsible for percent-encoding reserved characters that are {@link https://datatracker.ietf.org/doc/html/rfc3986#section-3.4 not allowed in the query string} (`[`, `]`, `#`), or have a special meaning in `application/x-www-form-urlencoded` (`-`, `&`, `+`); see Appendices {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#appendix-c-using-rfc6570-based-serialization C} and {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#appendix-e-percent-encoding-and-form-media-types E} for details. The default value is `false`. This field SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded`. 166 175 */ ··· 201 210 * 202 211 * TODO: examples 203 212 */ 204 - export interface ExampleObject { 213 + export interface ExampleObject extends SpecificationExtensions { 205 214 /** 206 215 * Long description for the example. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 207 216 */ ··· 232 241 * url: https://example.com 233 242 * ``` 234 243 */ 235 - export interface ExternalDocumentationObject { 244 + export interface ExternalDocumentationObject extends SpecificationExtensions { 236 245 /** 237 246 * A description of the target documentation. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 238 247 */ ··· 276 285 * version: 1.0.1 277 286 * ``` 278 287 */ 279 - export interface InfoObject { 288 + export interface InfoObject extends SpecificationExtensions { 280 289 /** 281 290 * The contact information for the exposed API. 282 291 */ ··· 313 322 * url: https://www.apache.org/licenses/LICENSE-2.0.html 314 323 * ``` 315 324 */ 316 - export interface LicenseObject { 325 + export interface LicenseObject extends SpecificationExtensions { 317 326 /** 318 327 * **REQUIRED**. The license name used for the API. 319 328 */ ··· 339 348 * 340 349 * TODO: examples 341 350 */ 342 - export interface LinkObject { 351 + export interface LinkObject extends SpecificationExtensions { 343 352 /** 344 353 * A description of the link. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 345 354 */ ··· 375 384 * 376 385 * TODO: examples 377 386 */ 378 - export interface MediaTypeObject { 387 + export interface MediaTypeObject extends SpecificationExtensions { 379 388 /** 380 389 * A map between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property. The `encoding` field SHALL only apply to {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#request-body-object Request Body Objects}, and only when the media type is `multipart` or `application/x-www-form-urlencoded`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. 381 390 */ ··· 401 410 * 402 411 * TODO: examples 403 412 */ 404 - export interface OAuthFlowObject { 413 + export interface OAuthFlowObject extends SpecificationExtensions { 405 414 /** 406 415 * **REQUIRED (`"implicit"`, `"authorizationCode"`)**. The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS. 407 416 */ ··· 425 434 * 426 435 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#specification-extensions Specification Extensions}. 427 436 */ 428 - export interface OAuthFlowsObject { 437 + export interface OAuthFlowsObject extends SpecificationExtensions { 429 438 /** 430 439 * Configuration for the OAuth Authorization Code flow. Previously called `accessCode` in OpenAPI 2.0. 431 440 */ ··· 451 460 * 452 461 * TODO: examples 453 462 */ 454 - export interface OperationObject { 463 + export interface OperationObject extends SpecificationExtensions { 455 464 /** 456 465 * A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#callback-object Callback Object} that describes a request that may be initiated by the API provider and the expected responses. 457 466 */ ··· 546 555 * 547 556 * TODO: examples 548 557 */ 549 - export interface ParameterObject { 558 + export interface ParameterObject extends SpecificationExtensions { 550 559 /** 551 560 * If `true`, clients MAY pass a zero-length string value in place of parameters that would otherwise be omitted entirely, which the server SHOULD interpret as the parameter being unused. Default value is `false`. If {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#parameter-style `style`} is used, and if {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#style-examples behavior is _n/a_ (cannot be serialized)}, the value of `allowEmptyValue` SHALL be ignored. Interactions between this field and the parameter's {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema-object Schema Object} are implementation-defined. This field is valid only for `query` parameters. Use of this field is NOT RECOMMENDED, and it is likely to be removed in a later revision. 552 561 */ ··· 618 627 * 619 628 * TODO: examples 620 629 */ 621 - export interface PathItemObject { 630 + export interface PathItemObject extends SpecificationExtensions { 622 631 /** 623 632 * Allows for a referenced definition of this path item. The value MUST be in the form of a URL, and the referenced structure MUST be in the form of a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#path-item-object Path Item Object}. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#relative-references-in-urls Relative References}. 624 633 */ ··· 680 689 * 681 690 * TODO: examples 682 691 */ 683 - export interface PathsObject { 692 + export interface PathsObject extends SpecificationExtensions { 684 693 /** 685 694 * A relative path to an individual endpoint. The field name MUST begin with a forward slash (`/`). The path is **appended** (no relative URL resolution) to the expanded URL from the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#server-object Server Object}'s `url` field in order to construct the full URL. {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#path-templating Path templating} is allowed. When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it's up to the tooling to decide which one to use. 686 695 */ ··· 728 737 * 729 738 * TODO: examples 730 739 */ 731 - export interface RequestBodyObject { 740 + export interface RequestBodyObject extends SpecificationExtensions { 732 741 /** 733 742 * **REQUIRED**. The content of the request body. The key is a media type or {@link https://tools.ietf.org/html/rfc7231#appendix-D media type range} and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. `"text/plain"` overrides `"text/*"` 734 743 */ ··· 750 759 * 751 760 * TODO: examples 752 761 */ 753 - export interface ResponseObject { 762 + export interface ResponseObject extends SpecificationExtensions { 754 763 /** 755 764 * A map containing descriptions of potential response payloads. The key is a media type or {@link https://tools.ietf.org/html/rfc7231#appendix-D media type range} and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. `"text/plain"` overrides `"text/*"` 756 765 */ ··· 782 791 * 783 792 * TODO: examples 784 793 */ 785 - export interface ResponsesObject { 794 + export interface ResponsesObject extends SpecificationExtensions { 786 795 /** 787 796 * Any {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#http-status-codes HTTP status code} can be used as the property name, but only one property per code, to describe the expected response for that HTTP status code. A {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#reference-object Reference Object} can link to a response that is defined in the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#components-responses OpenAPI Object's `components.responses`} section. This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character `X`. For example, `2XX` represents all response codes between `200` and `299`. Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX`, and `5XX`. If a response is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code. 788 797 */ 789 - [httpStatusCode: string]: ResponseObject | ReferenceObject | undefined; 798 + [httpStatusCode: string]: 799 + | ResponseObject 800 + | ReferenceObject 801 + | undefined 802 + | unknown; 790 803 /** 791 804 * The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses. A {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#reference-object Reference Object} can link to a response that the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#components-responses OpenAPI Object's `components.responses`} section defines. 792 805 */ ··· 844 857 * 845 858 * TODO: content, examples 846 859 */ 847 - export interface SchemaObject extends EnumExtensions { 860 + export interface SchemaObject extends EnumExtensions, SpecificationExtensions { 848 861 /** 849 862 * The value of "additionalProperties" MUST be a boolean or a schema. 850 863 * ··· 1097 1110 * 1098 1111 * TODO: examples 1099 1112 */ 1100 - export type SecuritySchemeObject = { 1113 + export type SecuritySchemeObject = SpecificationExtensions & { 1101 1114 /** 1102 1115 * A description for security scheme. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1103 1116 */ 1104 1117 description?: string; 1105 1118 } & ( 1106 - | { 1107 - /** 1108 - * **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"`, or `"cookie"`. 1109 - */ 1110 - in: 'cookie' | 'header' | 'query'; 1111 - /** 1112 - * **REQUIRED**. The name of the header, query or cookie parameter to be used. 1113 - */ 1114 - name: string; 1115 - /** 1116 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1117 - */ 1118 - type: 'apiKey'; 1119 - } 1120 - | { 1121 - /** 1122 - * A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes. 1123 - */ 1124 - bearerFormat?: string; 1125 - /** 1126 - * **REQUIRED**. The name of the HTTP Authentication scheme to be used in the {@link https://tools.ietf.org/html/rfc7235#section-5.1 Authorization header as defined in RFC7235}. The values used SHOULD be registered in the {@link https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml IANA Authentication Scheme registry}. The value is case-insensitive, as defined in {@link https://datatracker.ietf.org/doc/html/rfc7235#section-2.1 RFC7235}. 1127 - */ 1128 - scheme: string; 1129 - /** 1130 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1131 - */ 1132 - type: 'http'; 1133 - } 1134 - | { 1135 - /** 1136 - * **REQUIRED**. An object containing configuration information for the flow types supported. 1137 - */ 1138 - flows: OAuthFlowsObject; 1139 - /** 1140 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1141 - */ 1142 - type: 'oauth2'; 1143 - } 1144 - | { 1145 - /** 1146 - * **REQUIRED**. {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig Well-known URL} to discover the [[OpenID-Connect-Discovery]] {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata provider metadata}. 1147 - */ 1148 - openIdConnectUrl: string; 1149 - /** 1150 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1151 - */ 1152 - type: 'openIdConnect'; 1153 - } 1154 - ); 1119 + | { 1120 + /** 1121 + * **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"`, or `"cookie"`. 1122 + */ 1123 + in: 'cookie' | 'header' | 'query'; 1124 + /** 1125 + * **REQUIRED**. The name of the header, query or cookie parameter to be used. 1126 + */ 1127 + name: string; 1128 + /** 1129 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1130 + */ 1131 + type: 'apiKey'; 1132 + } 1133 + | { 1134 + /** 1135 + * A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes. 1136 + */ 1137 + bearerFormat?: string; 1138 + /** 1139 + * **REQUIRED**. The name of the HTTP Authentication scheme to be used in the {@link https://tools.ietf.org/html/rfc7235#section-5.1 Authorization header as defined in RFC7235}. The values used SHOULD be registered in the {@link https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml IANA Authentication Scheme registry}. The value is case-insensitive, as defined in {@link https://datatracker.ietf.org/doc/html/rfc7235#section-2.1 RFC7235}. 1140 + */ 1141 + scheme: string; 1142 + /** 1143 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1144 + */ 1145 + type: 'http'; 1146 + } 1147 + | { 1148 + /** 1149 + * **REQUIRED**. An object containing configuration information for the flow types supported. 1150 + */ 1151 + flows: OAuthFlowsObject; 1152 + /** 1153 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1154 + */ 1155 + type: 'oauth2'; 1156 + } 1157 + | { 1158 + /** 1159 + * **REQUIRED**. {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig Well-known URL} to discover the [[OpenID-Connect-Discovery]] {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata provider metadata}. 1160 + */ 1161 + openIdConnectUrl: string; 1162 + /** 1163 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`. 1164 + */ 1165 + type: 'openIdConnect'; 1166 + } 1167 + ); 1155 1168 1156 1169 /** 1157 1170 * An object representing a Server. ··· 1160 1173 * 1161 1174 * TODO: examples 1162 1175 */ 1163 - export interface ServerObject { 1176 + export interface ServerObject extends SpecificationExtensions { 1164 1177 /** 1165 1178 * An optional string describing the host designated by the URL. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1166 1179 */ ··· 1180 1193 * 1181 1194 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#specification-extensions Specification Extensions}. 1182 1195 */ 1183 - export interface ServerVariableObject { 1196 + export interface ServerVariableObject extends SpecificationExtensions { 1184 1197 /** 1185 1198 * **REQUIRED**. The default value to use for substitution, which SHALL be sent if an alternate value is _not_ supplied. If the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#server-variable-enum `enum`} is defined, the value SHOULD exist in the enum's values. Note that this behavior is different from the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema-object Schema Object}'s `default` keyword, which documents the receiver's behavior rather than inserting the value into the data. 1186 1199 */ ··· 1207 1220 * description: Pets operations 1208 1221 * ``` 1209 1222 */ 1210 - export interface TagObject { 1223 + export interface TagObject extends SpecificationExtensions { 1211 1224 /** 1212 1225 * A description for the tag. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1213 1226 */ ··· 1236 1249 * 1237 1250 * TODO: examples 1238 1251 */ 1239 - export interface XMLObject { 1252 + export interface XMLObject extends SpecificationExtensions { 1240 1253 /** 1241 1254 * Declares whether the property definition translates to an attribute instead of an element. Default value is `false`. 1242 1255 */
+5 -2
packages/openapi-ts/src/openApi/3.1.x/parser/index.ts
··· 121 121 parseServers({ context }); 122 122 123 123 for (const path in context.spec.paths) { 124 - const pathItem = context.spec.paths[path as keyof PathsObject]!; 124 + if (path.startsWith('x-')) continue; 125 + const pathItem = context.spec.paths[ 126 + path as keyof PathsObject 127 + ]! as PathItemObject; 125 128 126 129 const finalPathItem = pathItem.$ref 127 130 ? { ··· 145 148 servers: finalPathItem.servers, 146 149 summary: finalPathItem.summary, 147 150 }, 148 - path: path as keyof PathsObject, 151 + path: path as `/${string}`, 149 152 securitySchemesMap, 150 153 state, 151 154 };
+12 -2
packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
··· 6 6 7 7 import type { 8 8 OperationObject, 9 + ReferenceObject, 9 10 RequestBodyObject, 10 11 ResponseObject, 11 12 SecuritySchemeObject, 12 13 } from '../types/spec'; 13 14 import { contentToSchema, mediaTypeObjects } from './mediaType'; 14 15 import { paginationField } from './pagination'; 15 - import { schemaToIrSchema } from './schema'; 16 + import { parseExtensions, schemaToIrSchema } from './schema'; 16 17 17 18 interface Operation 18 19 extends Omit<OperationObject, 'parameters'>, ··· 74 75 operation, 75 76 }); 76 77 78 + parseExtensions({ 79 + source: operation, 80 + target: irOperation, 81 + }); 82 + 77 83 return irOperation; 78 84 }; 79 85 ··· 151 157 } 152 158 153 159 for (const name in operation.responses) { 160 + if (name.startsWith('x-')) continue; 161 + 154 162 if (!irOperation.responses) { 155 163 irOperation.responses = {}; 156 164 } 157 165 158 - const response = operation.responses[name]!; 166 + const response = operation.responses[name]! as 167 + | ResponseObject 168 + | ReferenceObject; 159 169 const responseObject = 160 170 '$ref' in response 161 171 ? context.resolveRef<ResponseObject>(response.$ref)
+6 -1
packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts
··· 9 9 } from '../types/spec'; 10 10 import { mediaTypeObjects } from './mediaType'; 11 11 import { paginationField } from './pagination'; 12 - import { schemaToIrSchema } from './schema'; 12 + import { parseExtensions, schemaToIrSchema } from './schema'; 13 13 14 14 /** 15 15 * Returns default parameter `allowReserved` based on value of `in`. ··· 165 165 if (parameter.required) { 166 166 irParameter.required = parameter.required; 167 167 } 168 + 169 + parseExtensions({ 170 + source: parameter, 171 + target: irParameter, 172 + }); 168 173 169 174 return irParameter; 170 175 };
+21
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
··· 449 449 return irSchema; 450 450 }; 451 451 452 + export const parseExtensions = ({ 453 + source, 454 + target, 455 + }: { 456 + source: object; 457 + target: object; 458 + }) => { 459 + for (const key in source) { 460 + if (key.startsWith('x-')) { 461 + (target as Record<string, unknown>)[key] = ( 462 + source as Record<string, unknown> 463 + )[key]; 464 + } 465 + } 466 + }; 467 + 452 468 const initIrSchema = ({ 453 469 schema, 454 470 }: { ··· 459 475 parseSchemaJsDoc({ 460 476 irSchema, 461 477 schema, 478 + }); 479 + 480 + parseExtensions({ 481 + source: schema, 482 + target: irSchema, 462 483 }); 463 484 464 485 return irSchema;
+3 -1
packages/openapi-ts/src/openApi/3.1.x/types/json-schema-draft-2020-12.d.ts
··· 1 1 import type { EnumExtensions } from '~/openApi/shared/types/openapi-spec-extensions'; 2 2 3 3 import type { MaybeArray } from '../../../types/utils'; 4 + import type { SpecificationExtensions } from './spec'; 4 5 import type { OpenApiSchemaExtensions } from './spec-extensions'; 5 6 6 7 // TODO: left out some keywords related to structuring a complex schema and declaring a dialect ··· 10 11 ObjectKeywords, 11 12 StringKeywords, 12 13 EnumExtensions, 13 - OpenApiSchemaExtensions { 14 + OpenApiSchemaExtensions, 15 + SpecificationExtensions { 14 16 /** 15 17 * The `$comment` {@link https://json-schema.org/learn/glossary#keyword keyword} is strictly intended for adding comments to a schema. Its value must always be a string. Unlike the annotations `title`, `description`, and `examples`, JSON schema {@link https://json-schema.org/learn/glossary#implementation implementations} aren't allowed to attach any meaning or behavior to it whatsoever, and may even strip them at any time. Therefore, they are useful for leaving notes to future editors of a JSON schema, but should not be used to communicate to users of the schema. 16 18 */
+97 -84
packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts
··· 1 1 import type { JsonSchemaDraft2020_12 } from './json-schema-draft-2020-12'; 2 2 3 3 /** 4 + * OpenAPI Specification Extensions. 5 + * 6 + * See {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}. 7 + */ 8 + export interface SpecificationExtensions { 9 + [extension: `x-${string}`]: unknown; 10 + } 11 + 12 + /** 4 13 * This is the root object of the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-document OpenAPI document}. 5 14 * 6 15 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}. 7 16 */ 8 - export interface OpenApiV3_1_X { 17 + export interface OpenApiV3_1_X extends SpecificationExtensions { 9 18 /** 10 19 * An element to hold various schemas for the document. 11 20 */ ··· 129 138 * description: callback successfully processed 130 139 * ``` 131 140 */ 132 - export interface CallbackObject { 141 + export interface CallbackObject extends SpecificationExtensions { 133 142 /** 134 143 * A Path Item Object, or a reference to one, used to define a callback request and expected responses. A {@link https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/callback-example.yaml complete example} is available. 135 144 */ 136 - [expression: string]: PathItemObject | ReferenceObject; 145 + [expression: string]: PathItemObject | ReferenceObject | unknown; 137 146 } 138 147 139 148 /** ··· 225 234 * read:pets: read your pets 226 235 * ``` 227 236 */ 228 - export interface ComponentsObject { 237 + export interface ComponentsObject extends SpecificationExtensions { 229 238 /** 230 239 * An object to hold reusable {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object Callback Objects}. 231 240 */ ··· 280 289 * email: support@example.com 281 290 * ``` 282 291 */ 283 - export interface ContactObject { 292 + export interface ContactObject extends SpecificationExtensions { 284 293 /** 285 294 * The email address of the contact person/organization. This MUST be in the form of an email address. 286 295 */ ··· 421 430 * 422 431 * will map to `Dog` because of the definition in the `mapping` element. 423 432 */ 424 - export interface DiscriminatorObject { 433 + export interface DiscriminatorObject extends SpecificationExtensions { 425 434 /** 426 435 * An object to hold mappings between payload values and schema names or references. 427 436 */ ··· 473 482 * type: integer 474 483 * ``` 475 484 */ 476 - export interface EncodingObject { 485 + export interface EncodingObject extends SpecificationExtensions { 477 486 /** 478 487 * Determines whether the parameter value SHOULD allow reserved characters, as defined by {@link https://tools.ietf.org/html/rfc3986#section-2.2 RFC3986} `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#encodingContentType `contentType`} (implicit or explicit) SHALL be ignored. 479 488 */ ··· 569 578 * $ref: '#/components/examples/confirmation-success' 570 579 * ``` 571 580 */ 572 - export interface ExampleObject { 581 + export interface ExampleObject extends SpecificationExtensions { 573 582 /** 574 583 * Long description for the example. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 575 584 */ ··· 599 608 * url: https://example.com 600 609 * ``` 601 610 */ 602 - export interface ExternalDocumentationObject { 611 + export interface ExternalDocumentationObject extends SpecificationExtensions { 603 612 /** 604 613 * A description of the target documentation. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 605 614 */ ··· 647 656 * version: 1.0.1 648 657 * ``` 649 658 */ 650 - export interface InfoObject { 659 + export interface InfoObject extends SpecificationExtensions { 651 660 /** 652 661 * The contact information for the exposed API. 653 662 */ ··· 689 698 * identifier: Apache-2.0 690 699 * ``` 691 700 */ 692 - export interface LicenseObject { 701 + export interface LicenseObject extends SpecificationExtensions { 693 702 /** 694 703 * An {@link https://spdx.org/licenses/ SPDX} license expression for the API. The `identifier` field is mutually exclusive of the `url` field. 695 704 */ ··· 851 860 * 852 861 * Runtime expressions preserve the type of the referenced value. Expressions can be embedded into string values by surrounding the expression with `{}` curly braces. 853 862 */ 854 - export interface LinkObject { 863 + export interface LinkObject extends SpecificationExtensions { 855 864 /** 856 865 * A description of the link. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 857 866 */ ··· 911 920 * $ref: "#/components/examples/frog-example" 912 921 * ``` 913 922 */ 914 - export interface MediaTypeObject { 923 + export interface MediaTypeObject extends SpecificationExtensions { 915 924 /** 916 925 * A map between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property. The encoding object SHALL only apply to `requestBody` objects when the media type is `multipart` or `application/x-www-form-urlencoded`. 917 926 */ ··· 953 962 * read:pets: read your pets 954 963 * ``` 955 964 */ 956 - export interface OAuthFlowObject { 965 + export interface OAuthFlowObject extends SpecificationExtensions { 957 966 /** 958 967 * **REQUIRED (`"implicit"`, `"authorizationCode"`)**. The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS. 959 968 */ ··· 977 986 * 978 987 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}. 979 988 */ 980 - export interface OAuthFlowsObject { 989 + export interface OAuthFlowsObject extends SpecificationExtensions { 981 990 /** 982 991 * Configuration for the OAuth Authorization Code flow. Previously called `accessCode` in OpenAPI 2.0. 983 992 */ ··· 1045 1054 * - read:pets 1046 1055 * ``` 1047 1056 */ 1048 - export interface OperationObject { 1057 + export interface OperationObject extends SpecificationExtensions { 1049 1058 /** 1050 1059 * A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object Callback Object} that describes a request that may be initiated by the API provider and the expected responses. 1051 1060 */ ··· 1193 1202 * type: number 1194 1203 * ``` 1195 1204 */ 1196 - export interface ParameterObject { 1205 + export interface ParameterObject extends SpecificationExtensions { 1197 1206 /** 1198 1207 * Sets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle `style`} is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision. 1199 1208 */ ··· 1296 1305 * style: simple 1297 1306 * ``` 1298 1307 */ 1299 - export interface PathItemObject { 1308 + export interface PathItemObject extends SpecificationExtensions { 1300 1309 /** 1301 1310 * Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object Path Item Object}. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relative-references-in-uris Relative References}. 1302 1311 */ ··· 1396 1405 * $ref: '#/components/schemas/pet' 1397 1406 * ``` 1398 1407 */ 1399 - export interface PathsObject { 1408 + export interface PathsObject extends SpecificationExtensions { 1400 1409 /** 1401 1410 * A relative path to an individual endpoint. The field name MUST begin with a forward slash (`/`). The path is **appended** (no relative URL resolution) to the expanded URL from the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-object `Server Object`}'s `url` field in order to construct the full URL. {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-templating Path templating} is allowed. When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it's up to the tooling to decide which one to use. 1402 1411 */ ··· 1501 1510 * type: string 1502 1511 * ``` 1503 1512 */ 1504 - export interface RequestBodyObject { 1513 + export interface RequestBodyObject extends SpecificationExtensions { 1505 1514 /** 1506 1515 * **REQUIRED**. The content of the request body. The key is a media type or {@link https://tools.ietf.org/html/rfc7231#appendix-D media type range} and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* 1507 1516 */ ··· 1577 1586 * description: object created 1578 1587 * ``` 1579 1588 */ 1580 - export interface ResponseObject { 1589 + export interface ResponseObject extends SpecificationExtensions { 1581 1590 /** 1582 1591 * A map containing descriptions of potential response payloads. The key is a media type or {@link https://datatracker.ietf.org/doc/html/rfc7231#appendix-D media type range} and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* 1583 1592 */ ··· 1625 1634 * $ref: '#/components/schemas/ErrorModel' 1626 1635 * ``` 1627 1636 */ 1628 - export interface ResponsesObject { 1637 + export interface ResponsesObject extends SpecificationExtensions { 1629 1638 /** 1630 1639 * Any {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#http-status-codes HTTP status code} can be used as the property name, but only one property per code, to describe the expected response for that HTTP status code. This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character `X`. For example, `2XX` represents all response codes between `[200-299]`. Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX`, and `5XX`. If a response is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code. 1631 1640 */ 1632 - [httpStatusCode: string]: ResponseObject | ReferenceObject | undefined; 1641 + [httpStatusCode: string]: 1642 + | ResponseObject 1643 + | ReferenceObject 1644 + | undefined 1645 + | unknown; 1633 1646 /** 1634 1647 * The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses. 1635 1648 */ ··· 1660 1673 * 1661 1674 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}, though as noted, additional properties MAY omit the `x-` prefix within this object. 1662 1675 */ 1663 - export type SchemaObject = JsonSchemaDraft2020_12; 1676 + export type SchemaObject = JsonSchemaDraft2020_12 & SpecificationExtensions; 1664 1677 1665 1678 /** 1666 1679 * Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsSecuritySchemes Security Schemes} under the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object Components Object}. ··· 1747 1760 * read:pets: read your pets 1748 1761 * ``` 1749 1762 */ 1750 - export type SecuritySchemeObject = { 1763 + export type SecuritySchemeObject = SpecificationExtensions & { 1751 1764 /** 1752 1765 * A description for security scheme. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1753 1766 */ 1754 1767 description?: string; 1755 1768 } & ( 1756 - | { 1757 - /** 1758 - * **REQUIRED**. The location of the API key. Valid values are "query", "header" or "cookie". 1759 - */ 1760 - in: 'cookie' | 'header' | 'query'; 1761 - /** 1762 - * **REQUIRED**. The name of the header, query or cookie parameter to be used. 1763 - */ 1764 - name: string; 1765 - /** 1766 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1767 - */ 1768 - type: 'apiKey'; 1769 - } 1770 - | { 1771 - /** 1772 - * A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes. 1773 - */ 1774 - bearerFormat?: string; 1775 - /** 1776 - * **REQUIRED**. The name of the HTTP Authorization scheme to be used in the {@link https://tools.ietf.org/html/rfc7235#section-5.1 Authorization header as defined in RFC7235}. The values used SHOULD be registered in the {@link https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml IANA Authentication Scheme registry}. 1777 - */ 1778 - scheme: string; 1779 - /** 1780 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1781 - */ 1782 - type: 'http'; 1783 - } 1784 - | { 1785 - /** 1786 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1787 - */ 1788 - type: 'mutualTLS'; 1789 - } 1790 - | { 1791 - /** 1792 - * **REQUIRED**. An object containing configuration information for the flow types supported. 1793 - */ 1794 - flows: OAuthFlowsObject; 1795 - /** 1796 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1797 - */ 1798 - type: 'oauth2'; 1799 - } 1800 - | { 1801 - /** 1802 - * **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL. The OpenID Connect standard requires the use of TLS. 1803 - */ 1804 - openIdConnectUrl: string; 1805 - /** 1806 - * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1807 - */ 1808 - type: 'openIdConnect'; 1809 - } 1810 - ); 1769 + | { 1770 + /** 1771 + * **REQUIRED**. The location of the API key. Valid values are "query", "header" or "cookie". 1772 + */ 1773 + in: 'cookie' | 'header' | 'query'; 1774 + /** 1775 + * **REQUIRED**. The name of the header, query or cookie parameter to be used. 1776 + */ 1777 + name: string; 1778 + /** 1779 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1780 + */ 1781 + type: 'apiKey'; 1782 + } 1783 + | { 1784 + /** 1785 + * A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes. 1786 + */ 1787 + bearerFormat?: string; 1788 + /** 1789 + * **REQUIRED**. The name of the HTTP Authorization scheme to be used in the {@link https://tools.ietf.org/html/rfc7235#section-5.1 Authorization header as defined in RFC7235}. The values used SHOULD be registered in the {@link https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml IANA Authentication Scheme registry}. 1790 + */ 1791 + scheme: string; 1792 + /** 1793 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1794 + */ 1795 + type: 'http'; 1796 + } 1797 + | { 1798 + /** 1799 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1800 + */ 1801 + type: 'mutualTLS'; 1802 + } 1803 + | { 1804 + /** 1805 + * **REQUIRED**. An object containing configuration information for the flow types supported. 1806 + */ 1807 + flows: OAuthFlowsObject; 1808 + /** 1809 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1810 + */ 1811 + type: 'oauth2'; 1812 + } 1813 + | { 1814 + /** 1815 + * **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL. The OpenID Connect standard requires the use of TLS. 1816 + */ 1817 + openIdConnectUrl: string; 1818 + /** 1819 + * **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`. 1820 + */ 1821 + type: 'openIdConnect'; 1822 + } 1823 + ); 1811 1824 1812 1825 /** 1813 1826 * An object representing a Server. ··· 1820 1833 * description: Development server 1821 1834 * ``` 1822 1835 */ 1823 - export interface ServerObject { 1836 + export interface ServerObject extends SpecificationExtensions { 1824 1837 /** 1825 1838 * An optional string describing the host designated by the URL. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1826 1839 */ ··· 1840 1853 * 1841 1854 * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}. 1842 1855 */ 1843 - export interface ServerVariableObject { 1856 + export interface ServerVariableObject extends SpecificationExtensions { 1844 1857 /** 1845 1858 * **REQUIRED**. The default value to use for substitution, which SHALL be sent if an alternate value is _not_ supplied. Note this behavior is different than the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object Schema Object's} treatment of default values, because in those cases parameter values are optional. If the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverVariableEnum `enum`} is defined, the value MUST exist in the enum's values. 1846 1859 */ ··· 1866 1879 * description: Pets operations 1867 1880 * ``` 1868 1881 */ 1869 - export interface TagObject { 1882 + export interface TagObject extends SpecificationExtensions { 1870 1883 /** 1871 1884 * A description for the tag. {@link https://spec.commonmark.org/ CommonMark syntax} MAY be used for rich text representation. 1872 1885 */ ··· 2073 2086 * </aliens> 2074 2087 * ``` 2075 2088 */ 2076 - export interface XMLObject { 2089 + export interface XMLObject extends SpecificationExtensions { 2077 2090 /** 2078 2091 * Declares whether the property definition translates to an attribute instead of an element. Default value is `false`. 2079 2092 */
+1 -1
packages/openapi-ts/src/openApi/shared/utils/patch.ts
··· 77 77 if (!schema || typeof schema !== 'object') continue; 78 78 79 79 const patchFn = patchOptions.schemas[key]!; 80 - patchFn(schema); 80 + patchFn(schema as Parameters<typeof patchFn>[0]); 81 81 } 82 82 } 83 83
+2 -2
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts
··· 137 137 plugin, 138 138 schema: item, 139 139 }), 140 - ) as 140 + ) as unknown as 141 141 | OpenApiV3_0_XTypes['SchemaObject'] 142 142 | OpenApiV3_0_XTypes['ReferenceObject']; 143 143 } ··· 235 235 plugin, 236 236 schema: item, 237 237 }), 238 - ) as OpenApiV3_1_XTypes['SchemaObject']; 238 + ) as unknown as OpenApiV3_1_XTypes['SchemaObject']; 239 239 } 240 240 241 241 const schema = structuredClone(_schema);