Skip to content

Fix ClassCastException when allOf array changes to type array - #916

Merged
DrSatyr merged 2 commits into
OpenAPITools:masterfrom
kamilkrzywanski:fix/887-allof-array-classcastexception
Aug 5, 2026
Merged

Fix ClassCastException when allOf array changes to type array#916
DrSatyr merged 2 commits into
OpenAPITools:masterfrom
kamilkrzywanski:fix/887-allof-array-classcastexception

Conversation

@kamilkrzywanski

@kamilkrzywanski kamilkrzywanski commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #887

When a property changes from allOf wrapping an array schema to a direct type: array, the left side stays a ComposedSchema after resolution while the right side is an ArraySchema. Casting both to ArraySchema threw ClassCastException.

Changes:

  • copy items when merging composed schemas in addSchema
  • use Schema#getItems() in ArraySchemaDiffResult instead of casting
  • add regression test from the issue repro

Summary by cubic

Fixes a crash when diffing array schemas that change from an allOf-wrapped array to a direct type: array. Prevents ClassCastException and ensures the specs compare equal.

  • Bug Fixes
    • Copy items in addSchema when merging composed schemas.
    • Use Schema#getItems() in ArraySchemaDiffResult instead of casting.
    • Strengthen regression: assert no exception and that both specs are equal.

Written for commit 99b2f79. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread core/src/test/java/org/openapitools/openapidiff/core/Issue887Test.java Outdated
Assert the allOf-array and direct-array specs compare equal instead of
only checking isCompatible(), which is also true for no changes.

@DrSatyr DrSatyr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — the fix is correct and the core suite passes locally against this branch (269 tests, 0 failures).

One note for the record: testDirectArrayToAllOfArrayDoesNotThrow covers the opposite direction but asserts only that no exception is thrown. That direction currently reports a false breaking change (array -> array), which is pre-existing and out of scope here. Tracked in #920 — the test should become assertOpenApiAreEquals once that's fixed.

Thanks for the fix and the regression test!

@DrSatyr
DrSatyr merged commit bcf097c into OpenAPITools:master Aug 5, 2026
7 checks passed
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.

ClassCastException when comparing schema changed from allOf to direct array type

2 participants