Adds Feature Example of the New Feature to the ReadMe
This commit is contained in:
57
README.md
57
README.md
@@ -27,10 +27,10 @@ Created to simplifying the process of dynamically generating Pydantic models for
|
|||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|
||||||
- ✅ Convert JSON Schema into Pydantic models dynamically
|
- ✅ Convert JSON Schema into Pydantic models dynamically;
|
||||||
- 🔒 Supports validation for strings, integers, floats, booleans, arrays, and nested objects
|
- 🔒 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
|
- ⚙️ Enforces constraints like `minLength`, `maxLength`, `pattern`, `minimum`, `maximum`, `uniqueItems`, and more;
|
||||||
- 📦 Zero config — just pass your schema and get a model
|
- 📦 Zero config — just pass your schema and get a model.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -45,7 +45,8 @@ pip install jambo
|
|||||||
## 🚀 Usage
|
## 🚀 Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from jambo.schema_converter import SchemaConverter
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
|
||||||
schema = {
|
schema = {
|
||||||
"title": "Person",
|
"title": "Person",
|
||||||
@@ -70,6 +71,9 @@ print(obj)
|
|||||||
### Strings with constraints
|
### Strings with constraints
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
|
||||||
schema = {
|
schema = {
|
||||||
"title": "EmailExample",
|
"title": "EmailExample",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@@ -92,6 +96,9 @@ print(obj)
|
|||||||
### Integers with bounds
|
### Integers with bounds
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
|
||||||
schema = {
|
schema = {
|
||||||
"title": "AgeExample",
|
"title": "AgeExample",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@@ -109,6 +116,9 @@ print(obj)
|
|||||||
### Nested Objects
|
### Nested Objects
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
|
||||||
schema = {
|
schema = {
|
||||||
"title": "NestedObjectExample",
|
"title": "NestedObjectExample",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@@ -130,6 +140,41 @@ obj = Model(address={"street": "Main St", "city": "Gotham"})
|
|||||||
print(obj)
|
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
|
## 🧪 Running Tests
|
||||||
@@ -171,8 +216,6 @@ poe create-hooks
|
|||||||
## 📌 Roadmap / TODO
|
## 📌 Roadmap / TODO
|
||||||
|
|
||||||
- [ ] Support for `enum` and `const`
|
- [ ] Support for `enum` and `const`
|
||||||
- [ ] Support for `anyOf`, `allOf`, `oneOf`
|
|
||||||
- [ ] Schema ref (`$ref`) resolution
|
|
||||||
- [ ] Better error reporting for unsupported schema types
|
- [ ] Better error reporting for unsupported schema types
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class SchemaConverter:
|
|||||||
schema,
|
schema,
|
||||||
context=schema,
|
context=schema,
|
||||||
ref_cache=dict(),
|
ref_cache=dict(),
|
||||||
required=True,
|
|
||||||
)
|
)
|
||||||
return parsed_model
|
return parsed_model
|
||||||
case _:
|
case _:
|
||||||
|
|||||||
Reference in New Issue
Block a user