Skip to content

Conversation

SebastienMelki
Copy link
Owner

Summary

This PR implements comprehensive structured validation error responses across the sebuf toolkit, providing consistent error handling for both request body and header validation.

Key Changes

  • Add ValidationError proto definitions (proto/sebuf/http/errors.proto)

    • ValidationError message with list of field violations
    • FieldViolation message with field path and description
    • Support for both JSON and protobuf serialization
  • Update HTTP generator (internal/httpgen/generator.go)

    • Generate structured error response functions
    • Convert protovalidate errors to ValidationError format
    • Support content-type aware error serialization (JSON/protobuf)
    • Update header validation to return structured errors
  • Update OpenAPI v3 generator (internal/openapiv3/generator.go)

    • Add ValidationError and FieldViolation schemas to components
    • Include 400 validation error responses in all API methods
    • Provide comprehensive error documentation for API consumers
  • Refactor for code quality

    • Break down long functions to fix linting issues (funlen violations)
    • Improve code readability and maintainability
    • Update golden files for comprehensive test coverage
  • Update documentation and examples

    • Update validation documentation with structured error examples
    • Refresh simple-api example with new error handling
    • Add structured error responses to main feature list

Error Response Format

{
  "violations": [
    {
      "field": "user.email",
      "description": "must be a valid email address"
    },
    {
      "field": "X-API-Key", 
      "description": "required header 'X-API-Key' is missing"
    }
  ]
}

Benefits

  • Consistent error handling across request body and header validation
  • Better API documentation with OpenAPI 400 response specifications
  • Enhanced developer experience with detailed field-level error information
  • Content-type awareness supporting both JSON and protobuf error responses
  • Comprehensive test coverage with updated golden files

Test Plan

  • All existing tests pass
  • Golden files updated for OpenAPI generator
  • Linting issues resolved (funlen violations fixed)
  • Simple-api example generates correctly with new error schemas
  • Both JSON and YAML OpenAPI formats include ValidationError schemas

🤖 Generated with Claude Code

SebastienMelki and others added 18 commits August 28, 2025 17:20
- Add ValidationError and FieldViolation messages
- Support field-level validation error details
- Enable JSON/protobuf serialization for error responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add writeValidationErrorResponse() for content-type aware error serialization
- Add writeValidationError() to convert protovalidate errors to ValidationError
- Update validateHeaders() to return ValidationError directly
- Replace plain text http.Error() calls with structured error responses
- Support both JSON and protobuf error response formats based on content-type
- Extract field paths from protovalidate violations for detailed error reporting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Include errors.proto in protoc compilation
- Add proper go_opt mapping for errors.proto

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove admin.proto and admin_service.proto
- Focus example on core user service functionality
- Reduce complexity for testing and demonstration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add replace directive to use local sebuf for testing
- Ensure examples use latest local changes during development

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update annotations.pb.go and headers.pb.go
- Regenerated with protoc v6.32.0

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Document ValidationError message structure with field violations
- Update error examples to show JSON response format
- Add examples of multiple validation failures
- Update features list to include structured errors and content-type awareness
- Show both header and body validation error responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update generated validation code examples to show ValidationError returns
- Modify header validation examples to show JSON error responses
- Add structured errors to features list
- Update curl examples with proper JSON error format

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update validation error examples to show JSON response format
- Add examples of multiple validation failures
- Remove references to deleted AdminService
- Simplify OpenAPI documentation references
- Add structured error responses to features list

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add ValidationError and FieldViolation schemas to OpenAPI components
- Include 400 validation error responses in all method specifications
- Provide comprehensive error documentation for API consumers
- Support both request body and header validation error reporting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Format long function signature lines for better readability
- Maintain consistent code style across generator functions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Split generateErrorResponseFunctions into smaller helper functions
- Split generateValidateHeadersFunction into smaller helper functions
- Fix funlen linting violations (functions > 50 statements)
- Maintain same generated code behavior with improved readability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add FieldViolation and ValidationError schemas to all golden files
- Include 400 validation error responses in method specifications
- Update both YAML and JSON golden file formats
- Reflect new OpenAPI generator behavior for validation errors

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove .generated files created during golden file testing
- Clean up test artifacts that shouldn't be committed
- These files are created during UPDATE_GOLDEN test runs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove temporary .generated files created during golden file testing
- These files are test artifacts and shouldn't be committed
- They are created during UPDATE_GOLDEN test runs for comparison

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Prevent temporary .generated test files from being committed
- These files are created during golden file testing for comparison
- Should be automatically cleaned up after test runs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

github-actions bot commented Aug 28, 2025

🔍 CI Pipeline Status

Lint: success
Test: success
Coverage: success
Build: success
Integration: success


📊 Coverage Report: Available in checks above
🔗 Artifacts: Test results and coverage reports uploaded

@SebastienMelki SebastienMelki merged commit a78b685 into main Aug 28, 2025
5 of 9 checks passed
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 13.77%. Comparing base (724ab8a) to head (d94d110).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/openapiv3/generator.go 80.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   10.61%   13.77%   +3.16%     
==========================================
  Files           5        5              
  Lines        1046     1096      +50     
==========================================
+ Hits          111      151      +40     
- Misses        930      940      +10     
  Partials        5        5              
Flag Coverage Δ
unittests 13.77% <80.00%> (+3.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant