Skip to content

#4852 Unit test and fix to allow recursive models to process without StackOverflow - #5004

Merged
ewaostrowska merged 8 commits into
swagger-api:masterfrom
Yaytay:#4852
Nov 7, 2025
Merged

#4852 Unit test and fix to allow recursive models to process without StackOverflow #5004
ewaostrowska merged 8 commits into
swagger-api:masterfrom
Yaytay:#4852

Conversation

@Yaytay

@Yaytay Yaytay commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Pull Request

Description

Bug fix ton undo a tiny part of v2.2.27...v2.2.28#diff-bed6aab5e29942b1a575bded333604f9dfaeb2ef9475f1433266ece4e49f4fcb that introduced a StackOverflow exception on recursive data models with OpenAPI 3.1.

Fixes: #4852

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

@ewaostrowska

Copy link
Copy Markdown
Contributor

hi @Yaytay ,
Thanks for providing this PR. It does help with the issue reported in the #4852 and pointing this spot is already quite helpful for us. Unfortunately we cannot merge this PR yet.

One issue that I see here is that the test ReaderTest.testArraySchemaImplementation is failing with

expected [openapi: 3.1.0
paths:
      items:
        type: number
]

This indicates that items are not resolved correctly after the change.
We need to investigate further on why this boolean property has been added to AnnotationsUtils.getArraySchema.

That extra true argument in 2.2.28 wasn't random — it was almost certainly introduced to fix some other array-handling edge case in the OpenAPI 3.1 path (for example, making sure annotated @ArraySchema metadata such as minItems, uniqueItems, description, proper items resolution, etc., is actually reflected in the generated schema for arrays of complex/polymorphic types).

We need to verify as well how does it influence the OAS 3.x schema as well.

Thanks again for your contribution! We're happy to see any updates from you on this topic :)

@Yaytay

Yaytay commented Oct 31, 2025

Copy link
Copy Markdown
Contributor Author

My apologies for making this a PR when the unit tests fail - I didn't realise the tests in the other module were affected, entirely my bad.

What I don't understand is why there would be any circumstances in which you'd want to reset the ModelConverterContext while processing a single model.
Actually there's a lot I don't understand about swagger-core :)

I've updated the PR so that it tracks the AnnotatedTypes that it is currently resolving.
This enables it to explicitly pass "false" in my circumstances, but otherwise retain the "true" argument.
At least locally this makes all tests in swagger-project pass.

@ewaostrowska

Copy link
Copy Markdown
Contributor

@Yaytay,
Thanks for introducing the changes to the PR! The solution looks better now and it also the test ReaderTest.testArraySchemaImplementation is not failing anymore. I have done some clean up both in tests and ModelResolver, but the core of the logic was correct and solves the issue without reintroducing regression. And yes, logic of swagger-core and especially ModelResolver can be quite challenging to understand :)

Thanks for your contribution!

@ewaostrowska
ewaostrowska merged commit 0a5556a into swagger-api:master Nov 7, 2025
5 checks passed
ewaostrowska pushed a commit to seonwooj0810/swagger-core that referenced this pull request Jul 22, 2026
…entation processing (swagger-api#5187)

`AnnotationsUtils.getArraySchema(...)` is called with
`processSchemaImplementation = false` whenever the cycle guard added in
swagger-api#5004 detects that the array's annotated type is already being resolved
further up the stack. In that branch the existing `setItems(...)` paths
are skipped, so the resulting array schema ends up with no `items` field
at all — degrading to `type: array` (and in deeper cycles getting
dropped entirely by downstream pruning).

The implementation class itself has already been (or will be) registered
in the `ModelConverterContext`, so we can recover a valid schema by
emitting a `$ref` to that registered component. This preserves the
StackOverflow fix while restoring `items: { $ref: ... }` for the
recursive case.

The lookup honours an explicit `@Schema(name = "...")` declaration on
the implementation type and otherwise falls back to the simple class
name (matching the default Jackson convention used elsewhere in
swagger-core). If neither is registered we leave `items` unset, so the
fallback is purely additive — schemas that already populated `items`
through other paths are not modified.
ewaostrowska pushed a commit that referenced this pull request Jul 22, 2026
…entation processing (#5187) (#5205)

`AnnotationsUtils.getArraySchema(...)` is called with
`processSchemaImplementation = false` whenever the cycle guard added in
#5004 detects that the array's annotated type is already being resolved
further up the stack. In that branch the existing `setItems(...)` paths
are skipped, so the resulting array schema ends up with no `items` field
at all — degrading to `type: array` (and in deeper cycles getting
dropped entirely by downstream pruning).

The implementation class itself has already been (or will be) registered
in the `ModelConverterContext`, so we can recover a valid schema by
emitting a `$ref` to that registered component. This preserves the
StackOverflow fix while restoring `items: { $ref: ... }` for the
recursive case.

The lookup honours an explicit `@Schema(name = "...")` declaration on
the implementation type and otherwise falls back to the simple class
name (matching the default Jackson convention used elsewhere in
swagger-core). If neither is registered we leave `items` unset, so the
fallback is purely additive — schemas that already populated `items`
through other paths are not modified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverflowError with recursive data model introduced with version 2.2.28

4 participants