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

Unified API params/data validation #7

Open
Theodlz opened this issue Sep 6, 2024 · 1 comment
Open

Unified API params/data validation #7

Theodlz opened this issue Sep 6, 2024 · 1 comment
Assignees

Comments

@Theodlz
Copy link
Collaborator

Theodlz commented Sep 6, 2024

Currently, we handle validation of API params on a HTTP + handler basis, by that I mean that we write validation code specify to every handler method, and we do not have a unified validation method. This means that we reimplement the same things everywhere, which most of the time results in unexpected errors.

We could consider using Marshmellow which we use for sqlalchemy and other schemas that are in fact already used for API docs generation by a couple of handlers. A good example is: https://github.com/skyportal/skyportal/blob/c2019aa779e663fdaa21d9857615952ce2f0e8af/skyportal/models/schema.py#L1691, that we then used in https://github.com/skyportal/skyportal/blob/c2019aa779e663fdaa21d9857615952ce2f0e8af/skyportal/handlers/api/spectrum.py#L1038.

We could consider using Marshmallow schemas everywhere

@Theodlz Theodlz changed the title API params/data validation Unified API params/data validation Sep 6, 2024
@stefanv
Copy link
Collaborator

stefanv commented Sep 7, 2024

OpenAPI core supports validation. We could modify our base handler to convert the docstring to OpenAPI via apispec, and then perform automatic validation on in and output:

https://openapi-core.readthedocs.io/en/latest/validation.html

@stefanv stefanv self-assigned this Sep 7, 2024
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

No branches or pull requests

2 participants