swagger-api / swagger-parser

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

No mechanism to override codePointLimit in org.yaml.SnakeYaml.LoaderOptions #1871

Closed AmateurECE closed 1 year ago

AmateurECE commented 1 year ago

Some OpenAPI documents, like the Redfish specification developed by DMTF, are larger than the default 3MiB limit set on input file size in org.yaml.SnakeYaml package. Users should have the opportunity to override this limit using the codePointLimit member in the org.yaml.SnakeYaml.LoaderOptions class, to avoid a YAMLException like the one below while running downstream code generation projects, like openapi-generator-cli.

/usr/lib/sdk/openjdk8/jvm/java-8-openjdk/bin/java -DmaxYamlCodePoints=5138022 -Dfile.encoding=UTF-8 -jar /home/edtwardy/Git/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g rust-server -o redfish-models -i openapi/openapi.yaml
[main] WARN  i.s.v.p.util.DeserializationUtils - Error snake-parsing yaml content
io.swagger.v3.parser.util.DeserializationUtils$SnakeException: Exception safe-checking yaml content  (maxDepth 2000, maxYamlAliasesForCollections 2147483647)
    at io.swagger.v3.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:438)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:477)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:406)
    at io.swagger.v3.parser.util.DeserializationUtils.readYamlTree(DeserializationUtils.java:211)
    at io.swagger.v3.parser.util.DeserializationUtils.deserializeIntoTree(DeserializationUtils.java:143)
    at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:165)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:94)
    at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
    at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:589)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:647)
    at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
    at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: org.yaml.snakeyaml.error.YAMLException: The incoming YAML document exceeds the limit: 3145728 code points.
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:342)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:263)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:662)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:185)
    at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:57)
    at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:43)
    at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:136)
    at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:116)
    at org.yaml.snakeyaml.composer.Composer.composeScalarNode(Composer.java:239)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:208)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:357)
    at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:336)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:311)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:212)
    at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:134)
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:160)
    at io.swagger.v3.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:415)
    ... 12 common frames omitted