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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java:
##########
@@ -624,6 +630,41 @@ private static JsonObject eipDoc(
         return result;
     }
 
+    /** The top-level entry of the YAML DSL that declares beans: a list of 
bean factories, with no model of its own. */
+    static final String BEANS_ENTRY = "beans";
+
+    private static final String BEANS_DESCRIPTION
+            = "The top-level entry of the YAML DSL that declares beans: a list 
of beans, each with a name and how to create"
+              + " it (type, properties, constructors, a factory method or a 
script)";
+
+    /**
+     * The beans entry of the YAML DSL (CAMEL-25719). Each item of its list is 
a bean factory, so the options are those
+     * of the beanFactory model, and the answer says where the entry goes and 
how a route uses a bean, with an example.
+     * A model that looked up beans before was told "EIP not found" four times 
in one step, while camel_catalog_sample
+     * had the example all along. Null when the catalog has no beanFactory 
model.
+     */
+    private static JsonObject beansDoc(CamelCatalog catalog, String filter, 
OptionScope scope, boolean includeDoc) {
+        EipModel factory = catalog.eipModel("beanFactory");
+        if (factory == null) {
+            return null;
+        }
+        JsonObject result = eipDoc(catalog, factory, filter, scope, 
includeDoc, null);
+        result.put("name", BEANS_ENTRY);
+        result.put("title", "Beans");
+        result.put("description", BEANS_DESCRIPTION + ". The options are those 
of one bean; name is required. A route uses"
+                                  + " a bean as #bean:name in an option, 
${bean:name.method} in Simple, or with the bean EIP"
+                                  + " (ref: name). The entry goes in the file 
of the routes, or in a file of its own such as"
+                                  + " beans.yaml next to them.");
+        result.put("placement", CatalogSamples.placement(BEANS_ENTRY));
+        // the example itself, short as it is, rather than a hint to fetch it 
with another call
+        JsonArray samples = (JsonArray) CatalogSamples.sample(catalog, 
BEANS_ENTRY, 1).get("samples");
+        if (samples != null && !samples.isEmpty()) {
+            result.put("sample", ((JsonObject) 
samples.get(0)).getString("yaml"));
+            result.remove("sampleHint");

Review Comment:
   💡 **Minor: `sampleHint` from `eipDoc()` may survive when samples are absent**
   
   `eipDoc()` is called with the `beanFactory` model, which sets a `sampleHint` 
referencing `"beanFactory"`. The `result.remove("sampleHint")` is only executed 
inside the `if (samples != null && !samples.isEmpty())` guard — if the 
`"beans"` sample is absent from the catalog, the stale `"beanFactory"` hint 
leaks through.
   
   Consider removing it unconditionally before the conditional block:
   
   ```suggestion
           result.put("placement", CatalogSamples.placement(BEANS_ENTRY));
           // the example itself, short as it is, rather than a hint to fetch 
it with another call
           JsonArray samples = (JsonArray) CatalogSamples.sample(catalog, 
BEANS_ENTRY, 1).get("samples");
           result.remove("sampleHint");
           if (samples != null && !samples.isEmpty()) {
               result.put("sample", ((JsonObject) 
samples.get(0)).getString("yaml"));
           }
   ```
   
   This way the method either provides the real sample or nothing — never a 
stale `beanFactory` hint.



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