Skip to content

fix(apiquery): preserve narrow numeric parameters - #76

Open
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/apiquery-numeric-widths
Open

fix(apiquery): preserve narrow numeric parameters#76
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/apiquery-numeric-widths

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Preserve narrow Go numeric values when encoding URL query parameters.

Fixes #75.

Problem

internal/apiquery currently has two width-related serialization gaps:

  • int8 and uint8 are not included in the primitive integer cases, so they silently produce no query pair;
  • float32 shares the float64 formatting path and is passed to strconv.FormatFloat with bitSize=64, exposing precision introduced only when reflection widens the value to a Go float64.

A caller can therefore omit a legitimate numeric query parameter entirely, or send a decimal representation different from the source float32 value.

Reproduction

On upstream main at d082a010f7c6cacf407d8a1581446a7857f9f1bb:

values, _ := apiquery.Marshal(map[string]any{"value": int8(-8)})
// values.Encode() == ""

values, _ = apiquery.Marshal(map[string]any{"value": uint8(8)})
// values.Encode() == ""

values, _ = apiquery.Marshal(map[string]any{"value": float32(0.1)})
// values.Get("value") == "0.10000000149011612"

Root cause

The primitive switch omitted the 8-bit integer kinds and grouped both floating-point kinds behind:

strconv.FormatFloat(value.Float(), 'f', -1, 64)

reflect.Value.Float() returns a float64, but FormatFloat's bitSize argument is specifically what tells it whether the original value should be represented with 32-bit or 64-bit precision.

The sibling multipart/form encoder already follows that distinction for primitive values.

Fix

  • include reflect.Int8 with the signed integer kinds;
  • include reflect.Uint8 with the unsigned integer kinds;
  • format reflect.Float32 with bitSize=32;
  • retain bitSize=64 for reflect.Float64.

No query key formatting, array formatting, nesting rules, null handling, or existing wider numeric behavior changes.

Regression coverage

Extended the existing table-driven TestEncode cases with:

  • int8(-8) -> query=-8;
  • uint8(8) -> query=8;
  • float32(0.1) -> query=0.1.

These cases fail on current main for the reasons described above and exercise the real MarshalWithSettings path rather than an isolated helper.

Validation

The branch is based directly on current upstream main and is not behind it. The diff is limited to:

  • 6 additions / 3 deletions in internal/apiquery/encoder.go;
  • 12 lines of focused regression coverage in internal/apiquery/query_test.go.

Full repository validation is left to the repository's GitHub Actions checks.

Risk

Low. The change only fills missing primitive cases and uses the source floating-point width when choosing the standard-library formatting precision. Existing int, wider integer, and float64 output is unchanged.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 18, 2026 10:48
@markstuart-oai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T01:30:48.289653Z 889c71d Manual request
🔒 Security Review Completed 2026-09-06T01:32:35.230832Z 889c71d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 889c71d8cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 889c71d8cf

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query encoder drops int8/uint8 values and widens float32 precision

2 participants