Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ generates:
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: [matches, /^$1/]
format:
# This example means `validation-schema: directive-arg`
# directive-arg is supported String and Enum.
email: email
```

Expand Down Expand Up @@ -279,6 +281,8 @@ generates:
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: [regex, /^$1/, message]
format:
# This example means `validation-schema: directive-arg`
# directive-arg is supported String and Enum.
email: email
```

Expand Down
2 changes: 1 addition & 1 deletion src/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function buildApiFromDirectiveArguments(config: FormattedDirectiveArguments, arg
}

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

const validationSchema = config[argValue.value];
Expand Down
19 changes: 19 additions & 0 deletions tests/directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,25 @@ describe('format directive config', () => {
},
want: `.required("message").min(100).email()`,
},
{
name: 'enum',
args: {
config: {
constraint: {
format: {
URI: ['uri'],
},
},
},
args: [
// @constraint(format: EMAIL)
buildConstDirectiveNodes('constraint', {
format: 'URI',
}),
],
},
want: `.uri()`,
},
];
for (const tc of cases) {
it(tc.name, () => {
Expand Down