SchemaComparator

sttp.apispec.validation.SchemaComparator
See theSchemaComparator companion object
class SchemaComparator(writerNamedSchemas: Map[String, Schema], readerNamedSchemas: Map[String, Schema])

Utility for comparing schemas for compatibility. See compare for more details.

Since this class contains a cache of comparison results, it is meant to be reused between multiple schema comparisons.

Value parameters

readerNamedSchemas

named schemas which may be referred to by the reader schema

writerNamedSchemas

named schemas which may be referred to by the writer schema

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def compare(writerSchema: SchemaLike, readerSchema: SchemaLike): List[SchemaCompatibilityIssue]

Compares two schemas for compatibility. More precisely, checks if data that is valid according to writerSchema is also valid according to readerSchema. If not, a list of compatibility issues is returned.

Compares two schemas for compatibility. More precisely, checks if data that is valid according to writerSchema is also valid according to readerSchema. If not, a list of compatibility issues is returned.

Determining compatibility (or incompatibility) of arbitrary schemas with certainty is non-trivial, or outright impossible in general. For this reason, this method works in a "best effort" manner, assuming that the schemas match one of the typical schema patterns generated by libraries like tapir. In more complex situations, the comparator simply falls back to comparing schemas by plain equality, or returns a GeneralSchemaMismatch, which indicates comparator's inability to definitely determine compatibility or incompatibility of the schemas.

In practice, the comparator is designed to detect typical changes that may appear in schemas during API evolution, e.g. adding new fields, changing types, etc.

Before being compared, all schemas are stripped of keywords which do not affect the comparison, e.g. annotations like title, description, etc.

Value parameters

readerSchema

schema of the data being read

writerSchema

schema of the data being written

Attributes

Returns

a list of incompatibilities between the schemas