@shadow-library/fastify 1.6.0 → 1.6.2

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.
package/README.md CHANGED
@@ -956,6 +956,8 @@ class CreateProductDto {
956
956
 
957
957
  The `@ApiOperation` decorator allows you to add OpenAPI/Swagger metadata to your route handlers. This metadata is integrated into the Fastify route schema and can be consumed by documentation generators like Swagger UI.
958
958
 
959
+ > **Note:** Tags are auto-generated from controller class names (e.g., `UserController` → `['User']`, `UserAccountHandler` → `['User Account']`) by stripping common suffixes and converting camelCase to spaced words. Similarly, summaries are auto-generated from method names when using HTTP input decorators. Use `@ApiOperation` to override these defaults.
960
+
959
961
  ```typescript
960
962
  @ApiOperation({
961
963
  summary: string; // Short description of the operation
@@ -1,7 +1 @@
1
- /**
2
- * Defining types
3
- */
4
- /**
5
- * Declaring the constants
6
- */
7
1
  export declare function HttpController(path?: string): ClassDecorator;
@@ -9,12 +9,23 @@ const app_1 = require("@shadow-library/app");
9
9
  * Importing user defined packages
10
10
  */
11
11
  const constants_1 = require("../constants.js");
12
+ const api_operation_decorator_1 = require("./api-operation.decorator.js");
12
13
  /**
13
14
  * Defining types
14
15
  */
15
16
  /**
16
17
  * Declaring the constants
17
18
  */
19
+ const controllerNameSuffixes = ['Controller', 'API', 'Api', 'Handler', 'Resource', 'Endpoint', 'Route'];
18
20
  function HttpController(path = '') {
19
- return target => (0, app_1.Controller)({ [constants_1.HTTP_CONTROLLER_TYPE]: 'router', path })(target);
21
+ return target => {
22
+ let tag = target.name;
23
+ for (const suffix of controllerNameSuffixes)
24
+ tag = tag.replace(suffix, '');
25
+ if (!tag)
26
+ tag = target.name;
27
+ tag = tag.replace(/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g, '$1$3 $2$4');
28
+ (0, app_1.Controller)({ [constants_1.HTTP_CONTROLLER_TYPE]: 'router', path })(target);
29
+ (0, api_operation_decorator_1.ApiOperation)({ tags: [tag] })(target);
30
+ };
20
31
  }
@@ -1,6 +1,3 @@
1
- /**
2
- * Importing user defined packages
3
- */
4
1
  /**
5
2
  * Defining types
6
3
  */
@@ -9,6 +9,7 @@ const app_1 = require("@shadow-library/app");
9
9
  /**
10
10
  * Importing user defined packages
11
11
  */
12
+ const api_operation_decorator_1 = require("./api-operation.decorator.js");
12
13
  /**
13
14
  * Defining types
14
15
  */
@@ -29,7 +30,12 @@ var HttpMethod;
29
30
  function HttpRoute(options) {
30
31
  if (options.path && options.path.charAt(0) !== '/')
31
32
  options.path = `/${options.path}`;
32
- return (0, app_1.Route)(options);
33
+ return (target, propertyKey, descriptor) => {
34
+ const methodName = propertyKey.toString();
35
+ const summary = methodName.charAt(0).toUpperCase() + methodName.slice(1).replace(/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g, '$1$3 $2$4');
36
+ (0, app_1.Route)(options)(target, propertyKey, descriptor);
37
+ (0, api_operation_decorator_1.ApiOperation)({ summary })(target, propertyKey, descriptor);
38
+ };
33
39
  }
34
40
  const Get = (path) => HttpRoute({ method: HttpMethod.GET, path });
35
41
  exports.Get = Get;
@@ -1,3 +1,4 @@
1
1
  export * from './fastify-module.interface.js';
2
2
  export * from './fastify-router.js';
3
3
  export * from './fastify.module.js';
4
+ export * from './error-response.dto.js';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./fastify-module.interface.js"), exports);
18
18
  __exportStar(require("./fastify-router.js"), exports);
19
19
  __exportStar(require("./fastify.module.js"), exports);
20
+ __exportStar(require("./error-response.dto.js"), exports);
@@ -1,7 +1 @@
1
- /**
2
- * Defining types
3
- */
4
- /**
5
- * Declaring the constants
6
- */
7
1
  export declare function HttpController(path?: string): ClassDecorator;
@@ -6,12 +6,23 @@ import { Controller } from '@shadow-library/app';
6
6
  * Importing user defined packages
7
7
  */
8
8
  import { HTTP_CONTROLLER_TYPE } from '../constants.js';
9
+ import { ApiOperation } from './api-operation.decorator.js';
9
10
  /**
10
11
  * Defining types
11
12
  */
12
13
  /**
13
14
  * Declaring the constants
14
15
  */
16
+ const controllerNameSuffixes = ['Controller', 'API', 'Api', 'Handler', 'Resource', 'Endpoint', 'Route'];
15
17
  export function HttpController(path = '') {
16
- return target => Controller({ [HTTP_CONTROLLER_TYPE]: 'router', path })(target);
18
+ return target => {
19
+ let tag = target.name;
20
+ for (const suffix of controllerNameSuffixes)
21
+ tag = tag.replace(suffix, '');
22
+ if (!tag)
23
+ tag = target.name;
24
+ tag = tag.replace(/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g, '$1$3 $2$4');
25
+ Controller({ [HTTP_CONTROLLER_TYPE]: 'router', path })(target);
26
+ ApiOperation({ tags: [tag] })(target);
27
+ };
17
28
  }
@@ -1,6 +1,3 @@
1
- /**
2
- * Importing user defined packages
3
- */
4
1
  /**
5
2
  * Defining types
6
3
  */
@@ -5,6 +5,7 @@ import { Route } from '@shadow-library/app';
5
5
  /**
6
6
  * Importing user defined packages
7
7
  */
8
+ import { ApiOperation } from './api-operation.decorator.js';
8
9
  /**
9
10
  * Defining types
10
11
  */
@@ -25,7 +26,12 @@ export var HttpMethod;
25
26
  export function HttpRoute(options) {
26
27
  if (options.path && options.path.charAt(0) !== '/')
27
28
  options.path = `/${options.path}`;
28
- return Route(options);
29
+ return (target, propertyKey, descriptor) => {
30
+ const methodName = propertyKey.toString();
31
+ const summary = methodName.charAt(0).toUpperCase() + methodName.slice(1).replace(/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g, '$1$3 $2$4');
32
+ Route(options)(target, propertyKey, descriptor);
33
+ ApiOperation({ summary })(target, propertyKey, descriptor);
34
+ };
29
35
  }
30
36
  export const Get = (path) => HttpRoute({ method: HttpMethod.GET, path });
31
37
  export const Post = (path) => HttpRoute({ method: HttpMethod.POST, path });
@@ -1,3 +1,4 @@
1
1
  export * from './fastify-module.interface.js';
2
2
  export * from './fastify-router.js';
3
3
  export * from './fastify.module.js';
4
+ export * from './error-response.dto.js';
@@ -1,3 +1,4 @@
1
1
  export * from './fastify-module.interface.js';
2
2
  export * from './fastify-router.js';
3
3
  export * from './fastify.module.js';
4
+ export * from './error-response.dto.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shadow-library/fastify",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "1.6.2",
5
5
  "sideEffects": false,
6
6
  "description": "A Fastify wrapper featuring decorator-based routing, middleware and error handling",
7
7
  "repository": {