-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
OpenAPI/Pydantic Validation Support #416
Comments
Do you use Superforms in SPA mode for this? (As it's not a Svelte library, but SvelteKit) |
@ciscoheat Sorry for the delayed response - I have been out traveling (and away from my computer). To answer your question, yes, I have been using Superforms in SPA mode. In the For instance, if we were to setup a FastAPI (i.e. OpenAPI) server to handle the example above, we would have a schema struct (automatically generated by https://openapi-ts.pages.dev/ or in general) that looks like: interface UserSchema {
id: integer
name: string
email: string
} When we called the API, it would return a json object with validation errors which at least in the case of fastapi looks something like this: {
"detail":[
{
"loc":[
"name"
],
"msg":"field required",
"type":"value_error.missing"
},
{
"loc":[
"id"
],
"msg": "value is not a valid integer",
"type": "type_error.float"
}
]
} Given this paradigm, where the "schema" is separated from the "validator", how would one go about integrating this into superforms (if this is a workflow that superforms supports)? |
I'm thinking that you can use the onUpdate event, call the API there and loop through its validation errors with setError, similar to https://superforms.rocks/concepts/spa#displaying-the-form |
Is your feature request related to a problem? Please describe.
Many backends for svelte apps are written in python using FastAPI and Pydantic. When a project uses this stack, Sveltekit Superforms is not able to natively display the validation errors returned by this backend.
Describe the solution you'd like
While pydantic is not a javascript validation library, it does do validation (and return validation errors) and a schema is available through the OpenAPI Specification. As such, I was wondering if it would be possible to parse and show the validation errors for form fields returned by pydantic.
Describe alternatives you've considered
Currently, I either replicate the schema I originally defined in Pydantic using zod or I don't use Sveltekit Superforms for validation.
The text was updated successfully, but these errors were encountered: