softwaremill / sttp-apispec

OpenAPI, AsyncAPI and JSON Schema Scala models.
Apache License 2.0
23 stars 11 forks source link

SchemaComparator #157

Closed ghik closed 4 months ago

ghik commented 4 months ago

Required for https://github.com/softwaremill/tapir/issues/3645

SchemaComparator compares two schemas for compatibility and returns a list of SchemaCompatibilityIssues.

Currently, the comparator only understands a fixed set of common schema patterns, likely to be generated by tapir from common Scala types:

The following JSON Schema keywords are currently not understood at all:

If schemas don't fall into any of the above categories, or contain any of the mentioned unsupported keywords, they are considered opaque and compared only for plain equality (with annotations stripped). If they are not equal a generic "fallback" error is returned that indicates SchemaComparator's inability to determine compatibility between schemas (they may or may not be compatible).

adamw commented 4 months ago

The most important missing feature is comparison of undiscriminated unions expressed with anyOf or oneOf - this is tricky because matching elements of anyOf/oneOf between two schemas can turn into a combinatorial explosion of comparisons.

Let's start with the simplest thing that works, and then we can refine :) I think for a start a very simplistic matching of schemas listed in anyOf will work (for each each schema on the left, there is a compatible schema on the right).

adamw commented 4 months ago

Nice work - well beyond what I imagined originally, but very thorough :).