Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error response schemas #177

Merged
merged 1 commit into from
Aug 26, 2024
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
141 changes: 106 additions & 35 deletions apps/example/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
}
}
},
"400": {
"description": "Invalid request body.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/MessageWithErrors" }
}
}
},
"500": {
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -69,7 +77,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -94,7 +102,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -119,7 +127,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -165,7 +173,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -197,7 +205,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -228,10 +236,21 @@
}
},
"400": {
"description": "An unknown error occurred, trying again might help.",
"description": "Error response.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": {
"oneOf": [
{
"description": "Invalid request body.",
"$ref": "#/components/schemas/MessageWithErrors"
},
{
"description": "An unknown error occurred, trying again might help.",
"$ref": "#/components/schemas/ErrorMessage"
}
]
}
}
}
}
Expand Down Expand Up @@ -265,7 +284,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -299,7 +318,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -324,7 +343,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -349,7 +368,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -390,7 +409,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -425,7 +444,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -466,7 +485,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -505,11 +524,19 @@
}
}
},
"400": {
"description": "Invalid request body.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/MessageWithErrors" }
}
}
},
"500": {
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -544,7 +571,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -569,7 +596,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -594,7 +621,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -640,7 +667,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -672,7 +699,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -703,10 +730,21 @@
}
},
"400": {
"description": "An unknown error occurred, trying again might help.",
"description": "Error response.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": {
"oneOf": [
{
"description": "Invalid request body.",
"$ref": "#/components/schemas/MessageWithErrors"
},
{
"description": "An unknown error occurred, trying again might help.",
"$ref": "#/components/schemas/ErrorMessage"
}
]
}
}
}
}
Expand Down Expand Up @@ -740,7 +778,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -774,7 +812,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -799,7 +837,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand All @@ -824,7 +862,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -865,7 +903,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -900,7 +938,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -941,7 +979,7 @@
"description": "An unknown error occurred, trying again might help.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UnexpectedError" }
"schema": { "$ref": "#/components/schemas/ErrorMessage" }
}
}
}
Expand Down Expand Up @@ -1001,6 +1039,11 @@
"additionalProperties": false,
"description": "TODO deleted message."
},
"ErrorMessage": {
"type": "object",
"properties": { "message": { "type": "string" } },
"additionalProperties": false
},
"FormDataMultipartRequestBody": {
"description": "Test form description.",
"type": "object",
Expand Down Expand Up @@ -1113,6 +1156,39 @@
},
"description": "List of TODOs."
},
"MessageWithErrors": {
"type": "object",
"properties": {
"message": { "type": "string" },
"errors": {
"type": "array",
"items": {
"type": "object",
"required": ["code", "path", "message"],
"properties": {
"code": {
"type": "string",
"description": "Discriminator field for the Zod issue type."
},
"path": {
"type": "array",
"items": {
"oneOf": [{ "type": "string" }, { "type": "number" }]
},
"description": "Path to the error in the validated object, represented as an array of strings and/or numbers."
},
"message": {
"type": "string",
"description": "Human-readable message describing the validation error."
}
},
"additionalProperties": true
}
}
},
"required": ["message"],
"additionalProperties": false
},
"MultipartFormData200ResponseBody": {
"description": "File response.",
"type": "string",
Expand All @@ -1127,11 +1203,6 @@
}
},
"RouteWithExternalDep200ResponseBody": { "type": "string" },
"UnexpectedError": {
"type": "object",
"properties": { "message": { "type": "string" } },
"additionalProperties": false
},
"UrlEncodedFormData200ResponseBody": {
"type": "object",
"properties": { "text": { "type": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion packages/next-rest-framework/src/app-router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const route = <T extends Record<string, RouteOperationDefinition>>(
if (contentTypeSchema && contentType !== contentTypeSchema) {
return NextResponse.json(
{ message: DEFAULT_ERRORS.invalidMediaType },
{ status: 415 }
{ status: 415, headers: { Allow: contentTypeSchema } }
);
}

Expand Down
Loading
Loading