You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/03/17 18:43:58 UTC

[camel] 03/03: CAMEL-19130: camel-restdsl-openapi-plugin - Upgrade to snakeyaml 2.x

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-19130/upgrade-snakeyaml-2
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 85ee8676a9c2213f47f602f0b6cb1516b12cea7a
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Mar 17 19:43:24 2023 +0100

    CAMEL-19130: camel-restdsl-openapi-plugin - Upgrade to snakeyaml 2.x
---
 .../maven/generator/openapi/AbstractGenerateMojo.java     | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tooling/maven/camel-restdsl-openapi-plugin/src/main/java/org/apache/camel/maven/generator/openapi/AbstractGenerateMojo.java b/tooling/maven/camel-restdsl-openapi-plugin/src/main/java/org/apache/camel/maven/generator/openapi/AbstractGenerateMojo.java
index 545b44847e2..4498f07a207 100644
--- a/tooling/maven/camel-restdsl-openapi-plugin/src/main/java/org/apache/camel/maven/generator/openapi/AbstractGenerateMojo.java
+++ b/tooling/maven/camel-restdsl-openapi-plugin/src/main/java/org/apache/camel/maven/generator/openapi/AbstractGenerateMojo.java
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -56,8 +57,10 @@ import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
 import org.twdata.maven.mojoexecutor.MojoExecutor;
+import org.yaml.snakeyaml.LoaderOptions;
 import org.yaml.snakeyaml.Yaml;
 import org.yaml.snakeyaml.constructor.SafeConstructor;
+import org.yaml.snakeyaml.inspector.TrustedTagInspector;
 
 import static org.apache.commons.lang3.StringUtils.isNotEmpty;
 import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
@@ -172,8 +175,8 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
 
         final DestinationGenerator destinationGeneratorObject;
         try {
-            destinationGeneratorObject = destinationGeneratorClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+            destinationGeneratorObject = destinationGeneratorClass.getDeclaredConstructor().newInstance();
+        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
             throw new MojoExecutionException(
                     "The given destinationGenerator class (" + destinationGenerator
                                              + ") cannot be instantiated, make sure that it is declared as public and that all dependencies are present on the COMPILE classpath scope of the project",
@@ -226,7 +229,7 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
                         version(swaggerCodegenMavenPluginVersion)),
                 goal("generate"),
                 configuration(
-                        elements.toArray(new MojoExecutor.Element[elements.size()])),
+                        elements.toArray(new MojoExecutor.Element[0])),
                 executionEnvironment(
                         mavenProject,
                         mavenSession,
@@ -243,7 +246,7 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         for (final Dependency dep : mavenProject.getDependencies()) {
             if ("org.apache.camel".equals(dep.getGroupId()) || "org.apache.camel.springboot".equals(dep.getGroupId())) {
                 final String aid = dep.getArtifactId();
-                final Optional<String> comp = Arrays.asList(DEFAULT_REST_CONSUMER_COMPONENTS).stream()
+                final Optional<String> comp = Arrays.stream(DEFAULT_REST_CONSUMER_COMPONENTS)
                         .filter(c -> aid.startsWith("camel-" + c)).findFirst();
                 if (comp.isPresent()) {
                     return comp.get();
@@ -340,7 +343,9 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
 
         String suffix = ".yaml";
         if (specificationUri.regionMatches(true, specificationUri.length() - suffix.length(), suffix, 0, suffix.length())) {
-            Yaml loader = new Yaml(new SafeConstructor());
+            LoaderOptions options = new LoaderOptions();
+            options.setTagInspector(new TrustedTagInspector());
+            Yaml loader = new Yaml(new SafeConstructor(options));
             Map map = loader.load(is);
             JsonNode node = mapper.convertValue(map, JsonNode.class);
             return (OasDocument) Library.readDocument(node);