Skip to content

Conversation

@moutonjeremy
Copy link
Member

@moutonjeremy moutonjeremy commented Dec 2, 2025

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 ValidationErrorHandler to Config and routes validation failures through it, with updated config merging, example app, and tests.

  • Core:
    • Add ValidationErrorHandler type and Config.ValidationErrorHandler field in types.go.
    • Update New config merge in fiberoapi.go to treat ValidationErrorHandler as explicit config and restore default booleans when it's the only option set.
    • In Method wrapper, route validation errors to config.ValidationErrorHandler if present; otherwise return default ErrorResponse.
  • Tests:
    • Add custom_validation_error_test.go covering custom handler response shape, default behavior without handler, respecting EnableOpenAPIDocs: false, and that setting only ValidationErrorHandler keeps validation/docs defaults.
  • Examples:
    • Add _examples/custom_validation_error with README.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.

Copilot AI review requested due to automatic review settings December 2, 2025 14:48
Copy link

@cursor cursor bot left a 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

fiber-oapi/fiberoapi.go

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

fiber-oapi/fiberoapi.go

Lines 75 to 78 in 6f8fa8b

}
if provided.ValidationErrorHandler != nil {
cfg.ValidationErrorHandler = provided.ValidationErrorHandler
}

Fix in Cursor Fix in Web


Copy link
Contributor

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 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 ValidationErrorHandler function 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.

Copy link

@cursor cursor bot left a 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.

@moutonjeremy moutonjeremy merged commit 98687a0 into main Dec 2, 2025
5 checks passed
@moutonjeremy moutonjeremy deleted the feat-custom-error-validation-message branch December 2, 2025 15:33
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