Skip to content

[BUG] [GO] Stack Overflow when cycle present in spec #13714

@AniketK-Crest

Description

@AniketK-Crest

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have provided a minimal version of the schema below with what I am facing the issue. In a way, it is similar to #4904. It works fine if I remove one of the items from AllOf from any attribute or remove the discriminator. However, I do not own the schema so it would not be possible for me to modify it.

Below is the error that I am getting:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'Type'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:518)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:912)
        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: java.lang.RuntimeException: Stack overflow hit when looking for Type an infinite loop starting and ending at ResponseDetails was seen
        at org.openapitools.codegen.DefaultCodegen.getAllOfDescendants(DefaultCodegen.java:3351)
        at org.openapitools.codegen.DefaultCodegen.createDiscriminator(DefaultCodegen.java:3420)
        at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:2906)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1291)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:513)
        ... 4 more
openapi-generator version

6.2.0

OpenAPI declaration file content
{
    "openapi": "3.0.0",
    "info": {
        "title": "Recursion Bug",
        "version": "2.0.0"
    },
    "paths": {},
    "components": {
        "schemas": {
            "Type": {
                "type": "object",
                "properties": {
                    "Type": { "type": "string" }
                },
                "discriminator": {
                    "propertyName": "Type",
                    "mapping": { "something": "#/components/schemas/CreationDetails" }
                }
            },
            "CreationDetails": {
                "allOf": [
                    { "$ref": "#/components/schemas/Type" }
                ]
            },
            "UpdateDetails": {
                "allOf": [
                    { "$ref": "#/components/schemas/CreationDetails" }
                ]
            },
            "ResponseDetails": {
                "allOf": [
                    { "$ref": "#/components/schemas/CreationDetails" },
                    { "$ref": "#/components/schemas/UpdateDetails" }
                ]
            }
        }
    }
}
Generation Details
Steps to reproduce
openapi-generator-cli generate -i https://gist.githubusercontent.com/AniketK-Crest/06c5248a2d1f34bc544c9ce758e7d2e3/raw/14e024cba487ccc8a2d682918ebfbd4792e6b96a/recursion-bug.json -g go -o ./Generated/recursion-bug-go-client
Related issues/PRs

#4904
#4906
#5229

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions