From d824084d94576ed2c7175daf6d4ce476ebaf50c3 Mon Sep 17 00:00:00 2001 From: Thor Whalen <1906276+thorwhalen@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:06:09 +0100 Subject: [PATCH] docs(README): define AdminModel, source_schema and json_data so the pydantic examples run [skip publish] --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4db230d..3c3348c 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ from ju.pydantic_util import is_valid_wrt_model, valid_models is_valid = is_valid_wrt_model({"name": "Bob", "age": 25}, UserModel) # Find all models that validate given data +AdminModel = data_to_pydantic_model({"name": "Root", "age": 40, "is_admin": True}, "Admin") models = [UserModel, ProductModel, AdminModel] matching = list(valid_models(data, models)) ``` @@ -192,6 +193,7 @@ def fix_field_names(schema): schema['properties'][new_name] = schema['properties'].pop(old_name) return schema +source_schema = schema # the JSON schema defined above code = pydantic_model_to_code( source_schema, ingress_transform=fix_field_names, @@ -218,6 +220,7 @@ paths = field_paths_and_annotations(UserModel) descriptions = model_field_descriptions(UserModel) # Use models as data extraction templates +json_data = data # the dict defined above extractor = ModelExtractor([UserModel, AdminModel]) data_reader = extractor(json_data) # Returns mapping with model-based paths values = data_reader['address.city'] # Extract nested values easily