feat: add v2 API with structured validation errors#1724
Conversation
Add /v2/files/* and /v2/files/{id}/batches endpoints that return
all validation errors in structured JSON format instead of a single
error string.
Add ValidateAll() methods to File and Batch types to collect all
errors. v1 API unchanged.
Closes moov-io#1625
Summary of ChangesHello @MorganaFuture, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the API's validation feedback mechanism by introducing a new V2 API. This new version provides structured JSON validation errors for both file and batch operations, allowing users to receive a comprehensive list of all issues rather than stopping at the first error encountered. This change improves the developer experience by making it easier to identify and resolve multiple validation problems in a single request, without altering the behavior of the existing V1 API. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a v2 API that provides structured validation errors, which is a significant improvement for API consumers. It adds ValidateAll methods to File and Batch types to collect all validation errors instead of failing on the first one. The implementation is consistent across different batch types, and the new server endpoints and error handling for the v2 API are well-designed. I've made a few suggestions to simplify error handling loops by using existing helper functions and variadic arguments, which should improve code conciseness and maintainability. Overall, this is a solid feature addition.
| if verifyErrs := batch.verifyAll(); verifyErrs != nil { | ||
| for _, err := range verifyErrs { | ||
| errors.Add(err) | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop to add errors from verifyAll can be simplified by using the variadic Add method on base.ErrorList. This would make the code more concise.
This pattern is repeated across many of the new ValidateAll implementations in other batch*.go files, and the same suggestion applies there.
if verifyErrs := batch.verifyAll(); verifyErrs != nil {
errors.Add(verifyErrs...)
}| if batchErrs := b.ValidateAll(); batchErrs != nil { | ||
| for _, err := range batchErrs { | ||
| errors.Add(err) | ||
| } | ||
| } |
| if errs := req.Batch.ValidateAll(); errs != nil { | ||
| for _, err := range errs { | ||
| validationErrors = append(validationErrors, ConvertError(err)) | ||
| } | ||
| } |
| if errs := req.File.ValidateAll(); errs != nil { | ||
| for _, err := range errs { | ||
| validationErrors = append(validationErrors, ConvertError(err)) | ||
| } | ||
| } |
| var validationErrors []ValidationError | ||
| for _, e := range errs { | ||
| validationErrors = append(validationErrors, ConvertError(e)) | ||
| } |
|
@MorganaFuture if we're going to make a v2 of endpoints I'd really like to get off go-kit and use gorilla directly. |
Add /v2/files/* and /v2/files/{id}/batches endpoints that return all validation errors in structured JSON format instead of a single error string.
Add ValidateAll() methods to File and Batch types to collect all errors. v1 API unchanged.
Closes #1625