From 9c10a394eb06479161209e5fe839be9d8424af6d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 18:41:39 +0000 Subject: [PATCH 1/2] fix: a property's x-go-name beside its $ref names its field A property that is a $ref took its field name from the referenced schema's x-go-name alone, so one written beside the reference was ignored, though a description there is read. go-api-libs/ibkr's portfolio summary has 50 properties of one SummaryValue type, each needing its own name. The property's own x-go-name now wins, the referenced schema's still serving where it has none; a tuple's items likewise. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y --- ir/schema.go | 4 ++-- ir/schema_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ir/schema.go b/ir/schema.go index 08f86cc0..a40b54a5 100644 --- a/ir/schema.go +++ b/ir/schema.go @@ -567,7 +567,7 @@ func getField(jsonName string, propRef *openapi.Schema, requiredSet map[string]b } fieldName := fieldGoName(jsonName) - if override := goNameOverride(v); override != "" { + if override := cmp.Or(goNameOverride(propRef), goNameOverride(v)); override != "" { fieldName = override } @@ -806,7 +806,7 @@ func fromTupleSchema(name string, s *openapi.Schema) (*Schema, error) { } fieldName := fmt.Sprintf("Item%0*d", width, i) - if override := goNameOverride(deref(p)); override != "" { + if override := cmp.Or(goNameOverride(p), goNameOverride(deref(p))); override != "" { fieldName = override } diff --git a/ir/schema_test.go b/ir/schema_test.go index df0cee3b..e043ab7d 100644 --- a/ir/schema_test.go +++ b/ir/schema_test.go @@ -1735,3 +1735,31 @@ func TestEnumConstNames(t *testing.T) { } } } + +// A property that is a $ref may name its field with an x-go-name of its own, beside the reference, as it may describe +// itself: many properties of one component type each get their own name. +func TestFromComponentSchemas_XGoNameBesideRef(t *testing.T) { + value := &openapi.Schema{Type: openapi.TypeObject} + + props := openapi.Schemas{} + props.Set("netliquidation", &openapi.Schema{ + Ref: &openapi.SchemaRef{Identifier: "#/components/schemas/SummaryValue", Value: value}, + Extensions: jsontext.Value(`{"x-go-name":"NetLiquidation"}`), + }) + + schemas := openapi.Schemas{} + schemas.Set("Summary", &openapi.Schema{Type: openapi.TypeObject, Properties: props}) + + got, err := ir.FromComponentSchemas(schemas) + if err != nil { + t.Fatal(err) + } + + if len(got) != 1 || len(got[0].Fields) != 1 { + t.Fatalf("unexpected schemas/fields: %+v", got) + } + + if f := got[0].Fields[0]; f.Name != "NetLiquidation" || f.JSONName != "netliquidation" { + t.Errorf("got field %q (json %q), want NetLiquidation (json netliquidation)", f.Name, f.JSONName) + } +} From e86db3ea1f297ac49d241b548b8a3ef8471d3b64 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 18:49:05 +0000 Subject: [PATCH 2/2] chore: oapi-codegen's other extensions that would fit go on the roadmap Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y --- docs/roadmap.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/roadmap.md b/docs/roadmap.md index 17dd1bc8..992d1f19 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -44,3 +44,30 @@ custom format, `date-time-ms`, like `date-basic`, makes them a `time.Time` in milliseconds, written and read through jsonutil helpers beside `TimeMarshalIntUnix`, in a body and a query parameter alike. openapi-enrich must keep the format when a recording's integer meets it. + +## More of oapi-codegen's extensions + +`x-go-name` and `x-enum-varnames` / `x-enumNames` work as in +[oapi-codegen](https://github.com/oapi-codegen/oapi-codegen/blob/main/docs/extensions.md), +a property's own extensions beside a `$ref` winning over the referenced +schema's. These would fit too, each as oapi-codegen has it, once a spec needs +it: + +- **`x-go-type` / `x-go-type-import`:** a field's or a type's Go type, given, + such as a decimal type for a number written as a string. +- **`x-go-type-skip-optional-pointer`:** an optional field without a pointer, + where its zero value needs no telling apart from its absence; see also "No + pointers in types only ever decoded". +- **`x-omitzero`:** `omitzero` on a field that would not otherwise have it. +- **`x-oapi-codegen-extra-tags`:** more struct tags on a field. +- **`x-deprecated-reason`:** a `Deprecated:` paragraph in a type's or field's + doc comment. +- **`x-order`:** a field's place in its struct, where the spec's order of + properties is not the one wanted. + +The others do not fit: `x-omitempty` is `x-omitzero`'s older form, +`x-go-type-name` a second way to name a type beside `x-go-name`, +`x-go-json-ignore` a property better left out of the spec, +`x-oapi-codegen-only-honour-go-name` an unexported field, and +`x-oapi-codegen-enum-merge` a choice between ways of merging one property's +enums across an `allOf`'s parts, which the generator does not merge.