OpenAPI generation
How Parity turns an OpenAPI 3 document into single-request scenarios — what is generated for each variation kind, how the set is bounded and seeded, and what it cannot cover.
Given an OpenAPI 3.x document, Parity builds one valid request for every operation and then varies it one aspect at a time. Each variation is a separate single-request scenario with a stable id.
sources:
- openapi: ./openapi.yamlOr without a configuration file:
parity compare --baseline http://localhost:8080 --candidate http://localhost:8081 --openapi openapi.yamlGeneration is rule-based. The result is a bounded, reproducible sample of the input space: it says nothing about inputs it did not try, and it is not a measure of coverage.
#What a scenario looks like
parity validate --list --filter "POST /orders*" openapi:POST /orders#valid POST /orders · valid request
openapi:POST /orders#valid:random-1 POST /orders · valid request, seeded sample 1
openapi:POST /orders#missing_required:body.customer_id POST /orders · `customer_id` omitted
openapi:POST /orders#missing_required:body.items POST /orders · `items` omitted
openapi:POST /orders#missing_required:body.items[0].quantity POST /orders · `items[0].quantity` omitted
…The id is openapi:<METHOD> <path template>#<variation>. It does not change when other operations are added or when the seed changes, so reviews and history can refer to it. Each scenario is tagged with the operation's OpenAPI tags and with its variation kind, so --tag missing_required runs only those.
#The valid request
For each operation Parity resolves $refs, merges allOf, and takes the first alternative of oneOf / anyOf. It then builds a value for every required parameter and for the JSON request body:
- an
example(on the parameter, the media type or the schema), the first ofexamples, or adefault, if present; - otherwise a
constor the firstenumvalue; - otherwise a value built from the type:
"string", a number insideminimum/maximum, and format-specific strings fordate-time,date,email,uuid,uri,hostname,ipv4,ipv6andbyte.
Only application/json-like request bodies are generated. Cookie parameters and the Authorization, Content-Type and Accept header parameters are skipped; authentication comes from the environment's auth.
Up to three kinds of valid scenario are produced:
| Id suffix | Request |
|---|---|
#valid | Required parameters only, examples preferred. |
#valid:all_parameters | Every optional parameter included (only when the operation has optional parameters). |
#valid:random-N | Seeded random choices: random enum members, random strings, optional parameters included by coin flip. generation.random_valid of these per operation (default 1). |
#Variations
Each variation changes exactly one thing in the valid request. Body variations go generation.max_depth levels into nested objects (default 4) and into the first element of arrays.
| Kind | What is sent | Applies to |
|---|---|---|
missing_required | The request without one required member or parameter | Required body members; required query and header parameters |
null | null in place of the value | Body members |
numeric_boundary | The minimum, one step below it, the maximum, one step above it. Without a bound: 0, -1, and 2147483648 | Integers and numbers |
invalid_enum | A value outside the enum (__parity_invalid_enum__) | Members and parameters with enum |
empty | "", [] or {}; and an empty object as the whole body | Strings without an enum, arrays, objects |
string_length | A string exactly at minLength, one below it, exactly at maxLength, one above it | Strings with length bounds |
invalid_type | A string where a number, boolean or object is expected; a number where a string is expected; an object where an array is expected | Everything |
The step for numeric boundaries is 1 for integers and 0.01 for numbers; exclusive bounds are honoured.
Query, path and header parameters get the same variations with two exceptions: values with no faithful URL encoding (null, arrays, objects) are not sent, and a path parameter is never omitted or emptied, because the request would address a different route.
Whether a variation should succeed is not Parity's concern. It sends the same request to both versions and compares what comes back. A request that both versions reject with the same 422 is unchanged; one that the baseline rejects and the candidate accepts is a difference — that is how the Shop API's loosened validation is found:
✗ POST /orders · `items[0].quantity` below its minimum (0) openapi · 1ms
~ Status changed from 422 Unprocessable Content to 201 Created.Choose kinds with generation.variations, and methods with generation.methods:
generation:
seed: 42
variations: [valid, missing_required, numeric_boundary]
methods: [GET, HEAD]#Bounding
Variation counts grow quickly with schema size, so generation is bounded twice.
Per operation (max_per_operation, default 40): valid requests are kept first; the remaining slots are filled by taking one variation from each kind in turn, so no kind crowds out the others. Within a kind, the order is a seeded shuffle.
Overall (max_scenarios, default 500): when the total exceeds the bound, scenarios are taken from every operation in turn, so no endpoint is starved by a larger one.
Which variations survive a cut depends only on the document and the seed.
#Seeding and reproducibility
Every random choice — random valid requests, the shuffle that decides which variations survive — is derived from generation.seed and the operation it belongs to. There is no other source of randomness.
- The same document, configuration and seed generate the same scenarios with the same ids and the same request bodies, on any machine.
- Changing the seed changes the random samples and, when bounds apply, which variations are kept.
--seed <N>overrides the configuration for one run. - Adding an operation to the document does not change the scenarios generated for other operations (unless the overall bound is reached).
The seed is printed in the run header and stored in the report as run.seed.
#Skipping operations
Mark an operation in the document:
paths:
/internal/metrics:
get:
x-parity-skip: true
responses:
"200": { description: OK }or filter in parity.yaml, which leaves the document untouched:
sources:
- openapi: ./openapi.yaml
include: ["* /orders*", "GET /products*"]
exclude: ["DELETE *"]#Limits
Requests are stateless. A generated scenario is one request. Behaviour that depends on earlier calls — reading back what a POST created, idempotency, state transitions — is out of reach. Use workflows for that.
Path parameters need examples. Without one,
GET /orders/{orderId}is sent with a placeholder such asstring, and both versions will usually answer 404. That still compares the not-found behaviour, but it does not exercise the endpoint. Add anexamplethat exists in both environments:yamlparameters: - name: orderId in: path required: true schema: { type: string } example: ord_demoMutating requests are sent. POST, PUT, PATCH and DELETE scenarios really do create and delete things. Parity only sends them to local addresses unless you authorise mutations.
Generated identifiers are not correlated. A response containing a server-generated ID will differ between the two versions. Ignore the field for the source (
compare: { ignore: [$.id] }) or use a workflow.Swagger 2.0 is not supported. Convert the document to OpenAPI 3.x first.
No claim of coverage. Parity does not measure which code paths or what share of the input space the scenarios reach, and an unchanged result is not a proof that two versions are equivalent.