File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ describe("Params spec extraction", () => {
9
9
. default
10
10
) . to . equal ( `{{ params.BAR != 22 ? "asdf" : "jkl;" }}` ) ;
11
11
} ) ;
12
+
13
+ it ( "converts RegExps in string validation parameters to strings" , ( ) => {
14
+ const foo = params . defineString ( "FOO" , { input : { text : { validationRegex : / \d { 5 } / } } } ) ;
15
+ expect ( foo . toSpec ( ) . input ) . to . deep . equal ( { text : { validationRegex : "\\d{5}" } } ) ;
16
+ } ) ;
12
17
} ) ;
13
18
14
19
describe ( "Params value extraction" , ( ) => {
Original file line number Diff line number Diff line change @@ -9,6 +9,36 @@ describe("stackToWire", () => {
9
9
params . clearParams ( ) ;
10
10
} ) ;
11
11
12
+ it ( "converts regular expressions used in param inputs" , ( ) => {
13
+ const regExpParam = params . defineString ( "foo" , {
14
+ input : { text : { validationRegex : / \d { 5 } / } } ,
15
+ } ) ;
16
+
17
+ const stack : ManifestStack = {
18
+ endpoints : { } ,
19
+ requiredAPIs : [ ] ,
20
+ params : [ regExpParam . toSpec ( ) ] ,
21
+ specVersion : "v1alpha1" ,
22
+ } ;
23
+ const expected = {
24
+ endpoints : { } ,
25
+ requiredAPIs : [ ] ,
26
+ params : [
27
+ {
28
+ name : "foo" ,
29
+ type : "string" ,
30
+ input : {
31
+ text : {
32
+ validationRegex : "\\d{5}" ,
33
+ } ,
34
+ } ,
35
+ } ,
36
+ ] ,
37
+ specVersion : "v1alpha1" ,
38
+ } ;
39
+ expect ( stackToWire ( stack ) ) . to . deep . equal ( expected ) ;
40
+ } ) ;
41
+
12
42
it ( "converts stack with null values" , ( ) => {
13
43
const stack : ManifestStack = {
14
44
endpoints : {
Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ type ParamInput<T> =
151
151
// eslint-disable-next-line @typescript-eslint/no-unused-vars
152
152
export interface TextInput < T = unknown > {
153
153
example ?: string ;
154
- validationRegex ?: string ;
154
+ validationRegex ?: string | RegExp ;
155
155
validationErrorMessage ?: string ;
156
156
}
157
157
@@ -261,6 +261,10 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
261
261
out . default = paramDefault ;
262
262
}
263
263
264
+ if ( out . input && "text" in out . input && out . input . text . validationRegex instanceof RegExp ) {
265
+ out . input . text . validationRegex = out . input . text . validationRegex . source ;
266
+ }
267
+
264
268
return out ;
265
269
}
266
270
}
You can’t perform that action at this time.
0 commit comments