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

Migrate to Pydantic for config models and validation #6

Closed
thomasborgen opened this issue Apr 29, 2021 · 3 comments · Fixed by #14
Closed

Migrate to Pydantic for config models and validation #6

thomasborgen opened this issue Apr 29, 2021 · 3 comments · Fixed by #14

Comments

@thomasborgen
Copy link
Contributor

Pydantic seems to be quite a good option for
reading our config input from json into typed objects that should probably be easy to work with.
validating that the json config input is in fact valid and it seems good at creating error messages.

The current json schema implementation does not handle errors as well as i hoped it would.

Pydantic is also used by FastAPI that we use to serve kaiba, which should mean that we should get super easy error handling and good messages.

@thomasborgen
Copy link
Contributor Author

This also relates to #4 since it would hopefully make it much easier to do typing

@thomasborgen
Copy link
Contributor Author

[mypy]
plugins = pydantic.mypy

@thomasborgen
Copy link
Contributor Author

https://pydantic-docs.helpmanual.io/usage/schema/

schema dumped works with json schema and openapi spec. (for client side validation while creating mapping file)

@thomasborgen thomasborgen linked a pull request Jun 5, 2021 that will close this issue
thomasborgen added a commit that referenced this issue Jun 7, 2021
* updates dev dependencies

* Types out the schema as pydantic BaseModels

* process now marshalls to pydantic

* If statements migrated to pydantic

* Slicing migrated to pydantic

* Regexp migrated to pydantic

* Casting migrated to pydantic

* Fixes doctests in functions.py

* Handler.handle_mapping migrated to pydantic

* Handlers.handle_attributes merged to pydantic

* Possibly done migrating mapper code to pydantic

* Migrates collection handlers to pydantic

* Migrates collection handlers tests to pydantic

* Migrates process function to pydantic

* fix process function so that it correctly returns a Failure(Exc)

* Add validation test that checks that the errors we get are correct and that things a marshalled correctly

* removes old jsonschema tests

* removes unused common.py and gets tests coverage up to 100% again

* Fixes linting errors

* cleans up constants.py

* Fixes mypy errors

* Fixes import sort

* fixes high jonas complexity lines

* in function stop using mapvalue and use same AnyType type that's used in pydantic schema

* fixes linting errors

* removes unused import

* Removes jsonschema dependency

* formatting

* Bump minor version

* Test that we can create a jsonschema

* Adds docstring.
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 a pull request may close this issue.

1 participant