swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
773 stars 525 forks source link

maxAliasesForCollections cannot be set for snakeyaml #2073

Closed msupic closed 3 months ago

msupic commented 3 months ago

The snakeyaml library throws the following exception when the number of aliases exceeds the value from maxAliasesForCollections property of the org.yaml.snakeyaml.LoaderOptions.

org.yaml.snakeyaml.error.YAMLException: Number of aliases for non-scalar nodes exceeds the specified max=50
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:190)

The maxAliasesForCollections value can be changed by providing custom LoaderOptions instance when creating org.yaml.snakeyaml.Yaml instance using the following constructor:

  public Yaml(LoaderOptions loadingConfig) {
    this(new Constructor(loadingConfig), new Representer(new DumperOptions()), new DumperOptions(),
        loadingConfig);
  }

but the swagger-parser doesn't provide a way to use custom LoaderOptions instance when reading yaml

    public static JsonNode readYamlTree(String contents) {
        org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
        return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
    }
msupic commented 3 months ago

Using old swagger-parser version (1.0.20)