You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/06/14 06:01:26 UTC
[camel] branch main updated: CAMEL-19453: camel-jbang - Run with --open-api to support yaml spec files
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new b7d31ad2c5a CAMEL-19453: camel-jbang - Run with --open-api to support yaml spec files
b7d31ad2c5a is described below
commit b7d31ad2c5aed34c5778c80e9c022f43e464bf1b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jun 14 08:01:10 2023 +0200
CAMEL-19453: camel-jbang - Run with --open-api to support yaml spec files
---
.../org/apache/camel/dsl/jbang/core/commands/Run.java | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 302e843431b..9862d46300e 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -22,6 +22,7 @@ import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -46,6 +47,7 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import io.apicurio.datamodels.Library;
import io.apicurio.datamodels.openapi.models.OasDocument;
import org.apache.camel.CamelContext;
@@ -216,7 +218,7 @@ public class Run extends CamelCommand {
@Option(names = { "--modeline" }, defaultValue = "true", description = "Enables Camel-K style modeline")
boolean modeline = true;
- @Option(names = { "--open-api" }, description = "Adds an OpenAPI spec from the given file")
+ @Option(names = { "--open-api" }, description = "Adds an OpenAPI spec from the given file (json or yaml file)")
String openapi;
@Option(names = { "--code" }, description = "Run the given string as Java DSL route")
@@ -956,8 +958,19 @@ public class Run extends CamelCommand {
}
private void generateOpenApi() throws Exception {
- final ObjectMapper mapper = new ObjectMapper();
- final JsonNode node = mapper.readTree(Paths.get(openapi).toFile());
+ File file = Paths.get(openapi).toFile();
+ if (!file.exists() && !file.isFile()) {
+ throw new FileNotFoundException("Cannot find file: " + file);
+ }
+
+ ObjectMapper mapper;
+ boolean yaml = file.getName().endsWith(".yaml") || file.getName().endsWith(".yml");
+ if (yaml) {
+ mapper = new YAMLMapper();
+ } else {
+ mapper = new ObjectMapper();
+ }
+ JsonNode node = mapper.readTree(file);
OasDocument document = (OasDocument) Library.readDocument(node);
RuntimeUtil.setRootLoggingLevel("off");
try {