Adds Docs for Object
This commit is contained in:
46
docs/source/usage.object.rst
Normal file
46
docs/source/usage.object.rst
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
Object Type
|
||||||
|
=================
|
||||||
|
|
||||||
|
|
||||||
|
The Bool type has no specific properties, it has only the generic properties:
|
||||||
|
|
||||||
|
- default: Default value for the string.
|
||||||
|
- description: Description of the string field.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
schema = {
|
||||||
|
"title": "Person",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"street": {"type": "string"},
|
||||||
|
"city": {"type": "string"},
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"street": "Unknown Street",
|
||||||
|
"city": "Unknown City",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"description": "A person object containing a address.",
|
||||||
|
"required": ["address"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Person = SchemaConverter.build(schema)
|
||||||
|
|
||||||
|
obj = Person.model_validate({ "address": {"street": "123 Main St", "city": "Springfield"} })
|
||||||
|
print(obj) # Output: Person(address=Address(street='123 Main St', city='Springfield'))
|
||||||
|
|
||||||
|
obj_default = Person() # Uses default values
|
||||||
|
print(obj_default) # Output: Person(address=Address(street='Unknown Street', city='Unknown City'))
|
||||||
@@ -40,4 +40,5 @@ For more complex schemas and types see our documentation on
|
|||||||
usage.string
|
usage.string
|
||||||
usage.numeric
|
usage.numeric
|
||||||
usage.bool
|
usage.bool
|
||||||
usage.array
|
usage.array
|
||||||
|
usage.object
|
||||||
Reference in New Issue
Block a user