Description
When comparing two OpenAPI specifications where a property's schema changes from:
- an
allOf composition referencing an array schema
- to a direct
type: array definition
openapi-diff throws a ClassCastException instead of reporting the schema difference.
Affected versions:
2.1.7
2.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: string
new.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: string
Command Used
docker run --rm -v "$(pwd):/specs" openapitools/openapi-diff:2.1.7 \
/specs/old.yml /specs/new.yml
Expected 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.
Description
When comparing two OpenAPI specifications where a property's schema changes from:
allOfcomposition referencing an array schematype: arraydefinitionopenapi-diffthrows aClassCastExceptioninstead of reporting the schema difference.Affected versions:
2.1.72.1.0-beta.11(also reproducible)Error
Minimal Reproduction
old.ymlnew.ymlCommand Used
docker run --rm -v "$(pwd):/specs" openapitools/openapi-diff:2.1.7 \ /specs/old.yml /specs/new.ymlExpected Behavior
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:
ComposedSchemaArraySchemaThe cast fails, resulting in a crash instead of a diff result.