Skip to content

fix: honor Binder behind an optional pointer - #198

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-196-binder-behind-pointer
Nov 23, 2026
Merged

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-196-binder-behind-pointer

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Part of #196 (2 of 2). This one is a behavior change; see below.

Problem

BindStringToObject checks for Binder on the destination as passed. For an optional field that is a **T, which never implements Binder, so the type fell through to the built-in conversion for its kind and Bind was never called.

With an integer type whose Bind accepts 50% and rejects anything over 100:

Where the type sits 50 50% 150
Top-level optional parameter (*Percent) 50 50 rejected
Required property of an exploded form object (Percent) 50 50 rejected
Optional property of an exploded form object (*Percent) 50 rejected: not an integer accepted as 150

The last row skipped the type's validation and refused its syntax.

Fix

Check for Binder again once the optional pointer has been dereferenced, so it has the same precedence in both cases. After this change the last row matches the other two.

Behavior change

Affects an optional property of an exploded form object (or any other caller passing a **T) whose type implements Binder and has a kind with a built-in conversion:

  • values Bind rejects but the primitive parser accepted are now errors (a 400 in generated servers);
  • values only Bind understands now bind;
  • a Bind that transforms its input now takes effect.

Types without a Bind method are unaffected. types.Date implements Binder, so an optional date property now goes through Date.Bind: it accepts the same values as before, including the empty string, but a malformed date reports the parse error without the previous error parsing '…' as date prefix.

Worth a line in the release notes.

The companion PR (fallback for types with no built-in conversion) is independent of this one and the two merge cleanly in either order.

🤖 Generated with Claude Code

BindStringToObject checks for Binder on the destination as passed. For
an optional field that is a **T, which never implements Binder, so the
type fell through to the built-in conversion for its kind. An integer
type with a Bind method was parsed as a plain integer: its validation
was skipped and any syntax of its own was refused. The same type bound
through Bind as a required field or as a top-level optional parameter.

Check again once the optional pointer has been dereferenced, so that a
Binder has the same precedence in both cases.

This changes the result for an optional property of an exploded form
object whose type has a primitive kind and implements Binder: values
which Bind rejects are now errors, values only Bind understands now
bind, and a Bind which transforms its input now takes effect. Types
without a Bind method are unaffected. types.Date binds the same values
as before, though a malformed date now reports the error from Date.Bind.

Part of oapi-codegen#196

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner November 23, 2026 00:15
@mromaszewicz mromaszewicz added bug Something isn't working ☢️ breaking change labels Nov 23, 2026
@mromaszewicz
mromaszewicz merged commit ee84079 into oapi-codegen:main Nov 23, 2026
10 checks passed
@mromaszewicz
mromaszewicz deleted the fix/issue-196-binder-behind-pointer branch November 23, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ breaking change bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant