From fc60a37ff50f3a8dc0ed8d5ca21357e3ff4f8d8a Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 7 Apr 2024 14:47:07 +0900 Subject: [PATCH 1/2] added support for URI format in directive config --- src/directive.ts | 2 +- tests/directive.spec.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/directive.ts b/src/directive.ts index 944585f4..71683287 100644 --- a/src/directive.ts +++ b/src/directive.ts @@ -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]; diff --git a/tests/directive.spec.ts b/tests/directive.spec.ts index 73059e6e..25bf1658 100644 --- a/tests/directive.spec.ts +++ b/tests/directive.spec.ts @@ -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, () => { From 898f82471f981780b7ac264c0bb5de2fd9c58050 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 7 Apr 2024 14:51:23 +0900 Subject: [PATCH 2/2] updated README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e5d1461c..184767bb 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 ```