4747 * This command downloads the specified Camel component dependencies and generates a JSON Schema (Draft 2020-12) for the
4848 * given fully qualified class name.
4949 *
50- * Usage Examples: - camel generate schema fhir org.hl7.fhir.r4.model.Patient - camel generate schema http
51- * org.apache.camel.component.http.HttpConfiguration
50+ * Usage Examples: - camel generate schema fhir org.hl7.fhir.r4.model.Patient - camel generate schema timer
51+ * org.apache.camel.component.timer.TimerComponent
5252 *
5353 * The generated schema includes: - Public and non-public fields (with getters) - Flattened enums using toString() -
5454 * Jackson annotations support
5555 *
56- * Exit Codes: - 0: Success - 1: Component not found or dependency download failed - 2: Class not found - 3: Schema
57- * generation failed - 4: General error
56+ * The schema goes to stdout, or to the file of --output; --verbose tells on stderr what the command does.
57+ *
58+ * Exit Codes: - 0: Success - 1: the dependencies cannot be downloaded, or the schema cannot be generated - 2: a
59+ * component or class name that is empty - 3: the class is not in the dependencies of the component - 70: an unexpected
60+ * error
5861 */
5962@ CommandDefinition (name = "schema" , description = "Create a JSON schema for a given Camel component and Java Object" ,
6063 generateHelp = true , sortOptions = true )
@@ -90,9 +93,9 @@ public Integer doCall() throws Exception {
9093 }
9194
9295 if (verbose ) {
93- printer ().println ("Generating JSON Schema for component: " + camelComponent );
94- printer ().println ("Class: " + fullyQualifiedName );
95- printer ().println ("Camel version: " + camelVersion );
96+ printer ().printDiagnostic ("Generating JSON Schema for component: " + camelComponent );
97+ printer ().printDiagnostic ("Class: " + fullyQualifiedName );
98+ printer ().printDiagnostic ("Camel version: " + camelVersion );
9699 }
97100
98101 // Validate inputs
@@ -137,7 +140,7 @@ public Integer doCall() throws Exception {
137140 outputSchema (schema );
138141
139142 if (verbose ) {
140- printer ().println ("Schema generation completed successfully" );
143+ printer ().printDiagnostic ("Schema generation completed successfully" );
141144 }
142145
143146 return 0 ;
@@ -181,12 +184,12 @@ private SchemaGeneratorConfig createSchemaGeneratorConfig(JacksonSchemaModule ja
181184 * @param verbose Whether to enable verbose logging
182185 * @return DependencyDownloaderClassLoader or null if failed
183186 */
184- private DependencyDownloaderClassLoader getDependencyDownloaderClassLoader (
187+ DependencyDownloaderClassLoader getDependencyDownloaderClassLoader (
185188 String camelComponent , String version , boolean verbose ) {
186189
187190 try {
188191 if (verbose ) {
189- printer ().println ("Creating dependency downloader class loader..." );
192+ printer ().printDiagnostic ("Creating dependency downloader class loader..." );
190193 }
191194
192195 DependencyDownloaderClassLoader cl = new DependencyDownloaderClassLoader (
@@ -199,7 +202,7 @@ private DependencyDownloaderClassLoader getDependencyDownloaderClassLoader(
199202 downloader .start ();
200203
201204 if (verbose ) {
202- printer ().println ("Downloading artifacts for camel-" + camelComponent + ":" + version );
205+ printer ().printDiagnostic ("Downloading artifacts for camel-" + camelComponent + ":" + version );
203206 }
204207
205208 List <MavenArtifact > artifacts = downloader .downloadArtifacts (
@@ -211,15 +214,15 @@ private DependencyDownloaderClassLoader getDependencyDownloaderClassLoader(
211214 if (artifacts == null || artifacts .isEmpty ()) {
212215 printer ().printErr (
213216 "Error: No artifacts found for component 'camel-" + camelComponent + "' version '" + version + "'" );
214- printer ().printErr ("Please verify that the component name is correct and the version exists." );
215- printer ().printErr ("Available components can be found at: https://camel.apache.org/components/" );
217+ printer ().printDiagnostic ("Please verify that the component name is correct and the version exists." );
218+ printer ().printDiagnostic ("Available components can be found at: https://camel.apache.org/components/" );
216219 IOHelper .close (cl );
217220 return null ;
218221 }
219222
220223 if (verbose ) {
221- printer ().println ("Downloaded " + artifacts .size () + " artifact(s)" );
222- artifacts .forEach (artifact -> printer ().println (" - " + artifact .getFile ().getName ()));
224+ printer ().printDiagnostic ("Downloaded " + artifacts .size () + " artifact(s)" );
225+ artifacts .forEach (artifact -> printer ().printDiagnostic (" - " + artifact .getFile ().getName ()));
223226 }
224227
225228 artifacts .forEach (artifact -> cl .addFile (artifact .getFile ()));
@@ -259,24 +262,25 @@ private DependencyDownloaderClassLoader getDependencyDownloaderClassLoader(
259262 private Class <?> loadTargetClass (ClassLoader classLoader , String className ) {
260263 try {
261264 if (verbose ) {
262- printer ().println ("Loading class: " + className );
265+ printer ().printDiagnostic ("Loading class: " + className );
263266 }
264267
265268 return classLoader .loadClass (className );
266269
267270 } catch (ClassNotFoundException e ) {
268271
269272 printer ().printErr ("Class '" + className + "' not found in component dependencies" );
270- printer ().printErr (System .lineSeparator ());
271- printer ().printErr ("Possible causes:" );
272- printer ().printErr (" - Class name is incorrect (check spelling and package)" );
273- printer ().printErr (" - Class is not part of the '" + camelComponent + "' component" );
274- printer ().printErr (" - Class is in a different artifact not included as dependency" );
275- printer ().printErr (System .lineSeparator ());
276- printer ().printErr ("To find available classes, you can:" );
277- printer ().printErr (" - Check the component documentation" );
278- printer ().printErr (" - Browse the Maven artifact at: https://mvnrepository.com/artifact/org/apache/camel/camel-"
279- + camelComponent );
273+ printer ().printDiagnostic ("" );
274+ printer ().printDiagnostic ("Possible causes:" );
275+ printer ().printDiagnostic (" - Class name is incorrect (check spelling and package)" );
276+ printer ().printDiagnostic (" - Class is not part of the '" + camelComponent + "' component" );
277+ printer ().printDiagnostic (" - Class is in a different artifact not included as dependency" );
278+ printer ().printDiagnostic ("" );
279+ printer ().printDiagnostic ("To find available classes, you can:" );
280+ printer ().printDiagnostic (" - Check the component documentation" );
281+ printer ().printDiagnostic (
282+ " - Browse the Maven artifact at: https://mvnrepository.com/artifact/org/apache/camel/camel-"
283+ + camelComponent );
280284
281285 if (verbose ) {
282286 e .printStackTrace ();
@@ -302,19 +306,19 @@ private Class<?> loadTargetClass(ClassLoader classLoader, String className) {
302306 private JsonNode generateSchema (SchemaGenerator generator , Class <?> targetClass ) {
303307 try {
304308 if (verbose ) {
305- printer ().println ("Generating schema for class: " + targetClass .getName ());
309+ printer ().printDiagnostic ("Generating schema for class: " + targetClass .getName ());
306310 }
307311
308312 return generator .generateSchema (targetClass );
309313
310314 } catch (Exception e ) {
311315 printer ().printErr ("Error generating schema for class '" + targetClass .getName () + "':" );
312- printer ().printErr (" " + e .getMessage ());
313- printer ().printErr ( System . lineSeparator () );
314- printer ().printErr ("This might be caused by:" );
315- printer ().printErr (" - Complex class structure that cannot be serialized" );
316- printer ().printErr (" - Missing dependencies for the class" );
317- printer ().printErr (" - Circular references in the class hierarchy" );
316+ printer ().printDiagnostic (" " + e .getMessage ());
317+ printer ().printDiagnostic ( "" );
318+ printer ().printDiagnostic ("This might be caused by:" );
319+ printer ().printDiagnostic (" - Complex class structure that cannot be serialized" );
320+ printer ().printDiagnostic (" - Missing dependencies for the class" );
321+ printer ().printDiagnostic (" - Circular references in the class hierarchy" );
318322
319323 if (verbose ) {
320324 e .printStackTrace ();
0 commit comments