Skip to content

Commit

Permalink
Merge pull request #549 from samchon/features/TypedException
Browse files Browse the repository at this point in the history
Complement #540 - `ISwaggerRoute.IResponseBody.description` is required.
  • Loading branch information
samchon authored Aug 17, 2023
2 parents 6bdc102 + 2cfc470 commit 45ad1b5
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 80 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^1.6.4",
"@nestia/core": "^1.6.5",
"typia": "^4.2.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion deploy/latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ npm install --save typia@latest
npm install --save-dev @nestia/core@latest
npm install --save-dev @nestia/fetcher@latest
npm run build
npm publish --access public --tag latest
npm publish --access public --tag latest
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"inquirer": "^8.2.5"
},
"devDependencies": {
"@nestia/core": "^1.6.4",
"@nestia/sdk": "^1.6.4",
"@nestia/core": "^1.6.5",
"@nestia/sdk": "^1.6.5",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/inquirer": "^9.0.3",
"@types/node": "^18.11.16",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "1.6.4",
"version": "1.6.5",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^1.6.4",
"@nestia/fetcher": "^1.6.5",
"@nestjs/common": ">= 7.0.1",
"@nestjs/core": ">= 7.0.1",
"@nestjs/platform-express": ">= 7.0.1",
Expand All @@ -47,7 +47,7 @@
"typia": "^4.2.3"
},
"peerDependencies": {
"@nestia/fetcher": ">= 1.6.4",
"@nestia/fetcher": ">= 1.6.5",
"@nestjs/common": ">= 7.0.1",
"@nestjs/core": ">= 7.0.1",
"@nestjs/platform-express": ">= 7.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/fetcher",
"version": "1.6.4",
"version": "1.6.5",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/migrate",
"version": "0.2.11",
"version": "0.2.12",
"description": "Migration program from swagger to NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -30,8 +30,8 @@
},
"homepage": "https://github.com/samchon/nestia#readme",
"devDependencies": {
"@nestia/core": "^1.6.4",
"@nestia/fetcher": "^1.6.4",
"@nestia/core": "^1.6.5",
"@nestia/fetcher": "^1.6.5",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/node": "^20.3.3",
"prettier": "^2.8.8",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "1.6.4",
"version": "1.6.5",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^1.6.4",
"@nestia/fetcher": "^1.6.5",
"cli": "^1.0.1",
"glob": "^7.2.0",
"path-to-regexp": "^6.2.1",
Expand All @@ -47,7 +47,7 @@
"typia": "^4.2.3"
},
"peerDependencies": {
"@nestia/fetcher": ">= 1.6.4",
"@nestia/fetcher": ">= 1.6.5",
"@nestjs/common": ">= 7.0.1",
"@nestjs/core": ">= 7.0.1",
"reflect-metadata": ">= 0.1.12",
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/generates/SwaggerGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export namespace SwaggerGenerator {
);
if (schema !== null)
output[status] = {
description: exp.description,
description: exp.description ?? "",
content: {
"application/json": { schema },
},
Expand Down Expand Up @@ -610,11 +610,11 @@ export namespace SwaggerGenerator {
const description: string | undefined =
elements.length === 1 ? undefined : elements.slice(1).join(" ");
const oldbie = output[status];
if (oldbie !== undefined && oldbie.description === undefined)
if (description && oldbie !== undefined)
oldbie.description = description;
else if (oldbie === undefined)
output[status] = {
description,
description: description ?? "",
content: {
"application/json": {
schema: {},
Expand Down Expand Up @@ -651,7 +651,7 @@ export namespace SwaggerGenerator {
? `${warning.get(!!description).get("response", route.method)}${
description ?? ""
}`
: description,
: description ?? "",
content:
schema === null || route.output.name === "void"
? undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export namespace SdkFunctionProgrammer {
)
continue;
comments.push(
value.description
value.description?.length
? `@throws ${key} ${value.description.split("\n")[0]}`
: `@throws ${key}`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/structures/ISwaggerRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export namespace ISwaggerRoute {
export type IResponseBody = Record<
string,
{
description?: string;
description: string;
content?: IContent;
"x-nestia-encrypted"?: boolean;
}
Expand Down
1 change: 0 additions & 1 deletion test/features/body-manual-assert/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand Down
1 change: 0 additions & 1 deletion test/features/body-manual-is/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand Down
1 change: 0 additions & 1 deletion test/features/body-manual-validate/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand Down
6 changes: 3 additions & 3 deletions test/features/distribute-assert/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:sdk": "rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api",
"compile": "rimraf lib && tsc",
"deploy": "npm run build && npm publish",
"prepare": "ts-patch install"
"postinstall": "ts-patch install"
},
"repository": {
"type": "git",
Expand All @@ -33,7 +33,7 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@nestia/fetcher": "^1.5.8",
"typia": "^4.2.1"
"@nestia/fetcher": "^1.6.4",
"typia": "^4.2.3"
}
}
6 changes: 3 additions & 3 deletions test/features/distribute-json/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:sdk": "rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api",
"compile": "rimraf lib && tsc",
"deploy": "npm run build && npm publish",
"prepare": "ts-patch install"
"postinstall": "ts-patch install"
},
"repository": {
"type": "git",
Expand All @@ -33,7 +33,7 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@nestia/fetcher": "^1.5.8",
"typia": "^4.2.1"
"@nestia/fetcher": "^1.6.4",
"typia": "^4.2.3"
}
}
2 changes: 1 addition & 1 deletion test/features/distribute/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@nestia/fetcher": "^1.5.8"
"@nestia/fetcher": "^1.6.4"
}
}
10 changes: 5 additions & 5 deletions test/features/encrypted/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "## Warning\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n\n-----------------\n\nInformation of yours",
"description": "## Warning\n\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n----------------\nInformation of yours",
"content": {
"text/plain": {
"schema": {
Expand All @@ -70,7 +70,7 @@
},
"responses": {
"201": {
"description": "## Warning\nResponse data have been encrypted.\n\nThe response body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedRoute.P.ost](https://github.com/samchon/@nestia/core#encryptedroute) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n\n-----------------\n\nInformation of newly joined seller",
"description": "## Warning\n\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n----------------\nInformation of newly joined seller",
"content": {
"text/plain": {
"schema": {
Expand Down Expand Up @@ -129,7 +129,7 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "## Warning\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n\n-----------------\n\nEmail and password",
"description": "## Warning\n\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n----------------\nEmail and password",
"content": {
"text/plain": {
"schema": {
Expand All @@ -142,7 +142,7 @@
},
"responses": {
"201": {
"description": "## Warning\nResponse data have been encrypted.\n\nThe response body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedRoute.P.ost](https://github.com/samchon/@nestia/core#encryptedroute) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n\n-----------------\n\nInformation of the seller",
"description": "## Warning\n\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n----------------\nInformation of the seller",
"content": {
"text/plain": {
"schema": {
Expand Down Expand Up @@ -201,7 +201,7 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "## Warning\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n\n-----------------\n\nOld and new passwords",
"description": "## Warning\n\nRequest body must be encrypted.\n\nThe request body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.\n----------------\nOld and new passwords",
"content": {
"text/plain": {
"schema": {
Expand Down
1 change: 0 additions & 1 deletion test/features/equals/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"tags": [],
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand Down
7 changes: 7 additions & 0 deletions test/features/exception-filter/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"responses": {
"201": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand All @@ -53,6 +54,7 @@
"parameters": [],
"responses": {
"200": {
"description": "",
"x-nestia-encrypted": false
}
},
Expand All @@ -78,6 +80,7 @@
],
"responses": {
"200": {
"description": "",
"x-nestia-encrypted": false
}
},
Expand All @@ -102,6 +105,7 @@
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand All @@ -123,6 +127,7 @@
"parameters": [],
"responses": {
"200": {
"description": "",
"x-nestia-encrypted": false
}
},
Expand All @@ -137,6 +142,7 @@
"parameters": [],
"responses": {
"200": {
"description": "",
"x-nestia-encrypted": false
}
},
Expand All @@ -151,6 +157,7 @@
"parameters": [],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@nestjs/common";
import { ApiResponse } from "@nestjs/swagger";
import typia, { TypeGuardError } from "typia";

import {
Expand All @@ -16,11 +15,11 @@ import { IUnprocessibleEntity } from "@api/lib/structures/IUnprocessibleEntity";

@Controller("exception")
export class ExceptionController {
@TypedRoute.Post(":section/typed")
@TypedException<TypeGuardError>(400, "invalid request")
@TypedException<INotFound>(404, "unable to find the matched section")
@TypedException<IUnprocessibleEntity>(428)
@TypedException<IInternalServerError>("5XX", "internal server error")
@TypedRoute.Post(":section/typed")
public async typed(
@TypedParam("section") section: string,
@TypedBody() input: IBbsArticle.IStore,
Expand Down Expand Up @@ -52,11 +51,11 @@ export class ExceptionController {
* @throw 428 unable to process the request
* @throw 5XX internal server error
*/
@TypedRoute.Post(":section/composite")
@TypedException<TypeGuardError>(400, "invalid request")
@TypedException<INotFound>(404)
@TypedException<IUnprocessibleEntity>(428)
@TypedException<IInternalServerError>("5XX")
@TypedRoute.Post(":section/composite")
public async composite(
@TypedParam("section") section: string,
@TypedBody() input: IBbsArticle.IStore,
Expand Down
Loading

0 comments on commit 45ad1b5

Please sign in to comment.