Bug Report Checklist
Description
Since #24349 ("Fix Golang pattern validation with regex fails on commas", merged 2026-07-19,
first released in v7.24.0), the Go client generator's UnmarshalJSON for oneOf models wraps the
"no match" error in an if err != nil { ... } else { ... } block to include the underlying error.
That block is generated inside a {{#oneOf}}...{{/oneOf}} Mustache section
(model_oneof.mustache#L82-L92):
} else { // no match
{{#oneOf}}
if err != nil {
return fmt.Errorf("data failed to match schemas in oneOf({{classname}}): %v", err)
} else {
return fmt.Errorf("data failed to match schemas in oneOf({{classname}})")
}
{{/oneOf}}
{{^oneOf}}
return fmt.Errorf("data failed to match schemas in oneOf({{classname}})")
{{/oneOf}}
}
The generated code still compiles (Go doesn't reject unreachable code after a return inside an
if/else where both branches return), so this doesn't break builds, but it produces obviously
wrong/duplicated dead code that shows up in every generated model with a multi-member oneOf.
This also reproduces in the project's own committed sample output from the same PR, e.g.
samples/client/others/go/oneof-anyof-required/model_object.go,
where the Object model has 2 oneOf members:
} else { // no match
if err != nil {
return fmt.Errorf("data failed to match schemas in oneOf(Object): %v", err)
} else {
return fmt.Errorf("data failed to match schemas in oneOf(Object)")
}
if err != nil {
return fmt.Errorf("data failed to match schemas in oneOf(Object): %v", err)
} else {
return fmt.Errorf("data failed to match schemas in oneOf(Object)")
}
}
openapi-generator version
Steps to reproduce
openapi: 3.0.3
info:
title: oneOf duplicate error block repro
version: "1.0"
paths:
/ping:
get:
operationId: ping
responses:
"200":
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/AreaId"
components:
schemas:
AreaId:
description: The identifier (ID) of an area.
oneOf:
- $ref: "#/components/schemas/StaticAreaID"
- type: string
StaticAreaID:
type: string
enum: [eu01, eu02]
Generate with:
openapi-generator-cli generate -g go -i spec.yaml -o out --additional-properties=disallowAdditionalPropertiesIfNotPresent=false
Actual output
out/model_area_id.go contains the duplicated if/else block in UnmarshalJSON (as shown above).
Expected output
The if/else block should be rendered exactly once per model, regardless of how many oneOf members
the schema has, e.g.:
} else { // no match
if err != nil {
return fmt.Errorf("data failed to match schemas in oneOf(AreaId): %v", err)
} else {
return fmt.Errorf("data failed to match schemas in oneOf(AreaId)")
}
}
Related issues/PRs
Bug Report Checklist
Description
Since #24349 ("Fix Golang pattern validation with regex fails on commas", merged 2026-07-19,
first released in v7.24.0), the Go client generator's
UnmarshalJSONforoneOfmodels wraps the"no match" error in an
if err != nil { ... } else { ... }block to include the underlying error.That block is generated inside a
{{#oneOf}}...{{/oneOf}}Mustache section(model_oneof.mustache#L82-L92):
The generated code still compiles (Go doesn't reject unreachable code after a
returninside anif/elsewhere both branches return), so this doesn't break builds, but it produces obviouslywrong/duplicated dead code that shows up in every generated model with a multi-member
oneOf.This also reproduces in the project's own committed sample output from the same PR, e.g.
samples/client/others/go/oneof-anyof-required/model_object.go,where the
Objectmodel has 2oneOfmembers:openapi-generator version
release built on top of it, and still present on
masteras of 2026-08-05)goSteps to reproduce
Generate with:
Actual output
out/model_area_id.gocontains the duplicated if/else block inUnmarshalJSON(as shown above).Expected output
The if/else block should be rendered exactly once per model, regardless of how many
oneOfmembersthe schema has, e.g.:
Related issues/PRs