Skip to content

Commit 5bc9c89

Browse files
author
Mateus Garcia
committed
feat: resource name override
1 parent 385933a commit 5bc9c89

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

libs/json-api-nestjs/src/lib/helper/swagger/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export function setSwaggerDecorator(
2323
if (!apiTag) {
2424
const entityName =
2525
entity instanceof Function ? entity.name : entity.options.name;
26-
ApiTags(camelToKebab(entityName))(controller);
26+
27+
const resourceName = config.overrideName
28+
? config.overrideName
29+
: `${camelToKebab(entityName)}`;
30+
31+
ApiTags(resourceName)(controller);
2732
}
2833
ApiExtraModels(FilterOperand)(controller);
2934
ApiExtraModels(createApiModels(entity))(controller);

libs/json-api-nestjs/src/lib/mixin/module/module.mixin.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ BaseModuleClass.forRoot = function (options): DynamicModule {
4646
const controllerClass =
4747
controller ||
4848
nameIt(getProviderName(entity, JSON_API_CONTROLLER_POSTFIX), class {});
49+
50+
const decoratorOptions: DecoratorOptions = Reflect.getMetadata(
51+
JSON_API_DECORATOR_OPTIONS,
52+
controllerClass
53+
);
54+
55+
const resourceName = decoratorOptions?.overrideName
56+
? decoratorOptions.overrideName
57+
: `${camelToKebab(entityName)}`;
58+
4959
const transformService = transformMixin(entity, connectionName);
5060
const serviceClass = typeormMixin(entity, connectionName, transformService);
51-
Controller(`${camelToKebab(entityName)}`)(controllerClass);
61+
Controller(resourceName)(controllerClass);
5262
UseInterceptors(ErrorInterceptors)(controllerClass);
5363
Inject(serviceClass)(controllerClass.prototype, 'serviceMixin');
5464
const properties = Reflect.getMetadata(
@@ -73,10 +83,7 @@ BaseModuleClass.forRoot = function (options): DynamicModule {
7383
controllerClass
7484
);
7585
}
76-
const decoratorOptions: DecoratorOptions = Reflect.getMetadata(
77-
JSON_API_DECORATOR_OPTIONS,
78-
controllerClass
79-
);
86+
8087
const moduleConfig: ConfigParam = {
8188
...ConfigParamDefault,
8289
...options.config,

libs/json-api-nestjs/src/lib/types/module.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ConfigParam {
1818
debug: boolean;
1919
maxExecutionTime: number;
2020
pipeForId: PipeMixin;
21+
overrideName?: string;
2122
}
2223

2324
export interface ModuleOptions {

0 commit comments

Comments
 (0)