How SchemaBuilder objects interact
masterYou can interact with SchemaBuilder instances in two primary ways:
- Merging: You can pass one
SchemaBuilderinstance directly into theadd_schema()method of another to merge their schemas. - Comparison: You can use the
==operator to check if twoSchemaBuilderobjects have resulted in identical schemas.
from genson import SchemaBuilder
b1 = SchemaBuilder()
b1.add_schema({"type": "object", "properties": {"hi": {"type": "string"}}})
b2 = SchemaBuilder()
b2.add_schema({"type": "object", "properties": {"hi": {"type": "integer"}}})
# Comparison returns False initially
print(b1 == b2) # False
# Merging b2 into b1
b1.add_schema(b2)
# Comparison returns True after merge
print(b1 == b2) # True