Skip to content

fix: detect property type changes on referenced component schemas in OpenAPI 3.1 - #938

Open
Inf1mum wants to merge 2 commits into
OpenAPITools:masterfrom
Inf1mum:fix/910-31-type-change
Open

Inf1mum wants to merge 2 commits into
OpenAPITools:masterfrom
Inf1mum:fix/910-31-type-change

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #910

Problem

In OpenAPI 3.1 documents, a type change on a property of a referenced component schema was silently ignored: getChangedOperations() and getChangedSchemas() came back empty. The identical 3.0 change is detected as INCOMPATIBLE.

Root cause

swagger-parser deserializes 3.1 schemas into JsonSchema where the type keyword lives in the types set (Schema#getTypes()) and Schema#getType() returns null; the gate in SchemaDiff#computeDiffForReal compared only getType() — null vs null for 3.1 — and never fired.

Fix

Compare the effective type set (union of getType() and getTypes()). For 3.1 the union is the type carrier, so changes are detected; 3.0 typed schemas populate both, so nothing changes; 3.0 composed schemas merged from allOf/anyOf (SchemaDiff#addSchema copies only type) keep comparing as before (AllOfDiffTest / Issue887Test confirm no regression). The reused 3.0 getTypeChangedSchema path keeps classification identical: changedType=true, reported INCOMPATIBLE.

Tests

SchemaDiffTest#schemaPropertyTypeChanged31 uses the issue spec (Widget.properties.weight.type integer → string, openapi: 3.1.0; fixtures schema-props-type-handling-3.1-1.yaml / -2.yaml). Failed before (changedOperations expected 1, was 0), passes after.

Scope notes

  • format changes in 3.1 are already detected; no other attribute shares the types gap.
  • Multi-type keywords (type: [integer, string]) are compared as sets, so reordering produces no false change.

Summary by cubic

Fixes #910. Property type changes on referenced component schemas in OpenAPI 3.1 documents were silently ignored — getChangedOperations() and getChangedSchemas() returned empty. The type-change gate now compares the effective type set (union of getType() and getTypes(), which OpenAPI 3.1 deserialization populates), so these changes are detected and classified as INCOMPATIBLE, matching OpenAPI 3.0 behavior.

  • Dropped the raw getType() comparison so equivalent schemas with the same effective type no longer report a false change.
  • resolveComposedSchema now flattens allOf/anyOf on any schema (3.1 compositions deserialize into JsonSchema, not ComposedSchema) and addSchema propagates getTypes(), so composed schemas keep their effective types.
  • Added the schemaPropertyTypeChanged31 regression test with the issue's spec pair, asserting the INCOMPATIBLE classification.

Written for commit 1d82249. Summary will update on new commits.

View guided diff

…OpenAPI 3.1

In OpenAPI 3.1 documents swagger-parser deserializes schemas into
JsonSchema instances where the type keyword is stored in the types set
and Schema#getType() returns null. The type-change gate in
SchemaDiff#computeDiffForReal only compared getType(), so a type change
on a property of a referenced component schema was silently ignored
(OpenAPI 3.0 detected the same change as INCOMPATIBLE via
getTypeChangedSchema/changedType).

Compare the effective type set (union of getType() and getTypes())
instead of the raw getType() string. This covers the 3.1 representation
and keeps the existing behavior for 3.0 schemas, where typed concrete
schemas carry both type and types while composed schemas merged from
their allOf/anyOf children carry only type.

Fixes OpenAPITools#910

@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 4 files

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

View guided diff | Re-trigger cubic

… composed schemas

The type-change gate in SchemaDiff#computeDiffForReal compared the raw
getType() before the effective type set, so an OpenAPI 3.0 schema (type
set) and an equivalent OpenAPI 3.1 JsonSchema (type null, types set)
describing the same effective type were reported as an INCOMPATIBLE
type change. Compare only the effective type sets (union of getType()
and getTypes()).

The effective set is computed after resolveComposedSchema, which
flattened only ComposedSchema instances and whose addSchema copied only
getType(). OpenAPI 3.1 compositions are deserialized into JsonSchema,
which does not extend ComposedSchema, so 3.1 allOf/anyOf members were
never merged and flattened schemas carried an empty effective type set:
equivalent composed and direct schemas were reported as a type change,
while real type changes between composed schemas were missed. Merge
members from any schema carrying allOf/anyOf on the shared base Schema
(swagger-models 2.2.x) and propagate getTypes() as well, so flattened
schemas keep their effective types.

Also assert the INCOMPATIBLE classification in the issue OpenAPITools#910
regression test.
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.

Property type change on referenced component schema is silently ignored

1 participant