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
Limit error response in large union #854
Comments
Currently, I don't think there is a clean way to validate a union-typed field without seeing all the errors. I recently put a little effort into building a type called
I haven't finished the implementation, but I'm convinced it should be possible to implement without too much effort. It should also play nice with the discriminator concept in OpenAPI (though I think most tools have weak support for that, at best). I'd be curious if there are others interested in this version of the implementation, or if a different API would be preferable. |
From the perspective of the current codebase I’m working with that implementation would be highly desirable. I agree that it the swagger may behave weirdly but it already has some issues with anyOf as we discussed on another issue :) |
I entirely agree that this would be great, see my comment: #619 (comment) and more below that You can see the bodge I'm using right now for this here. The reason I haven't worked on Closing this, if there's more feedback please comment on #619. |
Question
I am looking for ways to only see an error in a specific element of a union.
We have some models similar to this example from the docs:
For the Union in the Meal class, if the input satisfies none of the models, it would throw errors for all. Our use case has over 10 different models that have different fields in the Union and the response is difficult to parse. Each different type is based on a literal string similar to above.
Is there a way to limit/filter errors so that the response is more actionable?
Previously to avoid this, I had one large generic model with Optional field on all elements that were only in some cases. And then custom validators for each element to see whether it was required for this type.
Please complete:
import sys; print(sys.version)
: 3.7import pydantic; print(pydantic.VERSION)
: 0.32.2The text was updated successfully, but these errors were encountered: