Skip to content

Auto-generate Pydantic models from JSON Schemas #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 21, 2024
Merged

Conversation

osolmaz
Copy link
Contributor

@osolmaz osolmaz commented Aug 14, 2024

JSON Schemas are the single source of truth for page and block types. We implement auto-generated Pydantic models for manipulating JSON-DOC files in Python. See https://koxudaxi.github.io/datamodel-code-generator

The module path jsondoc.models contains said auto-generated models and any edits will be overwritten.

We make use of datamodel-code-generator conventions of customBasePath and customTypePath to rewire inheritance from base classes, so that blocks, rich text objects and file objects (e.g. for image block) can be deserialized elegantly. jsondoc.serialize contains logic that initializes Pydantic models from JSON-DOC files or dicts.

@osolmaz osolmaz changed the title Auto-generate Pydantic models from JSON Schemas and add converters Auto-generate Pydantic models from JSON Schemas Aug 21, 2024
@osolmaz osolmaz merged commit 9b93acf into main Aug 21, 2024
1 check passed
@osolmaz osolmaz deleted the add-converter-1 branch August 21, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant