Skip to content

ClassCastException when comparing schema changed from allOf to direct array type #887

@omarsy

Description

@omarsy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions