-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Open
Copy link
Milestone
Description
Description
When comparing two OpenAPI specifications where a property's schema changes from:
- an
allOfcomposition referencing an array schema - to a direct
type: arraydefinition
openapi-diff throws a ClassCastException instead of reporting the schema difference.
Affected versions:
2.1.72.1.0-beta.11(also reproducible)
Error
Unexpected exception. Reason: class io.swagger.v3.oas.models.media.ComposedSchema
cannot be cast to class io.swagger.v3.oas.models.media.ArraySchema
java.lang.ClassCastException: class io.swagger.v3.oas.models.media.ComposedSchema
cannot be cast to class io.swagger.v3.oas.models.media.ArraySchema
at org.openapitools.openapidiff.core.compare.schemadiffresult.ArraySchemaDiffResult.diff(ArraySchemaDiffResult.java:25)
at org.openapitools.openapidiff.core.compare.SchemaDiff.computeDiffForReal(SchemaDiff.java:357)
...
Minimal Reproduction
old.yml
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
components:
schemas:
TestResponse:
type: object
properties:
valuations:
allOf:
- $ref: '#/components/schemas/Valuations'
Valuations:
type: array
items:
type: object
properties:
value:
type: stringnew.yml
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
components:
schemas:
TestResponse:
type: object
properties:
valuations:
type: array
items:
$ref: '#/components/schemas/Valuation'
Valuation:
type: object
properties:
value:
type: stringCommand Used
docker run --rm -v "$(pwd):/specs" openapitools/openapi-diff:2.1.7 \
/specs/old.yml /specs/new.ymlExpected Behavior
- The tool should detect the schema change.
- It should classify the change as compatible or incompatible.
- It should not crash.
Actual Behavior
The tool throws a ClassCastException.
It appears the comparison logic assumes both schemas being compared are of the same concrete type. In this case:
- Old schema →
ComposedSchema - New schema →
ArraySchema
The cast fails, resulting in a crash instead of a diff result.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels