-
Notifications
You must be signed in to change notification settings - Fork 73
feature: validate document with go lib over json schema #306
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Nikita B <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @n2h9, 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!
Summary of Changes
This pull request introduces JSON schema validation for documents using a Go library. It includes updates to dependencies, adds new files for validation logic, and modifies existing JSON schema files to align with the new validation approach. The PR also incorporates error handling and testing for the validation process. As noted in the PR description, this is a proof-of-concept and not intended for immediate merging.
Highlights
- JSON Schema Validation: Implements validation of documents against JSON schemas using a Go library (
santhosh-tekuri/jsonschema). - Dependency Updates: Updates
go.modandgo.sumto include the new JSON schema validation library and other dependencies likegithub.com/google/uuidandgithub.com/sirupsen/logrus. - Error Handling: Introduces a custom error type (
ErrValidate) usingmeshkit/errorsfor better error reporting during validation. - Local Schema Loading: Adds functionality to load JSON schemas from local files, enabling validation against locally stored schema definitions.
- Test Cases: Includes a test suite to validate both valid and invalid model files against the defined JSON schema.
Changelog
Click here to see the changelog
- Makefile
- Adds new
erroranderror-utiltargets for analyzing and updating error codes usingmeshkit/cmd/errorutil.
- Adds new
- go.mod
- Updates Go version to 1.23.4.
- Adds
github.com/google/uuid,github.com/santhosh-tekuri/jsonschema,github.com/sirupsen/logrus, andgithub.com/stretchr/testifyas dependencies. - Updates
github.com/layer5io/meshkitto v0.8.26.
- go.sum
- Updates checksums for all dependencies, including newly added ones.
- meshkiterrors/component_info.json
- Creates a new file defining the component info for
meshery.schemas, setting the type toclientand the next error code to 2.
- Creates a new file defining the component info for
- schemas/constructs/core.json
- Removes the
patternproperty from theapiVersionschema definition.
- Removes the
- schemas/constructs/v1alpha1/capability/capability.json
- Updates the
$idtohttps://schemas.meshery.io/v1alpha1/capability/capability.json.
- Updates the
- schemas/constructs/v1beta1/category/category.json
- Updates the
$idtohttps://schemas.meshery.io/v1beta1/category/category.json.
- Updates the
- schemas/constructs/v1beta1/connection.json
- Updates the
$idtohttps://schemas.meshery.io/v1beta1/connection.json.
- Updates the
- schemas/constructs/v1beta1/model/model.json
- Updates the
$idtohttps://schemas.meshery.io/v1beta1/model/model.json. - Removes the
$refto./openapi.yml#/components/schemas/Modelfrom themodelproperty.
- Updates the
- schemas/constructs/v1beta1/subcategory/subcategory.json
- Updates the
$idtohttps://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
- Updates the
- validate/go/error.go
- Creates a new file defining the
ErrValidateerror type usingmeshkitErrors.
- Creates a new file defining the
- validate/go/json_schema_loader.go
- Creates a new file implementing a custom URL loader to load JSON schemas from local files, registering the
httpsscheme to use this loader.
- Creates a new file implementing a custom URL loader to load JSON schemas from local files, registering the
- validate/go/logger.go
- Creates a new file to set up a logger using
meshkit/logger.
- Creates a new file to set up a logger using
- validate/go/testdata/model.aws-ec2-controller.v1.4.1.json
- Creates a new file containing a valid model JSON for testing purposes.
- validate/go/testdata/model.invalid.00.json
- Creates a new file containing an invalid model JSON for testing purposes.
- validate/go/validate.go
- Creates a new file implementing the
ValidateandValidateFromFilePathfunctions to validate documents against JSON schemas, including temporary directory setup and schema loading.
- Creates a new file implementing the
- validate/go/validate_test.go
- Creates a new file containing test cases for the
ValidateFromFilePathfunction, testing both valid and invalid model files.
- Creates a new file containing test cases for the
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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.
A schema's embrace,
Validates data with grace,
Errors take their flight.
Footnotes
-
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. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR introduces JSON schema validation using a Go library, which is a valuable addition for ensuring data integrity. The implementation involves creating a temporary directory to store schemas, setting up a URL loader, and using the jsonschema library for validation. Overall, the code is well-structured, but there are areas for improvement regarding error handling, TODOs, and schema ID updates.
Summary of Findings
- Error Handling: The
ErrValidatefunction usesmeshkitErrors.Fatalwhich might be too severe for validation errors. Consider using a less severe error level likemeshkitErrors.ErrorormeshkitErrors.Warn. - TODOs: The
ErrValidatefunction containsTODOcomments for error descriptions and remediation steps. These should be addressed to provide more informative error messages. - Schema ID Updates: The
$idfields in the JSON schema files are being updated to include versioning. Ensure that all references to these schemas are also updated accordingly to maintain consistency.
Merge Readiness
The PR is not yet ready for merging. The TODO comments in the error handling need to be addressed, and the severity of the validation errors should be reviewed. Additionally, ensure that all schema references are updated to reflect the new versioned $id values. I am unable to approve this pull request, and recommend that it not be merged until the aforementioned issues are addressed.
| func ErrValidate(errs ...error) error { | ||
| return meshkitErrors.New( | ||
| ErrValidateCode, | ||
| meshkitErrors.Fatal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| []string{"TODO"}, | ||
| []string{"TODO"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These TODO comments should be replaced with actual error descriptions and remediation steps to provide more informative error messages to the user. This will greatly improve the debuggability of the validation process.
,
[]string{"Detailed error description here"},
[]string{"Steps to resolve the error"},| @@ -1,5 +1,5 @@ | |||
| { | |||
| "$id": "https://schemas.meshery.io/capability.json", | |||
| "$id": "https://schemas.meshery.io/v1alpha1/capability/capability.json", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "$id": "https://schemas.meshery.io/category.json", | |||
| "$id": "https://schemas.meshery.io/v1beta1/category/category.json", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "$id": "https://schemas.meshery.io/component.json", | |||
| "$id": "https://schemas.meshery.io/v1beta1/connection.json", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "$id": "https://schemas.meshery.io/model.json", | |||
| "$id": "https://schemas.meshery.io/v1beta1/model/model.json", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "$id": "https://schemas.meshery.io/category.json", | |||
| "$id": "https://schemas.meshery.io/v1beta1/subcategory/subcategory.json", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "minLength": 2, | ||
| "maxLength": 100, | ||
| "description": "API version of the object", | ||
| "pattern": "([a-z.])*(?!^/)v(alpha|beta|[0-9]+)([.-]*[a-z0-9]+)*$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not about to be merged)
this keep failing with error of invalid reg exp, was not able to resolve, removed for now to be able to compile schema.
…pi.yml to json on the flight Signed-off-by: Nikita B <[email protected]>
…onString pattern regexp Signed-off-by: Nikita B <[email protected]>
| "description": "API version of the object", | ||
| "pattern": "([a-z.])*(?!^/)v(alpha|beta|[0-9]+)([.-]*[a-z0-9]+)*$", | ||
| "example": ["v1", "v1alpha1", "v2beta3", "v1.custom-suffix"] | ||
| "pattern": "^(([a-z.])+\/?)?v(alpha|beta|[0-9]+)([.-]*[a-z0-9]+)*$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated version, which looks like very close to original, and is valid with respect to golang reg exp parser.
Notes for Reviewers
This PR adds validation of document over json schema with golang lib.
This is just to show the case, not intended to be merged yet.
Signed commits