Skip to content

fix(client): builders take a body that declares variants whole - #92

Merged
lightsofapollo merged 2 commits into
gpu-cli:mainfrom
iamralch:fix/builder-variant-body
Oct 2, 2026
Merged

lightsofapollo merged 2 commits into
gpu-cli:mainfrom
iamralch:fix/builder-variant-body

Conversation

@iamralch

@iamralch iamralch commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #86.

What was wrong

An object that declares variants beside its properties is generated as a struct with a required variant field:

pub struct RenderRequest {
    pub timeout: Option<f64>,
    /// The variant this value takes, alongside the fields above.
    pub variant: RenderRequestVariant,
}

It has neither Default nor a constructor from its required properties. body_model_plan planned the builder's body from the properties alone, ignoring variant, and so called whichever constructor applied:

  • request: Default::default() when no property is required: the trait bound RenderRequest: Default is not satisfied;
  • request: CreateAppRequest::new(name) when some are, beside optional ones: no function or associated item named new.

The change

An object with variant: Some(_) is RequiredBodyConstruction::Whole: the builder takes the body as an argument, as it already does a body that is all required properties. Its optional properties keep their setters:

client.render_builder(request).a("x").timeout(1.0).send().await

Tests

  • builders_take_a_body_that_declares_variants_whole in tests/operation_builder_test.rs, beside the OpenAI composition case and in the same style: both shapes above generate builders that take the body, and a crate calling them, including a body field setter, cargo checks. It fails before this change.
  • cargo test --all-features: 719 passed, none failed.
  • The corpus manifest doesn't change, since the corpus is generated without builders.
  • Against the current cloudflare/api-schemas, with builders enabled, 0.19.0 fails with 20 of these errors in Browser Rendering, Magic WAN, Stream and others. With this change, the whole Cloudflare client compiles, with 843 builders.

This and #90/#91 all add a Fixed entry under [Unreleased] in CHANGELOG.md; I'll rebase whichever merges later.

An object that declares variants beside its properties is generated as
a struct with a required `variant` field, so it has neither `Default`
nor a constructor from its required properties. The builder planned the
body from its properties alone and called whichever applied:
`Default::default()` with no required property, `Body::new(..)` with
some, and neither compiled.

The builder now takes such a body as an argument, as it does a body
that is all required properties. Its optional properties keep their
setters.

The corpus doesn't change: it's generated without builders.

Fixes gpu-cli#86
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown

@iamralch is attempting to deploy a commit to the lbl-rd Team on Vercel.

A member of the Team first needs to authorize it.

@lightsofapollo
lightsofapollo merged commit 2e1f1db into gpu-cli:main Oct 2, 2026
12 of 13 checks passed
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.

Operation builders call Default::default() on a body with a oneOf beside its properties

2 participants