diff --git a/README.md b/README.md index 8404244..8dba275 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,10 @@ Created to simplifying the process of dynamically generating Pydantic models for ## โœจ Features -- โœ… Convert JSON Schema into Pydantic models dynamically -- ๐Ÿ”’ Supports validation for strings, integers, floats, booleans, arrays, and nested objects -- โš™๏ธ Enforces constraints like `minLength`, `maxLength`, `pattern`, `minimum`, `maximum`, `uniqueItems`, and more -- ๐Ÿ“ฆ Zero config โ€” just pass your schema and get a model +- โœ… Convert JSON Schema into Pydantic models dynamically; +- ๐Ÿ”’ Supports validation for strings, integers, floats, booleans, arrays, nested objects, allOf, anyOf and ref; +- โš™๏ธ Enforces constraints like `minLength`, `maxLength`, `pattern`, `minimum`, `maximum`, `uniqueItems`, and more; +- ๐Ÿ“ฆ Zero config โ€” just pass your schema and get a model. --- @@ -45,7 +45,8 @@ pip install jambo ## ๐Ÿš€ Usage ```python -from jambo.schema_converter import SchemaConverter +from jambo import SchemaConverter + schema = { "title": "Person", @@ -70,6 +71,9 @@ print(obj) ### Strings with constraints ```python +from jambo import SchemaConverter + + schema = { "title": "EmailExample", "type": "object", @@ -92,6 +96,9 @@ print(obj) ### Integers with bounds ```python +from jambo import SchemaConverter + + schema = { "title": "AgeExample", "type": "object", @@ -109,6 +116,9 @@ print(obj) ### Nested Objects ```python +from jambo import SchemaConverter + + schema = { "title": "NestedObjectExample", "type": "object", @@ -130,6 +140,41 @@ obj = Model(address={"street": "Main St", "city": "Gotham"}) print(obj) ``` +### References + +```python +from jambo import SchemaConverter + + +schema = { + "title": "person", + "$ref": "#/$defs/person", + "$defs": { + "person": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "age": {"type": "integer"}, + "emergency_contact": { + "$ref": "#/$defs/person", + }, + }, + } + }, +} + +model = SchemaConverter.build(schema) + +obj = model( + name="John", + age=30, + emergency_contact=model( + name="Jane", + age=28, + ), +) +``` + --- ## ๐Ÿงช Running Tests @@ -171,8 +216,6 @@ poe create-hooks ## ๐Ÿ“Œ Roadmap / TODO - [ ] Support for `enum` and `const` -- [ ] Support for `anyOf`, `allOf`, `oneOf` -- [ ] Schema ref (`$ref`) resolution - [ ] Better error reporting for unsupported schema types --- diff --git a/jambo/schema_converter.py b/jambo/schema_converter.py index 952cdc2..6f9020e 100644 --- a/jambo/schema_converter.py +++ b/jambo/schema_converter.py @@ -50,7 +50,6 @@ class SchemaConverter: schema, context=schema, ref_cache=dict(), - required=True, ) return parsed_model case _: