Repository navigation
Generate conditional objects (#157) - #141
Merged
Merged
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
thenside is a conjunction of the base schema, the condition and the branch — the condition holds by construction rather than by filtering. Theelseside is built from the base schema andelse, and filtered by the condition, which is what an unsatisfiableelselooks 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: falsedrops thethenside outright,then: falsemakes 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 sameJsonBodyEncoderthe 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-contractmaster and symlink it over the installed package, so this branch runs against the contract as it will be once #172 merges.