Skip to content

Commit fc60a37

Browse files
committed
added support for URI format in directive config
1 parent 190056d commit fc60a37

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function buildApiFromDirectiveArguments(config: FormattedDirectiveArguments, arg
146146
}
147147

148148
function buildApiFromDirectiveObjectArguments(config: FormattedDirectiveObjectArguments, argValue: ConstValueNode): string {
149-
if (argValue.kind !== Kind.STRING)
149+
if (argValue.kind !== Kind.STRING && argValue.kind !== Kind.ENUM)
150150
return '';
151151

152152
const validationSchema = config[argValue.value];

tests/directive.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,25 @@ describe('format directive config', () => {
575575
},
576576
want: `.required("message").min(100).email()`,
577577
},
578+
{
579+
name: 'enum',
580+
args: {
581+
config: {
582+
constraint: {
583+
format: {
584+
URI: ['uri'],
585+
},
586+
},
587+
},
588+
args: [
589+
// @constraint(format: EMAIL)
590+
buildConstDirectiveNodes('constraint', {
591+
format: 'URI',
592+
}),
593+
],
594+
},
595+
want: `.uri()`,
596+
},
578597
];
579598
for (const tc of cases) {
580599
it(tc.name, () => {

0 commit comments

Comments
 (0)