Skip to content

Fix Upload width/height: spec truth over wire quirk#171

Merged
jeremy merged 2 commits intomainfrom
upload-dims
Mar 11, 2026
Merged

Fix Upload width/height: spec truth over wire quirk#171
jeremy merged 2 commits intomainfrom
upload-dims

Conversation

@jeremy
Copy link
Copy Markdown
Member

@jeremy jeremy commented Mar 11, 2026

Summary

  • Reverts the Smithy spec for Upload width/height from Double back to Integer (the type truth — pixel dimensions are integers)
  • Adds types.FlexInt, a custom Go type that unmarshals from any JSON number whose value is integral and within int32 range
  • Wires FlexInt through enhance-openapi-go-types.sh via x-go-type, following the established types.Date pattern for wire-format mismatches
  • FlexInt stays in the generated layer only — the hand-written Upload struct exposes plain int, with conversion at the boundary

The previous fix (4d7ec42) changed the spec itself to Double, making it lie about the data type. This fix keeps the spec honest and handles the Go-specific unmarshaling quirk where it belongs — in the Go type system.

Closes #168

Design decisions

  • Validation: FlexInt rejects non-integral values (1024.5) and int32 overflow (1e20) with errors, matching the int32 schema in openapi.json. No silent truncation or saturation.
  • Public API surface: Upload.Width and Upload.Height remain plain int in the hand-written struct. FlexInt is an internal detail of the generated client layer, converted at the uploadFromGenerated boundary.
  • Enhancement scope: The FlexInt rule targets components.schemas.Upload.properties specifically, not all width/height fields globally, avoiding surprises if integer width/height appears elsewhere in the spec.

Test plan

  • go test ./go/pkg/types/... — FlexInt unit tests (int, float, zero, negative, fractional rejection, overflow rejection, marshal, round-trip)
  • go test ./go/pkg/basecamp/... — Upload unmarshal tests go through generated→conversion path with 1024.0 fixtures
  • make smithy-check — OpenAPI in sync with Smithy
  • make go-check-drift — Service layer in sync with generated client
  • make check — Full CI suite passes

Copilot AI review requested due to automatic review settings March 11, 2026 03:43
@jeremy jeremy requested a review from a team as a code owner March 11, 2026 03:43
@github-actions github-actions bot added go spec Changes to the Smithy spec or OpenAPI labels Mar 11, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 11, 2026

Spec Change Impact

Changes in Spec

  • Modified: The Upload operation now has updated behavior to correctly interpret width and height fields as per spec truth.
  • No new operations, types, or resources were added or removed.

SDK Regeneration

  • All SDKs require regeneration due to the update in field interpretation.

Breaking API Change

  • No breaking changes. The changes align the field behavior with the spec but do not remove any operations or fields.

SDK Update Checklist:

  • Go
  • TypeScript
  • Ruby
  • Kotlin
  • Swift

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="go/pkg/types/flexint.go">

<violation number="1" location="go/pkg/types/flexint.go:18">
P2: Use `math.Round(f)` instead of truncating. Truncation toward zero means a value like `1023.9999999999998` (a plausible floating-point artifact for `1024`) would become `1023`. Rounding gives the semantically correct result for values that are conceptually integers.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ec8d4679d

ℹ️ 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".

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a wire-format mismatch for Upload.width/Upload.height by keeping the Smithy/OpenAPI spec semantically correct (integers) while making the Go SDK tolerant of the API’s float-encoded integer responses (e.g., 1024.0).

Changes:

  • Reverts Upload.width/height in Smithy/OpenAPI from double/number back to integer.
  • Introduces types.FlexInt in Go to unmarshal integer-like JSON floats into an integer type.
  • Extends the OpenAPI enhancement script to apply x-go-type: types.FlexInt for width/height, and regenerates the Go client/types accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/basecamp.smithy Changes Upload.width/height back to Integer to keep the spec truthful.
scripts/enhance-openapi-go-types.sh Adds jq rule to map width/height integer schema fields to types.FlexInt.
openapi.json Updates Upload.width/height schema to integer + Go type overrides (types.FlexInt).
go/pkg/types/flexint.go Adds FlexInt JSON marshal/unmarshal implementation.
go/pkg/types/flexint_test.go Adds unit tests for FlexInt JSON behavior.
go/pkg/generated/client.gen.go Updates generated Upload model to use types.FlexInt for width/height.
go/pkg/basecamp/vaults.go Updates public SDK Upload model to use types.FlexInt for width/height.
go/pkg/basecamp/vaults_test.go Updates assertions/formatting for new integer-like width/height type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The BC3 API serializes pixel dimensions as 1024.0 rather than 1024.
Go's encoding/json rejects float literals into int fields, unlike
every other language. FlexInt bridges this: an int32 that unmarshals
from any JSON number whose value is integral and in range. Follows
the types.Date pattern for wire-format mismatches resolved via
x-go-type.

Non-integral values and int32 overflow are rejected with errors,
matching the int32 schema in openapi.json.
@github-actions github-actions bot added the breaking Breaking change to public API label Mar 11, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 11, 2026

⚠️ Potential breaking changes detected:

  • Change in the Upload struct: Width and Height fields were changed from float64 to int, which is a breaking change as it modifies the type of exported fields.

Review carefully before merging. Consider a major version bump.

Copilot AI review requested due to automatic review settings March 11, 2026 04:19
@github-actions github-actions bot added the bug Something isn't working label Mar 11, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The previous fix (4d7ec42) changed the spec from Integer to Double to
work around Go's strict JSON unmarshaling. That made the spec lie —
pixel dimensions are integers; 1024.0 is a wire encoding detail.

Revert the Smithy spec to Integer and instead wire types.FlexInt
through the enhancement script's x-go-type mechanism, the same
pattern used for types.Date. The spec now tells the truth while Go
handles the wire quirk transparently.

FlexInt stays in the generated layer only — the hand-written Upload
struct exposes plain int, with conversion at the boundary in
uploadFromGenerated. The enhancement rule is scoped to the Upload
schema specifically, not applied by field name globally.
@jeremy jeremy enabled auto-merge (squash) March 11, 2026 04:31
@jeremy jeremy merged commit cc533eb into main Mar 11, 2026
48 checks passed
@jeremy jeremy deleted the upload-dims branch March 11, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change to public API bug Something isn't working go spec Changes to the Smithy spec or OpenAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated Upload type uses int32 for width/height but API returns floats

2 participants