fix: allow x-go-type and x-go-type-skip-optional-pointer for allOf#1610
Conversation
This patch ensures that if a schema is defined using allOf the main schema entry's x-go-type and x-go-type-skip-optional-pointer values are considered instead of a random allOf member's.
Greptile SummaryThis PR fixes
Confidence Score: 3/5Merge with caution — a P1 inconsistency means the global PreferSkipOptionalPointer option is silently ignored for allOf schemas unless the author confirms this is intentional. One P1 finding (global default not propagated to allOf-merged path) brings the ceiling to 4; the missing test coverage for the actual schema.go change further reduces confidence to 3. pkg/codegen/schema.go — the SkipOptionalPointer propagation block around line 403.
|
| Filename | Overview |
|---|---|
| pkg/codegen/schema.go | Adds SkipOptionalPointer propagation to the allOf-merge return path; the global PreferSkipOptionalPointer default is not applied when the outer schema lacks an explicit x-go-type-skip-optional-pointer, inconsistent with all other code paths. |
| pkg/codegen/codegen_test.go | New unit test verifies x-go-type override for allOf schemas (Cat/Dog/Pet); does not cover the x-go-type-skip-optional-pointer change that is the actual diff in schema.go. |
| pkg/codegen/test_specs/x-go-type-pet-allof.yaml | New test fixture covering the discriminator/allOf + x-go-type scenario; no x-go-type-skip-optional-pointer usage included. |
Reviews (2): Last reviewed commit: "update PR for upstream changes" | Re-trigger Greptile
Address greptile review feedback and adapt to upstream main: - pkg/codegen/schema.go: simplify the allOf branch. Upstream main now catches x-go-type at the schema level via the combined extensions early return, so the PR's allOf-specific x-go-type override block is unreachable; remove it. Keep x-go-type-skip-optional-pointer propagation as a conditional override (only when the parent sets it explicitly), which preserves the decorator-idiom behavior MergeSchemas relies on for issue oapi-codegen#1957. Read from combined extensions for parity with the rest of GenerateGoSchema. - pkg/codegen/test_specs/x-go-type-pet-allof.yaml: add trailing newline.
|
@greptileai please review again after latest commits. |
Right now if a schema contains
x-go-type, for example:old behavior
The generated code will still take the pet as the
x-go-type:new behavior
This patch makes sure that we are generating the expected output:
This is a corner case, as in most cases the same type is used (e.g. splitting the ID from the CreateRequest but using the same underlying object), but in case we would want to compose the objects it would make sense to make this overridable on the parent level.
This patch doesn't introduce a breaking change, as if the x-go-* values are not set, the same inheritance will hapen.