Adds Docs for AllOf and AnyOf

This commit is contained in:
2025-06-21 18:20:44 -03:00
parent dee8b02d26
commit ac239c2617
4 changed files with 95 additions and 9 deletions

View File

@@ -0,0 +1,41 @@
AnyOf Type
=================
The AnyOf type is used to specify that an object can conform to any one of the specified schemas. It allows for flexibility in the structure of the data, as it can match multiple possible schemas.
Examples
-----------------
.. code-block:: python
from jambo import SchemaConverter
schema = {
"title": "Person",
"description": "A person",
"type": "object",
"properties": {
"id": {
"anyOf": [
{"type": "integer"},
{"type": "string"},
]
},
},
}
Model = SchemaConverter.build(schema)
obj1 = Model(id="1")
print(obj1) # Output: Person(id='1')
obj2 = Model(id=1)
print(obj2) # Output: Person(id=1)
try:
obj3 = Model(name=1.1) # This will raise a validation error
except ValueError as e:
print("Validation fails as expected:", e) # Output: Validation fails as expected: 1 validation error for Person