From f4d797ab9f59baffac00e91a380d6314977b43d9 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 27 Dec 2024 12:14:06 +0900 Subject: [PATCH] Fix `TypedException.IProps.examples` type. --- benchmark/package.json | 2 +- package.json | 2 +- packages/benchmark/package.json | 2 +- packages/core/package.json | 6 +-- .../core/src/decorators/TypedException.ts | 42 ++++++++++++++++++- packages/e2e/package.json | 2 +- packages/editor/package.json | 4 +- packages/fetcher/package.json | 6 +-- packages/migrate/package.json | 4 +- packages/sdk/package.json | 6 +-- .../src/controllers/ExceptionController.ts | 26 ++++++++++++ .../src/test/features/test_swagger.ts | 31 ++++++++++++++ test/features/exception/swagger.json | 26 ++++++++++++ 13 files changed, 140 insertions(+), 19 deletions(-) diff --git a/benchmark/package.json b/benchmark/package.json index b5a8d3f9d..bf50ea41f 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -42,7 +42,7 @@ "reflect-metadata": "^0.2.2", "tgrid": "^1.1.0", "tstl": "^3.0.0", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "devDependencies": { "@types/autocannon": "^7.9.0", diff --git a/package.json b/package.json index 62ee470ad..f31d81700 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@nestia/station", - "version": "4.5.1", + "version": "4.5.2", "description": "Nestia station", "scripts": { "build": "node deploy build", diff --git a/packages/benchmark/package.json b/packages/benchmark/package.json index a6a5bbe6d..b61d05d2b 100644 --- a/packages/benchmark/package.json +++ b/packages/benchmark/package.json @@ -34,7 +34,7 @@ "ts-patch": "^3.3.0", "typescript": "~5.7.2", "typescript-transform-paths": "^3.4.7", - "typia": "^7.5.0", + "typia": "^7.5.1", "uuid": "^10.0.0" }, "dependencies": { diff --git a/packages/core/package.json b/packages/core/package.json index eeb240256..d097365b9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -39,7 +39,7 @@ "@nestia/fetcher": "workspace:^", "@nestjs/common": ">=7.0.1", "@nestjs/core": ">=7.0.1", - "@samchon/openapi": "^2.3.0", + "@samchon/openapi": "^2.3.1", "detect-ts-node": "^1.0.5", "get-function-location": "^2.0.0", "glob": "^7.2.0", @@ -48,7 +48,7 @@ "reflect-metadata": ">=0.1.12", "rxjs": ">=6.0.3", "tgrid": "^1.1.0", - "typia": "^7.5.0", + "typia": "^7.5.1", "ws": "^7.5.3" }, "peerDependencies": { @@ -57,7 +57,7 @@ "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12", "rxjs": ">=6.0.3", - "typia": ">=7.5.0 <8.0.0" + "typia": ">=7.5.1 <8.0.0" }, "devDependencies": { "@nestjs/common": "^10.4.13", diff --git a/packages/core/src/decorators/TypedException.ts b/packages/core/src/decorators/TypedException.ts index 9304c8965..49dfa436a 100644 --- a/packages/core/src/decorators/TypedException.ts +++ b/packages/core/src/decorators/TypedException.ts @@ -119,10 +119,48 @@ export function TypedException(...args: any[]): MethodDecorator { }; } export namespace TypedException { + /** + * Properties for the exception. + */ export interface IProps { + /** + * Status number or pattern like "2XX", "3XX", "4XX", "5XX". + */ status: number | "2XX" | "3XX" | "4XX" | "5XX"; + + /** + * Description about the exception. + */ + description?: string | undefined; + + /** + * Example value. + */ + example?: T | undefined; + + /** + * Collection of examples for the exception. + */ + examples?: Record> | undefined; + } + + /** + * Metadata collected in the {@link IProps.examples}. + */ + export interface IExample { + /** + * Summary of the example. + */ + summary?: string | undefined; + + /** + * Description of the example. + */ description?: string | undefined; - example?: T; - examples?: Record; + + /** + * Value of the example. + */ + value: T; } } diff --git a/packages/e2e/package.json b/packages/e2e/package.json index c63729e8c..76a6453cc 100644 --- a/packages/e2e/package.json +++ b/packages/e2e/package.json @@ -41,7 +41,7 @@ "ts-patch": "^3.3.0", "typescript": "~5.7.2", "typescript-transform-paths": "^3.4.7", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "files": [ "lib", diff --git a/packages/editor/package.json b/packages/editor/package.json index b5a2a6d6a..344afd7ed 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -35,12 +35,12 @@ "dependencies": { "@mui/material": "^5.15.6", "@nestia/migrate": "workspace:^", - "@samchon/openapi": "^2.3.0", + "@samchon/openapi": "^2.3.1", "@stackblitz/sdk": "^1.11.0", "js-yaml": "^4.1.0", "prettier": "3.3.3", "react-mui-fileuploader": "^0.5.2", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "devDependencies": { "@eslint/js": "^9.13.0", diff --git a/packages/fetcher/package.json b/packages/fetcher/package.json index 3605b9d83..d588d5382 100644 --- a/packages/fetcher/package.json +++ b/packages/fetcher/package.json @@ -26,8 +26,8 @@ }, "homepage": "https://nestia.io", "dependencies": { - "@samchon/openapi": "^2.3.0", - "typia": "^7.5.0" + "@samchon/openapi": "^2.3.1", + "typia": "^7.5.1" }, "peerDependencies": { "typescript": ">= 4.8.0" @@ -38,7 +38,7 @@ "@typescript-eslint/parser": "^5.46.1", "rimraf": "^3.0.2", "typescript": "~5.7.2", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "files": [ "README.md", diff --git a/packages/migrate/package.json b/packages/migrate/package.json index 89940a595..9d94e46af 100644 --- a/packages/migrate/package.json +++ b/packages/migrate/package.json @@ -72,13 +72,13 @@ }, "dependencies": { "@nestia/sdk": "workspace:^", - "@samchon/openapi": "^2.3.0", + "@samchon/openapi": "^2.3.1", "commander": "10.0.0", "inquirer": "8.2.5", "prettier": "^3.2.5", "tstl": "^3.0.0", "typescript": "~5.7.2", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "files": [ "lib", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index aa5ec040d..861f9cd57 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -34,7 +34,7 @@ "dependencies": { "@nestia/core": "workspace:^", "@nestia/fetcher": "workspace:^", - "@samchon/openapi": "^2.3.0", + "@samchon/openapi": "^2.3.1", "cli": "^1.0.1", "get-function-location": "^2.0.0", "glob": "^7.2.0", @@ -44,7 +44,7 @@ "tsconfck": "^2.1.2", "tsconfig-paths": "^4.1.1", "tstl": "^3.0.0", - "typia": "^7.5.0" + "typia": "^7.5.1" }, "peerDependencies": { "@nestia/core": ">=4.5.0-dev.20241218-2", @@ -53,7 +53,7 @@ "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12", "ts-node": ">=10.6.0", - "typia": ">=7.5.0 <8.0.0" + "typia": ">=7.5.1 <8.0.0" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", diff --git a/test/features/exception/src/controllers/ExceptionController.ts b/test/features/exception/src/controllers/ExceptionController.ts index 6766dab1c..5607b4975 100644 --- a/test/features/exception/src/controllers/ExceptionController.ts +++ b/test/features/exception/src/controllers/ExceptionController.ts @@ -27,6 +27,32 @@ export class ExceptionController { value: 123, message: "invalid type", }, + examples: { + title: { + summary: "title", + description: "Wrong type of the title", + value: { + name: "BadRequestException", + method: "TypedBody", + path: "$input.title", + expected: "string", + value: 123, + message: "invalid type", + }, + }, + content: { + summary: "content", + description: "content of the article", + value: { + name: "BadRequestException", + method: "TypedBody", + path: "$input.title", + expected: "string", + value: 123, + message: "invalid type", + }, + }, + }, }) @TypedException(404, "unable to find the matched section") @TypedException(428) diff --git a/test/features/exception/src/test/features/test_swagger.ts b/test/features/exception/src/test/features/test_swagger.ts index f0f14c5ce..694126417 100644 --- a/test/features/exception/src/test/features/test_swagger.ts +++ b/test/features/exception/src/test/features/test_swagger.ts @@ -25,4 +25,35 @@ export const test_swagger = async () => { { $ref: "#/components/schemas/IExceptional.Everything" }, ], }); + + TestValidator.equals("examples")( + content.paths["/exception/{section}/typed"].post.responses[400].content[ + "application/json" + ].examples, + )({ + title: { + summary: "title", + description: "Wrong type of the title", + value: { + name: "BadRequestException", + method: "TypedBody", + path: "$input.title", + expected: "string", + value: 123, + message: "invalid type", + }, + }, + content: { + summary: "content", + description: "content of the article", + value: { + name: "BadRequestException", + method: "TypedBody", + path: "$input.title", + expected: "string", + value: 123, + message: "invalid type", + }, + }, + }); }; diff --git a/test/features/exception/swagger.json b/test/features/exception/swagger.json index abb84d506..d3d4c2e8c 100644 --- a/test/features/exception/swagger.json +++ b/test/features/exception/swagger.json @@ -63,6 +63,32 @@ "expected": "string", "value": 123, "message": "invalid type" + }, + "examples": { + "title": { + "summary": "title", + "description": "Wrong type of the title", + "value": { + "name": "BadRequestException", + "method": "TypedBody", + "path": "$input.title", + "expected": "string", + "value": 123, + "message": "invalid type" + } + }, + "content": { + "summary": "content", + "description": "content of the article", + "value": { + "name": "BadRequestException", + "method": "TypedBody", + "path": "$input.title", + "expected": "string", + "value": 123, + "message": "invalid type" + } + } } } }