Skip to content

fix(client): don't reject unexpected success when no 2xx is declared - #90

Merged
lightsofapollo merged 1 commit into
gpu-cli:mainfrom
iamralch:fix/default-only-response-dead-branch
Oct 2, 2026
Merged

lightsofapollo merged 1 commit into
gpu-cli:mainfrom
iamralch:fix/default-only-response-dead-branch

Conversation

@iamralch

@iamralch iamralch commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes the first half of #89: the duplicated status.is_success() branch. The variant naming it also mentions (AmberStrict_2) is left for a separate PR.

What was wrong

An operation that declares no 2xx response, such as one with only a default response, selects every successful status, so its success guard is status.is_success() itself. The branch after it, which rejects successful statuses the return type didn't select, tested the same condition:

if status.is_success() {
    Ok(())
} else if status.is_success() {
    Err(/* unexpected successful status */)
} else {
    // ...
}

It couldn't be reached, and clippy's deny-by-default ifs_same_cond rejected the generated client.

The change

generate_error_handling emits the branch only when there are selected statuses to reject (!success.statuses.is_empty()). That covers the buffered path, which is the one clippy caught, and the binary and streaming paths, where the same check was nested inside the else and just as unreachable.

Tests

  • tests/default_only_response_test.rs: a default-only operation tests status.is_success() once and has no unexpected-success branch, and an operation with a declared 204 still rejects other successes. It fails before this change.
  • cargo test --all-features: 719 passed, none failed.
  • tests/corpus-manifest.txt is regenerated. scripts/gen-diff.sh upstream/main shows 15 specs moved, all in client.rs, by 342 removed branches. For cloudflare (43), github (8) and google-youtube (83), removing exactly those branches from the base output gives the new output byte for byte. The +141 lines in the Cloudflare diff are git aligning similar functions differently.

cargo clippy --all-features -- -D warnings reports one nonminimal_bool in src/schema_roundtrip.rs with clippy 0.1.93. It's on main as well, so it isn't from this change.

An operation that declares no 2xx response, such as one with only a
`default` response, selects every successful status: its success guard
is `status.is_success()` itself. The branch after it, which rejects the
successful statuses the return type didn't select, tested the same
condition, so it couldn't be reached, and clippy's deny-by-default
`ifs_same_cond` rejected the generated client.

The branch is now emitted only when there are selected statuses to
reject, in the buffered, binary and streaming paths alike.

The corpus moves for the 15 specs with such operations, by exactly those
342 branches.

Refs gpu-cli#89: the duplicated branch, not the variant names.
@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 aed1589 into gpu-cli:main Oct 2, 2026
1 check failed
iamralch added a commit to cf-contrib/cloudflare-rs that referenced this pull request Oct 3, 2026
openapi-to-rust's main has gpu-cli/openapi-to-rust#90, #91 and #92,
which no release has yet:

- Builders compile for every operation, so they're on: an operation with
  more than three optional parameters also has a `*_builder()`, and
  `zones_get_builder().per_page(50.0).send()` replaces ten positional
  Options.
- Requiredness-only unions that say `type: object` are constraints, so
  the overlay no longer removes them from Email Sending and Magic WAN.
- An operation with only a `default` response has no duplicated branch,
  so clippy::ifs_same_cond is no longer allowed.

The generator is a git dependency at a pinned commit until a release.
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.

2 participants