Skip to content

Commit

Permalink
Merge pull request #1171 from samchon/feat/examples
Browse files Browse the repository at this point in the history
Fix `TypedException.IProps.examples` type.
  • Loading branch information
samchon authored Dec 27, 2024
2 parents 91f2979 + f4d797a commit c76cf0e
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 19 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand All @@ -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",
Expand Down
42 changes: 40 additions & 2 deletions packages/core/src/decorators/TypedException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,48 @@ export function TypedException<T>(...args: any[]): MethodDecorator {
};
}
export namespace TypedException {
/**
* Properties for the exception.
*/
export interface IProps<T> {
/**
* 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<string, IExample<T>> | undefined;
}

/**
* Metadata collected in the {@link IProps.examples}.
*/
export interface IExample<T> {
/**
* Summary of the example.
*/
summary?: string | undefined;

/**
* Description of the example.
*/
description?: string | undefined;
example?: T;
examples?: Record<string, T>;

/**
* Value of the example.
*/
value: T;
}
}
2 changes: 1 addition & 1 deletion packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions test/features/exception/src/controllers/ExceptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<INotFound>(404, "unable to find the matched section")
@TypedException<IUnprocessibleEntity>(428)
Expand Down
31 changes: 31 additions & 0 deletions test/features/exception/src/test/features/test_swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
});
};
26 changes: 26 additions & 0 deletions test/features/exception/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
Expand Down

0 comments on commit c76cf0e

Please sign in to comment.