debugSupportingFiles causes Infinite recursion
Created by: matteomazza91
Description
the option debugSupportingFiles
causes a com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)
exception.
This only occurs if a Model-schema reference another model-schema
As (part of) the stack trace point out, the CodegenModel
has a "parentModel" property that cause the infinite recursion:
[main] INFO org.openapitools.codegen.DefaultGenerator - ############ Supporting file info ############
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.openapitools.codegen.CodegenModel["parentModel"]->org.openapitools.codegen.CodegenModel["children"]->java.util.ArrayList[0]->org.openapitools.codegen.CodegenModel["parentModel"]->org.openapitools.codegen.CodegenModel["children"]->java.util.ArrayList[0]->org.openapitools.codegen.CodegenModel["parentModel"]->org.openapitools.codegen.CodegenModel["children"]->java.util.ArrayList[0]->org.openapitools.codegen.CodegenModel["parentModel"]->org.openapitools.codegen.CodegenModel["children"]->java.util.ArrayList[0]->org.openapitools.codegen.CodegenModel["parentModel"]
openapi-generator version
OpenAPI declaration file content or url
This is the OpenAPI that generates the issue: https://pastebin.com/c5tQgWQ9
Note: if the line - $ref: "#/components/schemas/UserDetail"
is removed from the User schema, the exception is not raised.
Command line used for generation
java -jar openapi-generator-cli.jar generate -i /path/to/input.yaml -g java -o test/client/petsore/java -DdebugSupportingFiles=true
Steps to reproduce
- create the file
/path/to/input.yaml
with the content of https://pastebin.com/c5tQgWQ9 - run
java -jar openapi-generator-cli.jar generate -i /path/to/input.yaml -g java -o test/client/petsore/java -DdebugSupportingFiles=true
Suggest a fix/enhancement
the call to the debugging method is present in the buildSupportFileBundle
method of org.openapitools.codegen.DefaultGenerator
class
if (System.getProperty("debugSupportingFiles") != null) {
LOGGER.info("############ Supporting file info ############");
Json.prettyPrint(bundle);
}