Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/true-weeks-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@openapi-qraft/test-fixtures': patch
'@openapi-qraft/plugin': patch
---

Add support for responses with `$ref` specification.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ export interface components {
url: string;
};
};
responses: never;
responses: {
/** @description Unexpected error */
DefaultErrorSchemaResponse: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
};
parameters: {
IdIn: string[];
/** @example 2023-06-04 */
Expand Down Expand Up @@ -262,15 +272,7 @@ export interface operations {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
/** @description Unexpected error */
default: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
default: components["responses"]["DefaultErrorSchemaResponse"];
};
};
get_approval_policies_id: {
Expand Down Expand Up @@ -514,15 +516,7 @@ export interface operations {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
/** @description Internal Server Error */
default: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
default: components["responses"]["DefaultErrorSchemaResponse"];
};
};
post_files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ export interface components {
url: string;
};
};
responses: never;
responses: {
/** @description Unexpected error */
DefaultErrorSchemaResponse: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
};
parameters: {
IdIn: string[];
/** @example 2023-06-04 */
Expand Down Expand Up @@ -160,15 +170,7 @@ export interface operations {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
/** @description Internal Server Error */
default: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
default: components["responses"]["DefaultErrorSchemaResponse"];
};
};
post_files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ export interface components {
url: string;
};
};
responses: never;
responses: {
/** @description Unexpected error */
DefaultErrorSchemaResponse: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
};
parameters: {
IdIn: string[];
/** @example 2023-06-04 */
Expand Down Expand Up @@ -160,15 +170,7 @@ export interface operations {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
/** @description Internal Server Error */
default: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
default: components["responses"]["DefaultErrorSchemaResponse"];
};
};
post_files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,17 @@ export interface components {
url: string;
};
};
responses: never;
responses: {
/** @description Unexpected error */
DefaultErrorSchemaResponse: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
};
parameters: {
IdIn: string[];
/** @example 2023-06-04 */
Expand Down Expand Up @@ -197,15 +207,7 @@ export interface operations {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
/** @description Internal Server Error */
default: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorSchemaResponse"];
};
};
default: components["responses"]["DefaultErrorSchemaResponse"];
};
};
post_files: {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin/src/lib/open-api/OpenAPISchemaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type OpenAPISchemaType = {
};
responses: {
[statusCode in number | 'default']: {
description: string;
$ref?: string;
description?: string;
content?: {
[contentType: string]:
| {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin/src/lib/open-api/getServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export const getServices = (
>
>(
(acc, [statusCode, response]) => {
if (response.$ref) {
response = resolveDocumentLocalRef(
response.$ref,
openApiJson
) as typeof response;
}

const statusType =
statusCode !== 'default' && // See "default" response https://swagger.io/docs/specification/describing-responses/#default
Number(statusCode) < 400
Expand Down
24 changes: 12 additions & 12 deletions packages/test-fixtures/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@
}
},
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorSchemaResponse" }
}
}
"$ref": "#/components/responses/DefaultErrorSchemaResponse"
}
},
"security": [{ "userToken": [] }, { "partnerToken": [] }]
Expand Down Expand Up @@ -493,12 +488,7 @@
}
},
"default": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorSchemaResponse" }
}
}
"$ref": "#/components/responses/DefaultErrorSchemaResponse"
}
},
"security": [{ "HTTPBearer": [] }]
Expand Down Expand Up @@ -881,6 +871,16 @@
}
}
}
},
"responses": {
"DefaultErrorSchemaResponse": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorSchemaResponse" }
}
}
}
}
}
}
Loading