Skip to content

Conversation

sehansi-9
Copy link

Copy link

@Copilot Copilot AI left a 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

Comment on lines 393 to 395
required := []string{"columns", "rows"}
// Check required keys
for _, key := range required {
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Suggested change
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"}
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Comment on lines 402 to 403
if key != "columns" && key != "rows" {
return fmt.Errorf("unexpected key '%s' in tabular data; only 'columns' and 'rows' are allowed", key)
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Suggested change
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.

Comment on lines 411 to 420
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" {
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Suggested change
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.

@vibhatha
Copy link
Member

@sehansi-9 we merged in a refactor yesterday. Could you please rebase?

@sehansi-9 sehansi-9 force-pushed the feature/protobuf_validator branch from 676e6a5 to fa3dc1d Compare July 17, 2025 03:21
@sehansi-9
Copy link
Author

rebased

@sehansi-9 sehansi-9 self-assigned this Aug 17, 2025
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.

2 participants