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


##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/DocBlocks.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.yaml.validator;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * The YAML route examples of an AsciiDoc page, for everything that reads the 
documentation: the doc-samples plugin and
+ * the tests that validate every example in the repository.
+ * <p/>
+ * A page that shows what to avoid - the to-eip page shows a {@code to:} with 
an expression in its uri to say why
+ * {@code toD} exists - marks the block with {@value #SKIP_MARKER} on a line 
before it, and it is then neither validated
+ * nor offered as a sample (CAMEL-24917).
+ */
+public final class DocBlocks {
+
+    /** The AsciiDoc comment that keeps a block out of the examples. */
+    public static final String SKIP_MARKER = "// yaml-validator: skip";
+
+    private static final Pattern YAML_BLOCK = 
Pattern.compile("\\[source,yaml\\]\\s*\\n----\\n(.*?)\\n----",
+            Pattern.DOTALL);
+
+    /** How far back the marker is looked for, enough for the tabs and titles 
between it and the block. */
+    private static final int MARKER_LOOKBEHIND = 200;
+
+    private DocBlocks() {
+    }
+
+    /** The route examples of the page: the YAML blocks that start with a 
top-level list entry, markers honoured. */
+    public static List<String> examples(String doc) {
+        List<String> answer = new ArrayList<>();
+        if (doc == null) {
+            return answer;
+        }
+        Matcher m = YAML_BLOCK.matcher(doc);
+        while (m.find()) {
+            String yaml = m.group(1).stripTrailing() + "\n";
+            if (yaml.stripLeading().startsWith("- ") && !markedToSkip(doc, 
m.start())) {
+                answer.add(yaml);
+            }
+        }
+        return answer;

Review Comment:
   ⚠️ **`DocBlocks.examples()` is public but never called — and it cannot be 
adopted as-is.**
   
   All three consumers (`GenerateDocSamplesMojo.examples()`, 
`EipDocExamplesTest`, `CatalogDocExamplesTest`) inline their own `YAML_BLOCK` 
matching and call only `markedToSkip()`. None of them call 
`DocBlocks.examples()`.
   
   Worse: `GenerateDocSamplesMojo.examples()` strips AsciiDoc callout markers 
(`# <1>`) from the YAML before storing it, whereas `DocBlocks.examples()` does 
not. If a future caller switches to `DocBlocks.examples()`, generated samples 
will contain callout noise that breaks YAML parsing.
   
   Either:
   - Remove `examples()` from `DocBlocks` (it is unused dead API) and leave the 
three callers as they are; or
   - Have the three callers use `DocBlocks.examples()` and move the 
callout-stripping into it, making the API actually shared.
   
   As written, the method promises reuse (`"for everything that reads the 
documentation"`) but silently diverges from two of the three callers the moment 
callouts appear in a page.



-- 
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