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

Accessing validation results in the request pipeline #453

Open
guneyizol opened this issue May 27, 2024 · 1 comment
Open

Accessing validation results in the request pipeline #453

guneyizol opened this issue May 27, 2024 · 1 comment
Labels
question Further information is requested

Comments

@guneyizol
Copy link

Hi,

Is there a way to access the validation results in the downstream middlewares and/or handlers in the request pipeline before returning a response? I am happy with the built-in validation but I want to access and process the successfully validated fields and return http.StatusOK if there are any. (If this approach is not really compliant with the HTTP semantics, please let me know.)

What I am ultimately trying is to validate an input json object with possibly many fields and process all of the valid ones and let the user know which ones are successfully processed and which ones are not.

Thank you very much 🙏

@danielgtaylor
Copy link
Owner

@guneyizol this isn't really possible using the built-in request validation pipeline, however I think you could use the SkipValidate* settings in huma.Operation to bypass the built-in validation and then do the validation yourself in the handler. A quick & easy way to try it out would be to use the huma.ModelValidator and if that works to your satisfaction you can look inside its implementation to see how you can make your handler more efficient (e.g. pre-allocating schemas, path buffers, result objects, using sync.Pool, etc if needed).

Hope that helps!

@danielgtaylor danielgtaylor added the question Further information is requested label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants