-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Add support for custom validation error handler in OApiApp configuration #20
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
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.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bug: ValidationErrorHandler not in config detection, ignores boolean flags
The hasExplicitConfig check determines whether user-provided boolean fields (EnableValidation, EnableOpenAPIDocs) override defaults. The newly added ValidationErrorHandler is correctly copied at lines 76-78, but provided.ValidationErrorHandler != nil is missing from the hasExplicitConfig condition. This causes a problem when users provide only ValidationErrorHandler along with boolean flags like EnableOpenAPIDocs: false — since hasExplicitConfig evaluates to false, the boolean settings are silently ignored and defaults are used instead.
fiberoapi.go#L37-L43
Lines 37 to 43 in 6f8fa8b
| // we assume the user intended to configure it explicitly | |
| hasExplicitConfig := provided.EnableAuthorization || | |
| provided.AuthService != nil || | |
| provided.SecuritySchemes != nil || | |
| provided.OpenAPIDocsPath != "" || | |
| provided.OpenAPIJSONPath != "" || | |
| provided.OpenAPIYamlPath != "" |
fiberoapi.go#L75-L78
Lines 75 to 78 in 6f8fa8b
| } | |
| if provided.ValidationErrorHandler != nil { | |
| cfg.ValidationErrorHandler = provided.ValidationErrorHandler | |
| } |
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 introduces support for custom validation error handlers in the fiber-oapi framework, allowing users to define their own error response structures when validation fails. The feature enables greater flexibility in maintaining consistent error response formats across APIs.
Key Changes:
- Added
ValidationErrorHandlerfunction type and configuration field to allow custom error response handling - Updated validation error flow to use custom handler when configured, falling back to default behavior otherwise
- Included comprehensive tests and a working example demonstrating the feature
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| types.go | Added ValidationErrorHandler function type and new config field for custom validation error handling |
| fiberoapi.go | Integrated custom validation error handler into config initialization and validation error flow |
| custom_validation_error_test.go | Added comprehensive test coverage for both custom and default validation error handling |
| _examples/custom_validation_error/main.go | Provided example demonstrating custom validation error handler usage |
| _examples/custom_validation_error/go.mod | Added Go module file for the example (contains invalid Go version) |
| _examples/custom_validation_error/go.sum | Added dependency checksums for the example |
| _examples/custom_validation_error/README.md | Added documentation explaining the feature with usage examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
…ValidationErrorHandler is set without explicit disablement
…dler is set without explicit boolean configurations
…dationErrorHandler configured
Introduce a custom validation error handler in the OApiApp configuration, allowing users to define their own error response structure for validation failures. Include an example and tests to demonstrate the new functionality.
Note
Adds
ValidationErrorHandlertoConfigand routes validation failures through it, with updated config merging, example app, and tests.ValidationErrorHandlertype andConfig.ValidationErrorHandlerfield intypes.go.Newconfig merge infiberoapi.goto treatValidationErrorHandleras explicit config and restore default booleans when it's the only option set.Methodwrapper, route validation errors toconfig.ValidationErrorHandlerif present; otherwise return defaultErrorResponse.custom_validation_error_test.gocovering custom handler response shape, default behavior without handler, respectingEnableOpenAPIDocs: false, and that setting onlyValidationErrorHandlerkeeps validation/docs defaults._examples/custom_validation_errorwithREADME.md,main.go, and module files demonstrating custom validation error handling.Written by Cursor Bugbot for commit feac293. This will update automatically on new commits. Configure here.