Skip to content

Generate conditional objects (#157) - #141

Merged
rasuvaeff merged 1 commit into
masterfrom
feat/157-if-then-else
Oct 11, 2026
Merged

rasuvaeff merged 1 commit into
masterfrom
feat/157-if-then-else

Conversation

@rasuvaeff

Copy link
Copy Markdown
Owner

The contract side of #157 learned to evaluate if/then/else (openapi-contract#172); this package failed closed on the very same keyword, so a document the contract now accepts was still ungeneratable here.

How a conditional is generated. Each reachable side is built constructively. The then side is a conjunction of the base schema, the condition and the branch — the condition holds by construction rather than by filtering. The else side is built from the base schema and else, and filtered by the condition, which is what an unsatisfiable else looks like from the outside. A side the conditional does not declare is the base schema on that side, filtered the same way: the conditional leaves that side unchanged.

Boolean subschemas are honoured — if: false drops the then side outright, then: false makes that side unproducible. A side that yields no value is dropped from the choice rather than generated from and filtered eight times, and a conditional where neither side survives fails closed rather than looping on an exhausted filter.

The filter asks the contract's own SchemaCheck, so the branch a value takes here is the branch the validator will judge it by, encoded through the same JsonBodyEncoder the materializer uses — not a second opinion about what an object looks like on the wire.

Zoo. shipments.create: an expedited shipment must name a carrier, a standard one must not. Both sides are reachable, so the corpus the contract replays covers the keyword end to end.

Verification. 994 unit tests green plus the PHPUnit suite, psalm and php-cs-fixer clean, rector clean. A sample of 200 generated cases: 105 standard, 95 expedited, zero expedited shipments missing carrierCode.

The CI jobs check out openapi-contract master and symlink it over the installed package, so this branch runs against the contract as it will be once #172 merges.

A schema whose `then` requires a member the `else` does not is ordinary
OpenAPI 3.1, and this package failed closed on it — while
openapi-contract, which it depends on, learned to evaluate the very same
keyword.

The compiler now builds each reachable side constructively: `then` as a
conjunction of the base schema, the condition and the branch, so the
condition holds by construction rather than by filtering, and `else` from
the base schema and the branch, filtered by the condition. A side the
conditional does not declare is the base schema on that side, filtered the
same way. Boolean subschemas are honoured — `if: false` drops the `then`
side outright — a side that yields no value is dropped from the choice
rather than generated from and filtered, and a conditional where neither
side survives fails closed.

The filter asks the contract's own `SchemaCheck`, so the branch a value
takes here is the branch the validator will judge it by, encoded through
the same `JsonBodyEncoder` the materializer uses rather than a second
opinion about what an object looks like on the wire.

The zoo gains `shipments.create` — an expedited shipment must name a
carrier, a standard one must not — so both sides are reachable and the
recorded corpus covers the keyword end to end.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2fcc6fe0-5665-4beb-aa98-e9ff165ba2ea

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rasuvaeff
rasuvaeff merged commit 0051082 into master Oct 11, 2026
14 of 20 checks passed
@rasuvaeff
rasuvaeff deleted the feat/157-if-then-else branch October 11, 2026 16:20
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.

1 participant