diff --git a/pom.xml b/pom.xml
index 4fee441..fc2aace 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,6 +50,14 @@
jackson-dataformat-yaml${jackson.version}
+
+
+ org.yaml
+ snakeyaml
+ 2.3
+
diff --git a/src/main/java/io/floci/cli/commands/config/ConfigValidateCommand.java b/src/main/java/io/floci/cli/commands/config/ConfigValidateCommand.java
index d792f94..af11486 100644
--- a/src/main/java/io/floci/cli/commands/config/ConfigValidateCommand.java
+++ b/src/main/java/io/floci/cli/commands/config/ConfigValidateCommand.java
@@ -1,8 +1,6 @@
package io.floci.cli.commands.config;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.floci.cli.GlobalOptions;
import io.floci.cli.ProductProfile;
import io.floci.cli.output.Ansi;
@@ -26,8 +24,6 @@ import java.util.concurrent.Callable;
)
public class ConfigValidateCommand implements Callable {
- private static final ObjectMapper YAML = new ObjectMapper(new YAMLFactory());
-
protected final ProductProfile profile;
private final boolean dockerSockRequired;
private final String dockerSockNeededFor;
@@ -71,7 +67,7 @@ public class ConfigValidateCommand implements Callable {
JsonNode compose = null;
String unreadable = null;
try {
- compose = YAML.readTree(content);
+ compose = YamlTree.read(content);
if (compose == null || !compose.isObject()) {
unreadable = "Could not read " + composeFile + " as a Compose file: it has no top-level mapping";
}
diff --git a/src/main/java/io/floci/cli/commands/config/YamlTree.java b/src/main/java/io/floci/cli/commands/config/YamlTree.java
new file mode 100644
index 0000000..0ccd82f
--- /dev/null
+++ b/src/main/java/io/floci/cli/commands/config/YamlTree.java
@@ -0,0 +1,45 @@
+package io.floci.cli.commands.config;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.MissingNode;
+import org.yaml.snakeyaml.LoaderOptions;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.SafeConstructor;
+import org.yaml.snakeyaml.error.YAMLException;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * Reads a YAML document into a tree with its anchors, aliases and merge keys resolved, the way a
+ * YAML consumer such as Compose sees it. Jackson's own {@code readTree} leaves them unresolved:
+ * {@code volumes: *common} arrives as the string "common" and {@code <<: *base} as a field named
+ * {@code <<}, so a service built from an anchor looks empty. Its parser also drops anchors on
+ * scalars ({@code image: &img ...}), so they cannot be resolved on top of it either; SnakeYAML,
+ * which Jackson's YAML module is built on, does all three.
+ */
+public final class YamlTree {
+
+ private static final ObjectMapper TREES = new ObjectMapper();
+
+ private YamlTree() {}
+
+ /**
+ * The first document of {@code yaml}; a missing node for an empty one.
+ *
+ * @throws IOException when the text is not YAML, with a one-line reason
+ */
+ public static JsonNode read(String yaml) throws IOException {
+ try {
+ // SafeConstructor builds only maps, lists and scalars, never arbitrary classes, and the
+ // default LoaderOptions bound how far aliases may expand.
+ Iterator