Skip to content

[BUG][JAVA] StackOverflowError in ExampleGenerator due to circular allOf references #23966

@ainGitHub

Description

@ainGitHub

When processing OpenAPI schemas with circular allOf references, the ExampleGenerator throws a StackOverflowError due to infinite recursion between traverseSchemaProperties and resolveAllOfSchemaProperties methods.

Attach changed original 3.0/example_generator_test.yaml from core of project
example_generator_test.yaml

Simple example

    ExampleAllOfRecursionSchema:
      type: object
      allOf:
        - $ref: '#/components/schemas/ExampleAllOfRecursionSchema'
        - type: object
          properties:
            example_schema_property_composed_parent:
              type: string
              example: example schema property value composed parent

Stack Trace

java.lang.StackOverflowError
	at org.openapitools.codegen.utils.ModelUtils.isAllOf(ModelUtils.java:2286)
	at org.openapitools.codegen.examples.ExampleGenerator.traverseSchemaProperties(ExampleGenerator.java:394)
	at org.openapitools.codegen.examples.ExampleGenerator.resolveAllOfSchemaProperties(ExampleGenerator.java:410)
	at org.openapitools.codegen.examples.ExampleGenerator.traverseSchemaProperties(ExampleGenerator.java:395)
	at org.openapitools.codegen.examples.ExampleGenerator.resolveAllOfSchemaProperties(ExampleGenerator.java:415)
	at org.openapitools.codegen.examples.ExampleGenerator.traverseSchemaProperties(ExampleGenerator.java:395)
	at org.openapitools.codegen.examples.ExampleGenerator.resolveAllOfSchemaProperties(ExampleGenerator.java:415)
	at org.openapitools.codegen.examples.ExampleGenerator.traverseSchemaProperties(ExampleGenerator.java:395)

Additional Context
OpenAPI Generator version: 7.23.0-SNAPSHOT
Java version: Java 17 (in any version)
The issue is reproducible with any OpenAPI spec containing circular allOf references

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions