fix: pointer skipping for client query params#2330
Conversation
Closes: oapi-codegen#2329 Parameter-level x-go-type-skip-optional-pointer: true on a map- or slice-typed query parameter produced a struct field without a pointer (correct) but a client builder that still dereferenced it (*params.Field), so the generated package failed to compile. The params-struct path in GenStructFromSchema already read the parameter-level extension; DescribeParameters did not, leaving Schema.SkipOptionalPointer false on the ParameterDefinition that backs the client template. Mirror the override there. Also extend ZeroValueIsNil to recognize map[K]V so the emitted nil-check is not dropped when the optional pointer is skipped. Adds a regression fixture under internal/test/issues/issue-2329 covering both the deepObject map and form-style slice cases. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR fixes a compile error introduced when Confidence Score: 5/5Safe to merge — the fix is narrowly scoped, includes a compile-verified regression test, and the generated fixture diff is consistent with the stated change. No P0/P1 issues found. The two-part fix (propagating the extension in No files require special attention.
|
| Filename | Overview |
|---|---|
| pkg/codegen/operations.go | Core fix: propagates x-go-type-skip-optional-pointer extension from parameter level to ParameterDefinition.Schema; also extends ZeroValueIsNil to recognize map[K]V Go types |
| pkg/codegen/schema.go | Parallel fix: Property.ZeroValueIsNil extended to return true for map-typed properties, fixing nil-guard emission in custom MarshalJSON templates |
| internal/test/issues/issue-2329/issue2329.gen.go | Regression fixture: generated client now uses value types for Tags map[string]string and Labels []string params, guarded by != nil checks instead of pointer derefs |
| internal/test/components/components.gen.go | Regenerated: BodyWithAddPropsJSONBody.MarshalJSON now guards Inner map[string]int with a nil-check; nil map omitted instead of serialized as null |
| internal/test/issues/issue-2329/issue2329_test.go | Well-structured regression tests covering nil params, map serialization (deepObject), slice serialization (form), and custom MarshalJSON nil-omission |
| internal/test/issues/issue-2329/openapi.yaml | New OpenAPI fixture exercising both deepObject map and form-style array query params with x-go-type-skip-optional-pointer: true, plus a body schema with the same extension on properties |
| internal/test/issues/issue-2329/config.yaml | Standard codegen config enabling models+client generation for the regression fixture |
| internal/test/issues/issue-2329/generate.go | Standard go:generate directive for the regression fixture |
| pkg/codegen/schema_test.go | Adds test case for map-typed object schema returning true from ZeroValueIsNil, exercising the new GoType heuristic |
Reviews (3): Last reviewed commit: "fix: pointer skipping for body schema ma..." | Re-trigger Greptile
Property.ZeroValueIsNil mirrored ParameterDefinition.ZeroValueIsNil only for arrays. A map-typed property on a body schema with a custom MarshalJSON (i.e. one with additionalProperties or in oneOf/anyOf) and x-go-type-skip-optional-pointer: true emitted no nil-check, so an unset map field serialised as `"field":null` while an unset slice field with the same flag was omitted. Mirror the map-prefix check from operations.go so both kinds of zero value are treated consistently in the additional-properties / union / union-and-additional-properties templates. Extends the issue-2329 fixture with a Thing body schema covering both map and slice properties; the regression test marshals a zero-value Thing and asserts neither field appears in the JSON object. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Closes: #2329
Parameter-level x-go-type-skip-optional-pointer: true on a map- or slice-typed query parameter produced a struct field without a pointer (correct) but a client builder that still dereferenced it (*params.Field), so the generated package failed to compile.
The params-struct path in GenStructFromSchema already read the parameter-level extension; DescribeParameters did not, leaving Schema.SkipOptionalPointer false on the ParameterDefinition that backs the client template. Mirror the override there. Also extend ZeroValueIsNil to recognize map[K]V so the emitted nil-check is not dropped when the optional pointer is skipped.
Adds a regression fixture under internal/test/issues/issue-2329 covering both the deepObject map and form-style slice cases.