Skip to content

fix: qualify external ref schema types in default response codes#2241

Merged
jamietanna merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-2113
Feb 27, 2026
Merged

fix: qualify external ref schema types in default response codes#2241
jamietanna merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-2113

Conversation

@mromaszewicz
Copy link
Member

Closes #2113

When a response uses a $ref to an external components/responses definition, the generated strict-server code for non-fixed status codes (e.g. default) used the inner schema type without the external package qualifier, causing a compile error. Apply
ensureExternalRefsInSchema to response content schemas after resolving external response refs.

Closes oapi-codegen#2113

When a response uses a $ref to an external components/responses
definition, the generated strict-server code for non-fixed status
codes (e.g. default) used the inner schema type without the external
package qualifier, causing a compile error. Apply
ensureExternalRefsInSchema to response content schemas after
resolving external response refs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@mromaszewicz mromaszewicz requested a review from a team as a code owner February 24, 2026 18:05
@mromaszewicz mromaszewicz added this to the v2.6.0 milestone Feb 24, 2026
@oapi-codegen oapi-codegen deleted a comment from greptile-apps bot Feb 24, 2026
@mromaszewicz
Copy link
Member Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Feb 24, 2026

Greptile Summary

This PR fixes a compilation error that occurred when using external $ref in response definitions for non-fixed status codes (e.g., default). The fix ensures that schema types from external packages are properly qualified with their package name.

Key Changes:

  • Added ensureExternalRefsInSchema calls to response content schemas after resolving external response refs
  • The fix applies the external package qualifier (e.g., common.ProblemDetails) to content schemas so that generated code for non-fixed status codes uses the correct qualified type
  • Follows the same pattern as existing external ref handling for request bodies and path-level response definitions

Testing:

  • Comprehensive test case added that would fail to compile without the fix
  • Test verifies that default response type correctly uses common.ProblemDetails instead of unqualified ProblemDetails

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is a targeted 6-line change that follows the exact same pattern as existing external ref handling code in the codebase. The logic is sound, well-placed within the correct conditional block, and includes a comprehensive test that validates the fix.
  • No files require special attention

Important Files Changed

Filename Overview
pkg/codegen/operations.go Adds external ref qualifier to response content schemas for non-fixed status codes, fixing compilation errors with external response refs
internal/test/issues/issue-2113/spec.yaml Test spec demonstrating external ref in both fixed (400) and default response codes
internal/test/issues/issue-2113/issue_test.go Compilation test verifying default response type uses qualified common.ProblemDetails instead of unqualified ProblemDetails

Last reviewed commit: 71fc215

@jamietanna jamietanna merged commit d04991e into oapi-codegen:main Feb 27, 2026
27 checks passed
@jamietanna jamietanna added the bug Something isn't working label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$ref in responses is not adding the imported reference properly

2 participants