Skip to content
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

Prepare for pydanticv2 #20

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Prepare for pydanticv2 #20

wants to merge 9 commits into from

Conversation

ruscoder
Copy link
Member

@ruscoder ruscoder commented Sep 6, 2024

  • AnyResource is now Model with resourceType
  • All Resource Models (like Patient) inherit AnyResource as the first parent class. BaseModel is the second one - it restricts "extra" to forbid
  • BaseModel (that is used by all models) has a validator for all fields that transform AnyResource to the particular instance (with proper validation for lists)
  • primitive types have suffix Type

@ruscoder ruscoder requested a review from m0rl September 6, 2024 12:45
@ruscoder
Copy link
Member Author

ruscoder commented Sep 6, 2024

There's a dirty hack with primitive types - I add Type and then remove Type for unions - it needs to be re-written in a better way. But I'm afraid it will require to change our meta models to add real type and aliased type

@ruscoder
Copy link
Member Author

I had to add a custom serializer and validator for BaseModel that we use for all resources to handle AnyResource validation/serialization.
Functions _validate/_serialize run for each field, it's definitely not optimized way, however, it skips to default for non AnyResource values.
I assume it might be refactored using __get_pydantic_core_schema__ with a custom schema for AnyResource/list[AnyResource] fields.

Also, there's a bit tight connection to the pydantic internals due to enumerating all fields for model_dump - but otherwise it's impossible to do it with typed kwargs.

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