@nestia/core 2.5.8 → 2.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +9 -6
  2. package/lib/decorators/SwaggerCustomizer.d.ts +64 -0
  3. package/lib/decorators/SwaggerCustomizer.js +25 -0
  4. package/lib/decorators/SwaggerCustomizer.js.map +1 -0
  5. package/lib/module.d.ts +1 -0
  6. package/lib/module.js +1 -0
  7. package/lib/module.js.map +1 -1
  8. package/lib/structures/ISwagger.d.ts +72 -0
  9. package/lib/structures/ISwagger.js +3 -0
  10. package/lib/structures/ISwagger.js.map +1 -0
  11. package/lib/structures/ISwaggerComponents.d.ts +26 -0
  12. package/lib/structures/ISwaggerComponents.js +3 -0
  13. package/lib/structures/ISwaggerComponents.js.map +1 -0
  14. package/lib/structures/ISwaggerInfo.d.ts +71 -0
  15. package/lib/structures/ISwaggerInfo.js +3 -0
  16. package/lib/structures/ISwaggerInfo.js.map +1 -0
  17. package/lib/structures/ISwaggerRoute.d.ts +46 -0
  18. package/lib/structures/ISwaggerRoute.js +3 -0
  19. package/lib/structures/ISwaggerRoute.js.map +1 -0
  20. package/lib/structures/ISwaggerSecurityScheme.d.ts +56 -0
  21. package/lib/structures/ISwaggerSecurityScheme.js +3 -0
  22. package/lib/structures/ISwaggerSecurityScheme.js.map +1 -0
  23. package/package.json +3 -3
  24. package/src/decorators/EncryptedBody.ts +105 -105
  25. package/src/decorators/EncryptedModule.ts +96 -96
  26. package/src/decorators/PlainBody.ts +75 -75
  27. package/src/decorators/SwaggerCustomizer.ts +87 -0
  28. package/src/decorators/TypedBody.ts +62 -62
  29. package/src/decorators/TypedException.ts +90 -90
  30. package/src/decorators/TypedRoute.ts +144 -144
  31. package/src/decorators/internal/get_path_and_querify.ts +106 -106
  32. package/src/decorators/internal/load_controller.ts +51 -51
  33. package/src/decorators/internal/validate_request_body.ts +72 -72
  34. package/src/decorators/internal/validate_request_headers.ts +83 -83
  35. package/src/decorators/internal/validate_request_query.ts +71 -71
  36. package/src/module.ts +1 -0
  37. package/src/structures/ISwagger.ts +91 -0
  38. package/src/structures/ISwaggerComponents.ts +29 -0
  39. package/src/structures/ISwaggerInfo.ts +80 -0
  40. package/src/structures/ISwaggerRoute.ts +50 -0
  41. package/src/structures/ISwaggerSecurityScheme.ts +65 -0
  42. package/src/transformers/NodeTransformer.ts +16 -16
  43. package/src/transformers/TypedExceptionTransformer.ts +48 -48
  44. package/src/transformers/TypedRouteTransformer.ts +88 -88
  45. package/src/utils/Singleton.ts +20 -20
