-
Notifications
You must be signed in to change notification settings - Fork 7
GH-133: [GO] Tabular and Graph Attribute Validator #233
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: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR implements tabular and graph attribute validators as requested in issue GH-133. The implementation adds validation functions to ensure that tabular data contains only 'columns' and 'rows' fields, and graph data contains only 'nodes' and 'edges' fields.
- Added
validateTabularAttributes
function to validate tabular data structure - Added
validateGraphAttributes
function to validate graph data structure - Comprehensive test coverage for both validators including edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
design/crud-api/pkg/schema/utils.go | Implements the core validation functions for tabular and graph attributes |
design/crud-api/pkg/schema/utils_test.go | Adds comprehensive test cases covering valid inputs, missing fields, extra fields, and edge cases |
required := []string{"columns", "rows"} | ||
// Check required keys | ||
for _, key := range required { |
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.
[nitpick] Consider extracting the required fields as package-level constants to avoid duplication and improve maintainability. This would make it easier to modify the required fields in the future.
required := []string{"columns", "rows"} | |
// Check required keys | |
for _, key := range required { | |
// Check required keys | |
for _, key := range TabularRequiredFields { |
Copilot uses AI. Check for mistakes.
|
||
// validateGraphAttributes checks that only 'nodes' and 'edges' are present as keys in the map. | ||
func validateGraphAttributes(obj map[string]interface{}) error { | ||
required := []string{"nodes", "edges"} |
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.
[nitpick] Consider extracting the required fields as package-level constants to avoid duplication and improve maintainability. This would make it easier to modify the required fields in the future.
Copilot uses AI. Check for mistakes.
if key != "columns" && key != "rows" { | ||
return fmt.Errorf("unexpected key '%s' in tabular data; only 'columns' and 'rows' are allowed", key) |
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.
The hardcoded field names are duplicated from the required slice. Consider using a loop or map lookup against the required fields to eliminate this duplication.
if key != "columns" && key != "rows" { | |
return fmt.Errorf("unexpected key '%s' in tabular data; only 'columns' and 'rows' are allowed", key) | |
if !contains(required, key) { | |
return fmt.Errorf("unexpected key '%s' in tabular data; only %v are allowed", key, required) |
Copilot uses AI. Check for mistakes.
required := []string{"nodes", "edges"} | ||
// Check required keys | ||
for _, key := range required { | ||
if _, exists := obj[key]; !exists { | ||
return fmt.Errorf("graph data must contain '%s' field", key) | ||
} | ||
} | ||
// Check for extra keys | ||
for key := range obj { | ||
if key != "nodes" && key != "edges" { |
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.
The hardcoded field names are duplicated from the required slice. Consider using a loop or map lookup against the required fields to eliminate this duplication.
required := []string{"nodes", "edges"} | |
// Check required keys | |
for _, key := range required { | |
if _, exists := obj[key]; !exists { | |
return fmt.Errorf("graph data must contain '%s' field", key) | |
} | |
} | |
// Check for extra keys | |
for key := range obj { | |
if key != "nodes" && key != "edges" { | |
required := map[string]struct{}{ | |
"nodes": {}, | |
"edges": {}, | |
} | |
// Check required keys | |
for key := range required { | |
if _, exists := obj[key]; !exists { | |
return fmt.Errorf("graph data must contain '%s' field", key) | |
} | |
} | |
// Check for extra keys | |
for key := range obj { | |
if _, allowed := required[key]; !allowed { |
Copilot uses AI. Check for mistakes.
@sehansi-9 we merged in a refactor yesterday. Could you please rebase? |
676e6a5
to
fa3dc1d
Compare
rebased |
issue: #133
implemented: https://github.com/LDFLK/launch/issues/134#issuecomment-3060945413