From 0f85cc4eb06336b7f2238fa1a06a82876d1869a8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 22:21:59 +0000 Subject: [PATCH] fix: Correct extension field type handling per review feedback - Changed parseExtensions to use Record instead of any - Added type assertions at call sites for type safety - Restored SpecificationExtensions to CallbackObject, PathsObject, ResponsesObject - Kept PathsObject with [path: /${string}] template literal type - Extended index signatures with | unknown to satisfy TypeScript Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com> --- .../src/openApi/2.0.x/parser/operation.ts | 4 ++-- .../src/openApi/2.0.x/parser/parameter.ts | 4 ++-- .../src/openApi/2.0.x/parser/schema.ts | 8 ++++---- .../src/openApi/3.0.x/parser/operation.ts | 4 ++-- .../src/openApi/3.0.x/parser/parameter.ts | 4 ++-- .../src/openApi/3.0.x/parser/schema.ts | 8 ++++---- .../openapi-ts/src/openApi/3.0.x/types/spec.d.ts | 16 ++++++++++------ .../src/openApi/3.1.x/parser/operation.ts | 4 ++-- .../src/openApi/3.1.x/parser/parameter.ts | 4 ++-- .../src/openApi/3.1.x/parser/schema.ts | 8 ++++---- .../openapi-ts/src/openApi/3.1.x/types/spec.d.ts | 16 ++++++++++------ 11 files changed, 44 insertions(+), 36 deletions(-) diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts index 1764e5da8..52cc08d4f 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts @@ -78,8 +78,8 @@ const initIrOperation = ({ }); parseExtensions({ - source: operation, - target: irOperation, + source: operation as Record, + target: irOperation as Record, }); return irOperation; diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts index fb09fc5fa..93d9cd940 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts @@ -166,8 +166,8 @@ const parameterToIrParameter = ({ } parseExtensions({ - source: parameter, - target: irParameter, + source: parameter as Record, + target: irParameter as Record, }); return irParameter; diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts index 46db6bb8c..aa7b8c58f 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts @@ -274,8 +274,8 @@ export const parseExtensions = ({ source, target, }: { - source: any; - target: any; + source: Record; + target: Record; }) => { for (const key in source) { if (key.startsWith('x-')) { @@ -297,8 +297,8 @@ const initIrSchema = ({ }); parseExtensions({ - source: schema, - target: irSchema, + source: schema as Record, + target: irSchema as Record, }); return irSchema; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts index 2aff14e46..c8cd4349c 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts @@ -75,8 +75,8 @@ const initIrOperation = ({ }); parseExtensions({ - source: operation, - target: irOperation, + source: operation as Record, + target: irOperation as Record, }); return irOperation; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts index 30b2ec328..a82e89647 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts @@ -174,8 +174,8 @@ const parameterToIrParameter = ({ } parseExtensions({ - source: parameter, - target: irParameter, + source: parameter as Record, + target: irParameter as Record, }); return irParameter; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts index 58a17a69e..c22605ee2 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts @@ -280,8 +280,8 @@ export const parseExtensions = ({ source, target, }: { - source: any; - target: any; + source: Record; + target: Record; }) => { for (const key in source) { if (key.startsWith('x-')) { @@ -303,8 +303,8 @@ const initIrSchema = ({ }); parseExtensions({ - source: schema, - target: irSchema, + source: schema as Record, + target: irSchema as Record, }); return irSchema; diff --git a/packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts b/packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts index 62bd35d3f..999909032 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts @@ -55,11 +55,11 @@ export interface OpenApiV3_0_X extends SpecificationExtensions { * * TODO: examples */ -export interface CallbackObject { +export interface CallbackObject extends SpecificationExtensions { /** * 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. */ - [expression: string]: PathItemObject | ReferenceObject; + [expression: string]: PathItemObject | ReferenceObject | unknown; } /** @@ -688,11 +688,11 @@ export interface PathItemObject extends SpecificationExtensions { * * TODO: examples */ -export interface PathsObject { +export interface PathsObject extends SpecificationExtensions { /** * 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. */ - [path: string]: PathItemObject; + [path: `/${string}`]: PathItemObject | unknown; } /** @@ -790,11 +790,15 @@ export interface ResponseObject extends SpecificationExtensions { * * TODO: examples */ -export interface ResponsesObject { +export interface ResponsesObject extends SpecificationExtensions { /** * 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. */ - [httpStatusCode: string]: ResponseObject | ReferenceObject | undefined; + [httpStatusCode: string]: + | ResponseObject + | ReferenceObject + | undefined + | unknown; /** * 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. */ diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts index 92e69f0bf..c9594abd6 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts @@ -75,8 +75,8 @@ const initIrOperation = ({ }); parseExtensions({ - source: operation, - target: irOperation, + source: operation as Record, + target: irOperation as Record, }); return irOperation; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts index 2850e9ae9..f69623b45 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts @@ -167,8 +167,8 @@ const parameterToIrParameter = ({ } parseExtensions({ - source: parameter, - target: irParameter, + source: parameter as Record, + target: irParameter as Record, }); return irParameter; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts index e6cf2b9b4..911a6e8ea 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts @@ -361,8 +361,8 @@ export const parseExtensions = ({ source, target, }: { - source: any; - target: any; + source: Record; + target: Record; }) => { for (const key in source) { if (key.startsWith('x-')) { @@ -384,8 +384,8 @@ const initIrSchema = ({ }); parseExtensions({ - source: schema, - target: irSchema, + source: schema as Record, + target: irSchema as Record, }); return irSchema; diff --git a/packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts b/packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts index 24c8781b2..048470a95 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts @@ -137,11 +137,11 @@ export interface OpenApiV3_1_X extends SpecificationExtensions { * description: callback successfully processed * ``` */ -export interface CallbackObject { +export interface CallbackObject extends SpecificationExtensions { /** * 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. */ - [expression: string]: PathItemObject | ReferenceObject; + [expression: string]: PathItemObject | ReferenceObject | unknown; } /** @@ -1404,11 +1404,11 @@ export interface PathItemObject extends SpecificationExtensions { * $ref: '#/components/schemas/pet' * ``` */ -export interface PathsObject { +export interface PathsObject extends SpecificationExtensions { /** * 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. */ - [path: string]: PathItemObject; + [path: `/${string}`]: PathItemObject | unknown; } /** @@ -1633,11 +1633,15 @@ export interface ResponseObject extends SpecificationExtensions { * $ref: '#/components/schemas/ErrorModel' * ``` */ -export interface ResponsesObject { +export interface ResponsesObject extends SpecificationExtensions { /** * 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. */ - [httpStatusCode: string]: ResponseObject | ReferenceObject | undefined; + [httpStatusCode: string]: + | ResponseObject + | ReferenceObject + | undefined + | unknown; /** * The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses. */ -- 2.51.2