@@ -1,105 +1,105 @@
1
- import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
2
- import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
3
- import {
4
- BadRequestException,
5
- ExecutionContext,
6
- createParamDecorator,
7
- } from "@nestjs/common";
8
- import type express from "express";
9
- import type { FastifyRequest } from "fastify";
10
- import { assert, is, validate } from "typia";
11
-
12
- import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
13
- import { Singleton } from "../utils/Singleton";
14
- import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
15
- import { get_text_body } from "./internal/get_text_body";
16
- import { headers_to_object } from "./internal/headers_to_object";
17
- import { validate_request_body } from "./internal/validate_request_body";
18
-
19
- /**
20
- * Encrypted body decorator.
21
- *
22
- * `EncryptedBody` is a decorator function getting `application/json` typed data from
23
- * requeset body which has been encrypted by AES-128/256 algorithm. Also,
24
- * `EncyrptedBody` validates the request body data type through
25
- * [typia](https://github.com/samchon/typia) ad the validation speed is
26
- * maximum 15,000x times faster than `class-validator`.
27
- *
28
- * For reference, when the request body data is not following the promised type `T`,
29
- * `BadRequestException` error (status code: 400) would be thrown. Also,
30
- * `EncryptedRoute` decrypts request body using those options.
31
- *
32
- * - AES-128/256
33
- * - CBC mode
34
- * - PKCS #5 Padding
35
- * - Base64 Encoding
36
- *
37
- * @return Parameter decorator
38
- * @author Jeongho Nam - https://github.com/samchon
39
- */
40
- export function EncryptedBody<T>(
41
- validator?: IRequestBodyValidator<T>,
42
- ): ParameterDecorator {
43
- const checker = validate_request_body("EncryptedBody")(validator);
44
- return createParamDecorator(async function EncryptedBody(
45
- _unknown: any,
46
- context: ExecutionContext,
47
- ) {
48
- const request: express.Request | FastifyRequest = context
49
- .switchToHttp()
50
- .getRequest();
51
- if (isTextPlain(request.headers["content-type"]) === false)
52
- throw new BadRequestException(`Request body type is not "text/plain".`);
53
-
54
- const param: IEncryptionPassword | IEncryptionPassword.Closure | undefined =
55
- Reflect.getMetadata(ENCRYPTION_METADATA_KEY, context.getClass());
56
- if (!param)
57
- throw new Error(
58
- "Error on nestia.core.EncryptedBody(): no encryption password is given.",
59
- );
60
-
61
- // GET BODY DATA
62
- const headers: Singleton<Record<string, string>> = new Singleton(() =>
63
- headers_to_object(request.headers),
64
- );
65
- const body: string = await get_text_body(request);
66
- const password: IEncryptionPassword =
67
- typeof param === "function"
68
- ? param({ headers: headers.get(), body, direction: "decode" })
69
- : param;
70
-
71
- // PARSE AND VALIDATE DATA
72
- const data: any = JSON.parse(decrypt(body, password.key, password.iv));
73
- const error: Error | null = checker(data);
74
- if (error !== null) throw error;
75
- return data;
76
- })();
77
- }
78
- Object.assign(EncryptedBody, is);
79
- Object.assign(EncryptedBody, assert);
80
- Object.assign(EncryptedBody, validate);
81
-
82
- /**
83
- * @internal
84
- */
85
- const decrypt = (body: string, key: string, iv: string): string => {
86
- try {
87
- return AesPkcs5.decrypt(body, key, iv);
88
- } catch (exp) {
89
- if (exp instanceof Error)
90
- throw new BadRequestException(
91
- "Failed to decrypt the request body. Check your body content or encryption password.",
92
- );
93
- else throw exp;
94
- }
95
- };
96
-
97
- /**
98
- * @internal
99
- */
100
- const isTextPlain = (text?: string): boolean =>
101
- text !== undefined &&
102
- text
103
- .split(";")
104
- .map((str) => str.trim())
105
- .some((str) => str === "text/plain");
1
+ import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
2
+ import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
3
+ import {
4
+ BadRequestException,
5
+ ExecutionContext,
6
+ createParamDecorator,
7
+ } from "@nestjs/common";
8
+ import type express from "express";
9
+ import type { FastifyRequest } from "fastify";
10
+ import { assert, is, validate } from "typia";
11
+
12
+ import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
13
+ import { Singleton } from "../utils/Singleton";
14
+ import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
15
+ import { get_text_body } from "./internal/get_text_body";
16
+ import { headers_to_object } from "./internal/headers_to_object";
17
+ import { validate_request_body } from "./internal/validate_request_body";
18
+
19
+ /**
20
+ * Encrypted body decorator.
21
+ *
22
+ * `EncryptedBody` is a decorator function getting `application/json` typed data from
23
+ * requeset body which has been encrypted by AES-128/256 algorithm. Also,
24
+ * `EncyrptedBody` validates the request body data type through
25
+ * [typia](https://github.com/samchon/typia) ad the validation speed is
26
+ * maximum 15,000x times faster than `class-validator`.
27
+ *
28
+ * For reference, when the request body data is not following the promised type `T`,
29
+ * `BadRequestException` error (status code: 400) would be thrown. Also,
30
+ * `EncryptedRoute` decrypts request body using those options.
31
+ *
32
+ * - AES-128/256
33
+ * - CBC mode
34
+ * - PKCS #5 Padding
35
+ * - Base64 Encoding
36
+ *
37
+ * @return Parameter decorator
38
+ * @author Jeongho Nam - https://github.com/samchon
39
+ */
40
+ export function EncryptedBody<T>(
41
+ validator?: IRequestBodyValidator<T>,
42
+ ): ParameterDecorator {
43
+ const checker = validate_request_body("EncryptedBody")(validator);
44
+ return createParamDecorator(async function EncryptedBody(
45
+ _unknown: any,
46
+ context: ExecutionContext,
47
+ ) {
48
+ const request: express.Request | FastifyRequest = context
49
+ .switchToHttp()
50
+ .getRequest();
51
+ if (isTextPlain(request.headers["content-type"]) === false)
52
+ throw new BadRequestException(`Request body type is not "text/plain".`);
53
+
54
+ const param: IEncryptionPassword | IEncryptionPassword.Closure | undefined =
55
+ Reflect.getMetadata(ENCRYPTION_METADATA_KEY, context.getClass());
56
+ if (!param)
57
+ throw new Error(
58
+ "Error on nestia.core.EncryptedBody(): no encryption password is given.",
59
+ );
60
+
61
+ // GET BODY DATA
62
+ const headers: Singleton<Record<string, string>> = new Singleton(() =>
63
+ headers_to_object(request.headers),
64
+ );
65
+ const body: string = await get_text_body(request);
66
+ const password: IEncryptionPassword =
67
+ typeof param === "function"
68
+ ? param({ headers: headers.get(), body, direction: "decode" })
69
+ : param;
70
+
71
+ // PARSE AND VALIDATE DATA
72
+ const data: any = JSON.parse(decrypt(body, password.key, password.iv));
73
+ const error: Error | null = checker(data);
74
+ if (error !== null) throw error;
75
+ return data;
76
+ })();
77
+ }
78
+ Object.assign(EncryptedBody, is);
79
+ Object.assign(EncryptedBody, assert);
80
+ Object.assign(EncryptedBody, validate);
81
+
82
+ /**
83
+ * @internal
84
+ */
85
+ const decrypt = (body: string, key: string, iv: string): string => {
86
+ try {
87
+ return AesPkcs5.decrypt(body, key, iv);
88
+ } catch (exp) {
89
+ if (exp instanceof Error)
90
+ throw new BadRequestException(
91
+ "Failed to decrypt the request body. Check your body content or encryption password.",
92
+ );
93
+ else throw exp;
94
+ }
95
+ };
96
+
97
+ /**
98
+ * @internal
99
+ */
100
+ const isTextPlain = (text?: string): boolean =>
101
+ text !== undefined &&
102
+ text
103
+ .split(";")
104
+ .map((str) => str.trim())
105
+ .some((str) => str === "text/plain");
@@ -1,96 +1,96 @@
1
- import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
2
- import { Module } from "@nestjs/common";
3
-
4
- import { Creator } from "../typings/Creator";
5
- import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
6
- import { load_controllers } from "./internal/load_controller";
7
-
8
- /**
9
- * Encrypted module.
10
- *
11
- * `EncryptedModule` is an extension of the {@link Module} class decorator function
12
- * who configures encryption password of the AES-128/256 algorithm. The encryption
13
- * algorithm and password would be used by {@link EncryptedRoute} and {@link EncryptedBody}
14
- * to encrypt the request and response bod of the HTTP protocol.
15
- *
16
- * By using this `EncryptedModule` decorator function, all of the
17
- * {@link Controller controllers} configured in the *metadata* would be automatically
18
- * changed to the {@link EncryptedController} with the *password*. If there're some
19
- * original {@link EncryptedController} decorated classes in the *metadata*, their
20
- * encryption password would be kept.
21
- *
22
- * Therefore, if you're planning to place original {@link EncryptedController} decorated
23
- * classes in the *metadata*, I hope them to have different encryption password from the
24
- * module level. If not, I recommend you use the {@link Controller} decorator
25
- * function instead.
26
- *
27
- * In addition, the `EncryptedModule` supports a convenient dynamic controller importing
28
- * function, {@link EncryptedModule.dynamic}. If you utilize the function with directory
29
- * path of the controller classes, it imports and configures the controller classes into
30
- * the `Module`, automatically.
31
- *
32
- * @param metadata Module configuration metadata
33
- * @param password Encryption password or its getter function
34
- * @returns Class decorator
35
- *
36
- * @author Jeongho Nam - https://github.com/samchon
37
- */
38
- export function EncryptedModule(
39
- metadata: Parameters<typeof Module>[0],
40
- password: IEncryptionPassword.Closure,
41
- ): ClassDecorator {
42
- return function (target: any) {
43
- Module(metadata)(target);
44
- iterate(password)(target);
45
- };
46
- }
47
-
48
- export namespace EncryptedModule {
49
- /**
50
- * Dynamic encrypted module.
51
- *
52
- * `EncryptedModule.dynamic` is an extension of the {@link EncryptedModule} function
53
- * who configures controller classes by the dynamic importing. By specifying directory
54
- * path of the controller classes, those controllers would be automatically imported
55
- * and configured.
56
- *
57
- * @param path Directory path of the controller classes
58
- * @param password Encryption password or its getter function
59
- * @param options Additional options except controller
60
- * @returns Class decorated module instance
61
- */
62
- export async function dynamic(
63
- path: string | string[] | { include: string[]; exclude?: string[] },
64
- password: IEncryptionPassword | IEncryptionPassword.Closure,
65
- options: Omit<Parameters<typeof Module>[0], "controllers"> = {},
66
- ): Promise<object> {
67
- // LOAD CONTROLLERS
68
- const controllers: Creator<object>[] = await load_controllers(path);
69
-
70
- // RETURNS WITH DECORATING
71
- @EncryptedModule(
72
- { ...options, controllers },
73
- typeof password === "object" ? () => password : password,
74
- )
75
- class NestiaModule {}
76
- return NestiaModule;
77
- }
78
- }
79
-
80
- /**
81
- * @internal
82
- */
83
- const iterate =
84
- (password: IEncryptionPassword.Closure) =>
85
- (modulo: any): void => {
86
- const imports = Reflect.getMetadata("imports", modulo);
87
- if (Array.isArray(imports))
88
- for (const imp of imports)
89
- if (typeof imp === "function") iterate(password)(imp);
90
-
91
- const controllers = Reflect.getMetadata("controllers", modulo);
92
- if (Array.isArray(controllers))
93
- for (const c of controllers)
94
- if (typeof c === "function")
95
- Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, c);
96
- };
1
+ import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
2
+ import { Module } from "@nestjs/common";
3
+
4
+ import { Creator } from "../typings/Creator";
5
+ import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
6
+ import { load_controllers } from "./internal/load_controller";
7
+
8
+ /**
9
+ * Encrypted module.
10
+ *
11
+ * `EncryptedModule` is an extension of the {@link Module} class decorator function
12
+ * who configures encryption password of the AES-128/256 algorithm. The encryption
13
+ * algorithm and password would be used by {@link EncryptedRoute} and {@link EncryptedBody}
14
+ * to encrypt the request and response bod of the HTTP protocol.
15
+ *
16
+ * By using this `EncryptedModule` decorator function, all of the
17
+ * {@link Controller controllers} configured in the *metadata* would be automatically
18
+ * changed to the {@link EncryptedController} with the *password*. If there're some
19
+ * original {@link EncryptedController} decorated classes in the *metadata*, their
20
+ * encryption password would be kept.
21
+ *
22
+ * Therefore, if you're planning to place original {@link EncryptedController} decorated
23
+ * classes in the *metadata*, I hope them to have different encryption password from the
24
+ * module level. If not, I recommend you use the {@link Controller} decorator
25
+ * function instead.
26
+ *
27
+ * In addition, the `EncryptedModule` supports a convenient dynamic controller importing
28
+ * function, {@link EncryptedModule.dynamic}. If you utilize the function with directory
29
+ * path of the controller classes, it imports and configures the controller classes into
30
+ * the `Module`, automatically.
31
+ *
32
+ * @param metadata Module configuration metadata
33
+ * @param password Encryption password or its getter function
34
+ * @returns Class decorator
35
+ *
36
+ * @author Jeongho Nam - https://github.com/samchon
37
+ */
38
+ export function EncryptedModule(
39
+ metadata: Parameters<typeof Module>[0],
40
+ password: IEncryptionPassword.Closure,
41
+ ): ClassDecorator {
42
+ return function (target: any) {
43
+ Module(metadata)(target);
44
+ iterate(password)(target);
45
+ };
46
+ }
47
+
48
+ export namespace EncryptedModule {
49
+ /**
50
+ * Dynamic encrypted module.
51
+ *
52
+ * `EncryptedModule.dynamic` is an extension of the {@link EncryptedModule} function
53
+ * who configures controller classes by the dynamic importing. By specifying directory
54
+ * path of the controller classes, those controllers would be automatically imported
55
+ * and configured.
56
+ *
57
+ * @param path Directory path of the controller classes
58
+ * @param password Encryption password or its getter function
59
+ * @param options Additional options except controller
60
+ * @returns Class decorated module instance
61
+ */
62
+ export async function dynamic(
63
+ path: string | string[] | { include: string[]; exclude?: string[] },
64
+ password: IEncryptionPassword | IEncryptionPassword.Closure,
65
+ options: Omit<Parameters<typeof Module>[0], "controllers"> = {},
66
+ ): Promise<object> {
67
+ // LOAD CONTROLLERS
68
+ const controllers: Creator<object>[] = await load_controllers(path);
69
+
70
+ // RETURNS WITH DECORATING
71
+ @EncryptedModule(
72
+ { ...options, controllers },
73
+ typeof password === "object" ? () => password : password,
74
+ )
75
+ class NestiaModule {}
76
+ return NestiaModule;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @internal
82
+ */
83
+ const iterate =
84
+ (password: IEncryptionPassword.Closure) =>
85
+ (modulo: any): void => {
86
+ const imports = Reflect.getMetadata("imports", modulo);
87
+ if (Array.isArray(imports))
88
+ for (const imp of imports)
89
+ if (typeof imp === "function") iterate(password)(imp);
90
+
91
+ const controllers = Reflect.getMetadata("controllers", modulo);
92
+ if (Array.isArray(controllers))
93
+ for (const c of controllers)
94
+ if (typeof c === "function")
95
+ Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, c);
96
+ };
@@ -1,75 +1,75 @@
1
- import {
2
- BadRequestException,
3
- ExecutionContext,
4
- createParamDecorator,
5
- } from "@nestjs/common";
6
- import type express from "express";
7
- import type { FastifyRequest } from "fastify";
8
- import { assert } from "typia";
9
-
10
- import { get_text_body } from "./internal/get_text_body";
11
- import { validate_request_body } from "./internal/validate_request_body";
12
-
13
- /**
14
- * Plain body decorator.
15
- *
16
- * `PlainBody` is a decorator function getting full body text from the HTTP request.
17
- *
18
- * If you adjust the regular {@link Body} decorator function to the body parameter,
19
- * you can't get the full body text because the {@link Body} tries to convert the
20
- * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
21
- * decorator function to get the full body text.
22
- *
23
- * ```typescript
24
- * \@TypedRoute.Post("memo")
25
- * public store
26
- * (
27
- * \@PlainBody() body: string
28
- * ): void;
29
- * ```
30
- *
31
- * @return Parameter decorator
32
- * @author Jeongho Nam - https://github.com/samchon
33
- */
34
- export function PlainBody(): ParameterDecorator;
35
-
36
- /**
37
- * @internal
38
- */
39
- export function PlainBody(
40
- assert?: (input: unknown) => string,
41
- ): ParameterDecorator {
42
- const checker = assert
43
- ? validate_request_body("PlainBody")({
44
- type: "assert",
45
- assert,
46
- })
47
- : null;
48
- return createParamDecorator(async function PlainBody(
49
- _data: any,
50
- context: ExecutionContext,
51
- ) {
52
- const request: express.Request | FastifyRequest = context
53
- .switchToHttp()
54
- .getRequest();
55
- if (!isTextPlain(request.headers["content-type"]))
56
- throw new BadRequestException(`Request body type is not "text/plain".`);
57
- const value: string = await get_text_body(request);
58
- if (checker) {
59
- const error: Error | null = checker(value);
60
- if (error !== null) throw error;
61
- }
62
- return value;
63
- })();
64
- }
65
- Object.assign(PlainBody, assert);
66
-
67
- /**
68
- * @internal
69
- */
70
- const isTextPlain = (text?: string): boolean =>
71
- text !== undefined &&
72
- text
73
- .split(";")
74
- .map((str) => str.trim())
75
- .some((str) => str === "text/plain");
1
+ import {
2
+ BadRequestException,
3
+ ExecutionContext,
4
+ createParamDecorator,
5
+ } from "@nestjs/common";
6
+ import type express from "express";
7
+ import type { FastifyRequest } from "fastify";
8
+ import { assert } from "typia";
9
+
10
+ import { get_text_body } from "./internal/get_text_body";
11
+ import { validate_request_body } from "./internal/validate_request_body";
12
+
13
+ /**
14
+ * Plain body decorator.
15
+ *
16
+ * `PlainBody` is a decorator function getting full body text from the HTTP request.
17
+ *
18
+ * If you adjust the regular {@link Body} decorator function to the body parameter,
19
+ * you can't get the full body text because the {@link Body} tries to convert the
20
+ * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
21
+ * decorator function to get the full body text.
22
+ *
23
+ * ```typescript
24
+ * \@TypedRoute.Post("memo")
25
+ * public store
26
+ * (
27
+ * \@PlainBody() body: string
28
+ * ): void;
29
+ * ```
30
+ *
31
+ * @return Parameter decorator
32
+ * @author Jeongho Nam - https://github.com/samchon
33
+ */
34
+ export function PlainBody(): ParameterDecorator;
35
+
36
+ /**
37
+ * @internal
38
+ */
39
+ export function PlainBody(
40
+ assert?: (input: unknown) => string,
41
+ ): ParameterDecorator {
42
+ const checker = assert
43
+ ? validate_request_body("PlainBody")({
44
+ type: "assert",
45
+ assert,
46
+ })
47
+ : null;
48
+ return createParamDecorator(async function PlainBody(
49
+ _data: any,
50
+ context: ExecutionContext,
51
+ ) {
52
+ const request: express.Request | FastifyRequest = context
53
+ .switchToHttp()
54
+ .getRequest();
55
+ if (!isTextPlain(request.headers["content-type"]))
56
+ throw new BadRequestException(`Request body type is not "text/plain".`);
57
+ const value: string = await get_text_body(request);
58
+ if (checker) {
59
+ const error: Error | null = checker(value);
60
+ if (error !== null) throw error;
61
+ }
62
+ return value;
63
+ })();
64
+ }
65
+ Object.assign(PlainBody, assert);
66
+
67
+ /**
68
+ * @internal
69
+ */
70
+ const isTextPlain = (text?: string): boolean =>
71
+ text !== undefined &&
72
+ text
73
+ .split(";")
74
+ .map((str) => str.trim())
75
+ .some((str) => str === "text/plain");
@@ -0,0 +1,87 @@
1
+ import { ISwagger } from "../structures/ISwagger";
2
+ import { ISwaggerRoute } from "../structures/ISwaggerRoute";
3
+
4
+ /**
5
+ * Swagger customization decorator.
6
+ *
7
+ * `SwaggerCustomizer` is a method decorator function which can used for
8
+ * customizing the swagger data with `npx nestia swagger` command. Furthermore,
9
+ * it is possible to add plugin properties starting with `x-` characters.
10
+ *
11
+ * In other words, this decorator function does not affect to the runtime,
12
+ * but only for the swagger data customization.
13
+ *
14
+ * @param closure Callback function which can customize the swagger data
15
+ * @returns Method decorator
16
+ * @author Jeongho Nam - https://github.com/samchon
17
+ */
18
+ export function SwaggerCustomizer(
19
+ closure: (props: SwaggerCustomizer.IProps) => unknown,
20
+ ): MethodDecorator {
21
+ return function SwaggerCustomizer(
22
+ target: Object,
23
+ propertyKey: string | symbol,
24
+ descriptor: TypedPropertyDescriptor<any>,
25
+ ) {
26
+ Reflect.defineMetadata(
27
+ "nestia/SwaggerCustomizer",
28
+ closure,
29
+ target,
30
+ propertyKey,
31
+ );
32
+ return descriptor;
33
+ };
34
+ }
35
+ export namespace SwaggerCustomizer {
36
+ /**
37
+ * Properties for the `SwaggerCustomizer` decorator.
38
+ *
39
+ * `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
40
+ * `SwaggerCustomizer` decorator. It's a callback function which can customize
41
+ * the swagger data.
42
+ */
43
+ export interface IProps {
44
+ /**
45
+ * Swagger data.
46
+ */
47
+ swagger: ISwagger;
48
+
49
+ /**
50
+ * Method of the route.
51
+ */
52
+ method: string;
53
+
54
+ /**
55
+ * Path of the route.
56
+ */
57
+ path: string;
58
+
59
+ /**
60
+ * Route data.
61
+ */
62
+ route: ISwaggerRoute;
63
+
64
+ /**
65
+ * Get neighbor route data.
66
+ *
67
+ * @param accessor Accessor for getting neighbor route data
68
+ * @returns Neighbor route data
69
+ */
70
+ get(accessor: IAccessor): ISwaggerRoute | undefined;
71
+ }
72
+
73
+ /**
74
+ * Accessor for getting neighbor route data.
75
+ */
76
+ export interface IAccessor {
77
+ /**
78
+ * Path of the neighbor route.
79
+ */
80
+ path: string;
81
+
82
+ /**
83
+ * Method of the neighbor route.
84
+ */
85
+ method: string;
86
+ }
87
+ }