@shadow-library/fastify 1.6.1 → 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 +2 -0
- package/cjs/decorators/http-controller.decorator.d.ts +0 -6
- package/cjs/decorators/http-controller.decorator.js +12 -1
- package/cjs/decorators/http-route.decorator.d.ts +0 -3
- package/cjs/decorators/http-route.decorator.js +7 -1
- package/esm/decorators/http-controller.decorator.d.ts +0 -6
- package/esm/decorators/http-controller.decorator.js +12 -1
- package/esm/decorators/http-route.decorator.d.ts +0 -3
- package/esm/decorators/http-route.decorator.js +7 -1
- package/package.json +1 -1
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
|
|
@@ -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 =>
|
|
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
|
}
|
|
@@ -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 (
|
|
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;
|
|
@@ -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 =>
|
|
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
|
}
|
|
@@ -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
|
|
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 });
|
package/package.json
CHANGED