gnodet-bot commented on code in PR #28025:
URL: https://github.com/apache/camel/pull/28025#discussion_r4303622928


##########
dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSchemaMojo.java:
##########
@@ -538,7 +538,42 @@ private void setProperty(
             for (String enumValue : enumValues.split(",")) {
                 current.withArray("enum").add(enumValue);
             }
+        } else if (propertyType.startsWith("multienum:")) {
+            // several of the enum values separated by comma, such as A,B: a 
JSON schema enum cannot say that
+            current.put("type", "string");
+            current.put("pattern", 
multiEnumPattern(StringHelper.after(propertyType, ":")));
+        }
+    }
+
+    /**
+     * The pattern of a comma-separated list of the enum values, with spaces 
allowed around the commas: for A,B it is
+     * ^\\s*(A|B)\\s*(,\\s*(A|B)\\s*)*$. It is an ECMA 262 regular expression, 
as JSON schema uses.
+     */
+    static String multiEnumPattern(String enumValues) {
+        String one = Stream.of(enumValues.split(","))
+                .map(String::trim)
+                .map(v -> v.replaceAll("[^A-Za-z0-9_-]", "\\\\$0"))

Review Comment:
   👍 Good — the `replaceAll` call correctly escapes the enum values for ECMA 
262 regex compatibility. The `multiEnumPattern` method faithfully produces a 
pattern like `(val1|val2|val3)` with all necessary escaping.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to