Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ public static JsonNode readYamlTree(String contents) {
}
public static JsonNode readYamlTree(String contents, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult) {

LoaderOptions loaderOptions = new LoaderOptions();
if (parseOptions != null && parseOptions.isLegacyYamlDeserialization()) {
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor(loaderOptions));
return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
}
try {
org.yaml.snakeyaml.Yaml yaml = null;
if (options.isValidateYamlInput()) {
yaml = buildSnakeYaml(new CustomSnakeYamlConstructor());
yaml = buildSnakeYaml(new CustomSnakeYamlConstructor(loaderOptions));
} else {
yaml = buildSnakeYaml(new SafeConstructor());
yaml = buildSnakeYaml(new SafeConstructor(loaderOptions));
}
Object o = yaml.load(contents);
if (options.isValidateYamlInput()) {
Expand Down Expand Up @@ -244,7 +245,8 @@ public static <T> T readYamlValue(String contents, Class<T> expectedType) {
return readYamlValue(contents, expectedType, false);
}
public static <T> T readYamlValue(String contents, Class<T> expectedType, boolean openapi31) {
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
LoaderOptions loaderOptions = new LoaderOptions();
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor(loaderOptions));
ObjectMapper jsonMapper = openapi31 ? Json31.mapper() : Json.mapper();
return jsonMapper.convertValue(yaml.load(contents), expectedType);
}
Expand All @@ -255,8 +257,14 @@ public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor
} catch (NoSuchMethodException e) {
return new org.yaml.snakeyaml.Yaml(constructor);
}
LoaderOptions loaderOptions;
try {
Method method = BaseConstructor.class.getMethod("getLoadingConfig");
loaderOptions = (LoaderOptions) method.invoke(constructor);
} catch (ReflectiveOperationException e) {
loaderOptions = new LoaderOptions();
}
try {
LoaderOptions loaderOptions = new LoaderOptions();
Method method = LoaderOptions.class.getMethod("setMaxAliasesForCollections", int.class);
method.invoke(loaderOptions, options.getMaxYamlAliasesForCollections());
method = LoaderOptions.class.getMethod("setAllowRecursiveKeys", boolean.class);
Expand All @@ -265,7 +273,8 @@ public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor
method.invoke(loaderOptions, false);
method = LoaderOptions.class.getMethod("setCodePointLimit", int.class);
method.invoke(loaderOptions, options.getMaxYamlCodePoints());
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(), new DumperOptions(), loaderOptions, new CustomResolver());
DumperOptions dumperOptions = new DumperOptions();
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(dumperOptions), dumperOptions, loaderOptions, new CustomResolver());
return yaml;
} catch (ReflectiveOperationException e) {
//
Expand Down Expand Up @@ -396,6 +405,10 @@ public SnakeException(String message, Throwable cause) {

static class CustomSnakeYamlConstructor extends SafeConstructor {

private CustomSnakeYamlConstructor(LoaderOptions loaderOptions) {
super(loaderOptions);
}

private boolean checkNode(MappingNode node, Integer depth) {
if (node.getValue() == null) return true;
if (depth > options.getMaxYamlDepth()) return false;
Expand Down