Skip to content

Commit ae3434c

Browse files
committed
Validation pattern needs escaping for | characters to prevent breaking tables
1 parent 9908731 commit ae3434c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/jsonschema/jsonschema.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func Flatten(schema apiextensionsv1.JSONSchemaProps, properties []Property, dept
8080
enum = append(enum, v)
8181
}
8282

83+
pattern := strings.ReplaceAll(schemaProps.Pattern, "|", "\\|")
84+
8385
property := Property{
8486
Depth: depth,
8587
Description: schemaProps.Description,
@@ -89,7 +91,7 @@ func Flatten(schema apiextensionsv1.JSONSchemaProps, properties []Property, dept
8991
MaxLength: maxLen,
9092
Name: propname,
9193
Path: path,
92-
Pattern: schemaProps.Pattern,
94+
Pattern: pattern,
9395
Required: required,
9496
Type: schemaProps.Type,
9597
}
@@ -113,6 +115,8 @@ func Flatten(schema apiextensionsv1.JSONSchemaProps, properties []Property, dept
113115
enum = append(enum, v)
114116
}
115117

118+
pattern := strings.ReplaceAll(schemaProps.Items.Schema.Pattern, "|", "\\|")
119+
116120
// Add description of array member type
117121
property := Property{
118122
Depth: depth + 1,
@@ -121,7 +125,7 @@ func Flatten(schema apiextensionsv1.JSONSchemaProps, properties []Property, dept
121125
Immutability: ImmutabilityRules(schemaProps.Items.Schema.XValidations),
122126
Name: propname + arrayItemIndicator,
123127
Path: path + arrayItemIndicator,
124-
Pattern: schemaProps.Items.Schema.Pattern,
128+
Pattern: pattern,
125129
Type: schemaProps.Items.Schema.Type,
126130
}
127131

0 commit comments

Comments
 (0)