Skip to content

feat: add v2 API with structured validation errors#1724

Open
MorganaFuture wants to merge 1 commit intomoov-io:masterfrom
MorganaFuture:MorganaFuture/feat/addV2APIendpointsWithStructuredValidationErrors
Open

feat: add v2 API with structured validation errors#1724
MorganaFuture wants to merge 1 commit intomoov-io:masterfrom
MorganaFuture:MorganaFuture/feat/addV2APIendpointsWithStructuredValidationErrors

Conversation

@MorganaFuture
Copy link
Contributor

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

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 V2 API Endpoints: Introduced new API endpoints under /v2/files/* and /v2/files/{id}/batches to support enhanced validation capabilities.
  • Structured Validation Errors: The new V2 API endpoints now return all validation errors in a structured JSON format, providing detailed information about each issue, rather than a single error string.
  • Comprehensive Validation Methods: Added ValidateAll() methods to the File and various Batch types. These methods accumulate and return all detected validation errors, improving the diagnostic feedback for users.
  • V1 API Unchanged: The existing V1 API remains unaffected by these changes, ensuring backward compatibility.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +72 to +76
if verifyErrs := batch.verifyAll(); verifyErrs != nil {
for _, err := range verifyErrs {
errors.Add(err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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...)
    }

Comment on lines +920 to +924
if batchErrs := b.ValidateAll(); batchErrs != nil {
for _, err := range batchErrs {
errors.Add(err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop for adding batch errors can be made more concise by using the variadic Add method of base.ErrorList.

                if batchErrs := b.ValidateAll(); batchErrs != nil {
                    errors.Add(batchErrs...)
                }

Comment on lines +61 to +65
if errs := req.Batch.ValidateAll(); errs != nil {
for _, err := range errs {
validationErrors = append(validationErrors, ConvertError(err))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ConvertErrorList helper function can be used here to simplify converting the base.ErrorList to a slice of ValidationError.

            validationErrors = ConvertErrorList(req.Batch.ValidateAll())

Comment on lines +101 to +105
if errs := req.File.ValidateAll(); errs != nil {
for _, err := range errs {
validationErrors = append(validationErrors, ConvertError(err))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ConvertErrorList helper function can be used here to simplify converting the base.ErrorList to a slice of ValidationError.

            validationErrors = append(validationErrors, ConvertErrorList(req.File.ValidateAll())...)

Comment on lines +174 to +177
var validationErrors []ValidationError
for _, e := range errs {
validationErrors = append(validationErrors, ConvertError(e))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ConvertErrorList helper function can be used here to simplify converting the base.ErrorList to a slice of ValidationError.

        validationErrors := ConvertErrorList(errs)

@adamdecaf
Copy link
Member

@MorganaFuture if we're going to make a v2 of endpoints I'd really like to get off go-kit and use gorilla directly.

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

Successfully merging this pull request may close these issues.

Support structured validation errors in HTTP API

2 participants