Skip to content

Commit d6b664a

Browse files
authored
feat: add decorator name to validation metadata (#1687)
1 parent c3130af commit d6b664a

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

src/metadata/ValidationMetadata.ts

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export class ValidationMetadata {
1414
*/
1515
type: string;
1616

17+
/**
18+
* Validator name.
19+
*/
20+
name?: string;
21+
1722
/**
1823
* Target class to which this validation is applied.
1924
*/
@@ -70,6 +75,7 @@ export class ValidationMetadata {
7075

7176
constructor(args: ValidationMetadataArgs) {
7277
this.type = args.type;
78+
this.name = args.name;
7379
this.target = args.target;
7480
this.propertyName = args.propertyName;
7581
this.constraints = args?.constraints;

src/metadata/ValidationMetadataArgs.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export interface ValidationMetadataArgs {
99
*/
1010
type: string;
1111

12+
/**
13+
* Validator name.
14+
*/
15+
name?: string;
16+
1217
/**
1318
* Object that is used to be validated.
1419
*/

src/register-decorator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function registerDecorator(options: ValidationDecoratorOptions): void {
7676

7777
const validationMetadataArgs: ValidationMetadataArgs = {
7878
type: options.name && ValidationTypes.isValid(options.name) ? options.name : ValidationTypes.CUSTOM_VALIDATION,
79+
name: options.name,
7980
target: options.target,
8081
propertyName: options.propertyName,
8182
validationOptions: options.options,

src/validation-schema/ValidationSchema.ts

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface ValidationSchema {
2121
*/
2222
type: string;
2323

24+
/**
25+
* Validator name.
26+
*/
27+
name?: string;
28+
2429
/**
2530
* Constraints set by validation type.
2631
*/

src/validation-schema/ValidationSchemaToMetadataTransformer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class ValidationSchemaToMetadataTransformer {
1919
};
2020
const args: ValidationMetadataArgs = {
2121
type: validation.type,
22+
name: validation.name,
2223
target: schema.name,
2324
propertyName: property,
2425
constraints: validation.constraints,

0 commit comments

Comments
 (0)