Skip to content

Suppress 4XX catch-all response for explicit error codes#54

Merged
moutonjeremy merged 2 commits into
mainfrom
feat-suppress-4xx-when-errors-declared
Jun 2, 2026
Merged

Suppress 4XX catch-all response for explicit error codes#54
moutonjeremy merged 2 commits into
mainfrom
feat-suppress-4xx-when-errors-declared

Conversation

@moutonjeremy
Copy link
Copy Markdown
Member

This pull request updates the OpenAPI spec generation logic to better handle how error responses are documented, particularly regarding the legacy 4XX catch-all response versus explicit error status codes. The changes clarify and enforce that when explicit error codes are provided, the generic 4XX catch-all is omitted, resulting in a more accurate and less confusing API specification. Additionally, new tests ensure this behavior is correct and maintains backward compatibility.

OpenAPI error response handling:

  • The OpenAPI spec generator (fiberoapi.go) now omits the legacy 4XX catch-all response when explicit error codes are provided via OpenAPIOptions.Errors, ensuring only the enumerated status codes appear in the spec. If no explicit errors are declared and a non-empty TError is present, the 4XX catch-all is still emitted for backward compatibility.
  • The documentation (README.md) is updated to explain the new behavior: the 4XX catch-all is suppressed when explicit errors are declared, and only those status codes appear in the spec.

Testing and validation:

  • Two new tests are added in custom_errors_test.go:
    • One verifies that the 4XX catch-all is suppressed when explicit errors are declared.
    • The other ensures the legacy 4XX catch-all is still emitted when no explicit errors are declared, preserving backward compatibility.

Copilot AI review requested due to automatic review settings June 2, 2026 15:32
Copy link
Copy Markdown
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 refines OpenAPI spec generation for error responses by suppressing the legacy 4XX catch-all response when a route explicitly declares per-status errors via OpenAPIOptions.Errors, while keeping the 4XX catch-all for backward compatibility when no explicit errors are provided.

Changes:

  • Update spec generation to only emit the legacy 4XX catch-all when TError is non-empty and no explicit OpenAPIOptions.Errors are provided.
  • Document the updated behavior in README.md.
  • Add tests covering both the suppression case and the backward-compatible legacy case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
README.md Documents that 4XX is omitted once per-status Errors are declared.
fiberoapi.go Suppresses the legacy 4XX response when explicit per-status errors are present.
custom_errors_test.go Adds tests ensuring 4XX is suppressed with explicit errors and preserved without them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fiberoapi.go Outdated
Comment thread custom_errors_test.go Outdated
@moutonjeremy moutonjeremy merged commit 60079ef into main Jun 2, 2026
4 checks passed
@moutonjeremy moutonjeremy deleted the feat-suppress-4xx-when-errors-declared branch June 2, 2026 15:46
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