Skip to content

Add missing case to type generation traversal#2298

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-1306
Apr 29, 2026
Merged

Add missing case to type generation traversal#2298
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-1306

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Fixes: #1306

GenerateTypeDefsForOperation() was extracting AdditionalTypes from params and request bodies, but not from response content schemas. This meant that x-go-type-name on an inline response schema was silently ignored — the type definition was created internally but never collected for output.

Add the missing loop over op.Responses[].Contents[].Schema to extract AdditionalTypes, matching the existing pattern for params and bodies. Extend the xgotypename example with a response-level x-go-type-name test case.

Due to this bug, we've neglected to generate types for any types defined inline in responses, so a lot of generated files were affected due to those types being missing.

@mromaszewicz mromaszewicz requested a review from a team as a code owner March 23, 2026 18:36
@mromaszewicz mromaszewicz force-pushed the fix/issue-1306 branch 2 times, most recently from ff7a6f3 to 62bc09c Compare March 23, 2026 19:42
@mromaszewicz mromaszewicz added the bug Something isn't working label Mar 23, 2026
@heww

heww commented Apr 17, 2026

Copy link
Copy Markdown

Hi @mromaszewicz could you merge this PR to the main? Thanks!

@mromaszewicz mromaszewicz added this to the v2.7.0 milestone Apr 21, 2026
@mromaszewicz

Copy link
Copy Markdown
Member Author

@greptileai

@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a long-standing bug in GenerateTypeDefsForOperation where AdditionalTypes from inline response schemas were collected during traversal but never appended to the returned slice, causing x-go-type-name on response bodies to be silently dropped. The fix adds the missing two-level loop over op.Responses[].Contents[].Schema.AdditionalTypes, exactly mirroring the existing pattern for params and request bodies. The resulting churn across multiple *.gen.go fixtures is expected — all newly emitted types are additive and do not alter existing generated identifiers or signatures.

Confidence Score: 4/5

Safe to merge; change is a minimal additive fix with no breaking changes to the existing generated API surface.

The core fix in operations.go is correct and well-scoped. All generated file diffs are proportionate — only previously-missing types are added. No types are removed or renamed. Two P2 findings: missing dedicated regression test in internal/test/issues/ and a misleading template comment that now applies to response types. Neither blocks merging.

pkg/codegen/templates/param-types.tmpl — the comment template wording is now visibly incorrect for response types.

Important Files Changed

Filename Overview
pkg/codegen/operations.go Core bug fix: adds missing loop over op.Responses[].Contents[].Schema to collect AdditionalTypes, matching the existing pattern for params and bodies. Change is minimal and correct.
examples/extensions/xgotypename/api.yaml Adds a GET /example path with an inline response schema using x-go-type-name: ResponseRenamed to demonstrate and test the bug fix.
examples/extensions/xgotypename/gen.go Regenerated output now includes ResponseRenamed struct; comment says "defines parameters for ExampleGet" which is misleading for a response type (pre-existing template wording issue).
internal/test/any_of/codegen/inline/openapi.gen.go Newly emits GetPets200JSONResponse_Data_Item (union type) that was previously missing from generated output; additive change, no breakage.
internal/test/strict-server/chi/types.gen.go Adds UnionExample200JSONResponse0 = string type alias previously missing; identical diff across all strict-server backends (chi, echo, fiber, gin, gorilla, iris, stdhttp).
internal/test/issues/issue-1277/content-array.gen.go Newly emits Test200JSONResponse_Item with full additional-properties marshaling support that was previously missing; proportionate to the bug fix.
internal/test/name_conflict_resolution/name_conflict_resolution.gen.go Adds four PatchResource response type aliases that were previously missing; additive change, no drift beyond the expected fix.

Reviews (1): Last reviewed commit: "Add missing case to type generation trav..." | Re-trigger Greptile

Fixes: oapi-codegen#1306

GenerateTypeDefsForOperation() was extracting AdditionalTypes from
params and request bodies, but not from response content schemas.
This meant that x-go-type-name on an inline response schema was
silently ignored — the type definition was created internally but
never collected for output.

Add the missing loop over op.Responses[].Contents[].Schema to
extract AdditionalTypes, matching the existing pattern for params
and bodies. Extend the xgotypename example with a response-level
x-go-type-name test case.

Due to this bug, we've neglected to generate types for any types
defined inline in responses, so a lot of generated files were
affected due to those types being missing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mromaszewicz

Copy link
Copy Markdown
Member Author

@heww - When things our out for review, I intend to merge them, but they often wait on code review or some other gating feature.

We changed our code review policies so that I can now work through my backlog. There's no need to remind me to push :) My goal is 0 open PR and 0 open issues.

@mromaszewicz mromaszewicz merged commit 7787164 into oapi-codegen:main Apr 29, 2026
17 checks passed
@mromaszewicz mromaszewicz deleted the fix/issue-1306 branch April 29, 2026 21:18
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.

x-go-type-name isn't working when used in responses section

2 participants