Pre-release. Parity is not publicly available yet: the CLI, the GitHub Action and the hosted workspace open at launch. The demo runs on example data.

Skip to content

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.

yaml
sources:
  - openapi: ./openapi.yaml

Or without a configuration file:

bash
parity compare --baseline http://localhost:8080 --candidate http://localhost:8081 --openapi openapi.yaml

Generation 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

bash
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:

  1. an example (on the parameter, the media type or the schema), the first of examples, or a default, if present;
  2. otherwise a const or the first enum value;
  3. otherwise a value built from the type: "string", a number inside minimum / maximum, and format-specific strings for date-time, date, email, uuid, uri, hostname, ipv4, ipv6 and byte.

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 suffixRequest
#validRequired parameters only, examples preferred.
#valid:all_parametersEvery optional parameter included (only when the operation has optional parameters).
#valid:random-NSeeded 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.

KindWhat is sentApplies to
missing_requiredThe request without one required member or parameterRequired body members; required query and header parameters
nullnull in place of the valueBody members
numeric_boundaryThe minimum, one step below it, the maximum, one step above it. Without a bound: 0, -1, and 2147483648Integers and numbers
invalid_enumA value outside the enum (__parity_invalid_enum__)Members and parameters with enum
empty"", [] or {}; and an empty object as the whole bodyStrings without an enum, arrays, objects
string_lengthA string exactly at minLength, one below it, exactly at maxLength, one above itStrings with length bounds
invalid_typeA string where a number, boolean or object is expected; a number where a string is expected; an object where an array is expectedEverything

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:

yaml
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:

yaml
paths:
  /internal/metrics:
    get:
      x-parity-skip: true
      responses:
        "200": { description: OK }

or filter in parity.yaml, which leaves the document untouched:

yaml
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 as string, and both versions will usually answer 404. That still compares the not-found behaviour, but it does not exercise the endpoint. Add an example that exists in both environments:

    yaml
    parameters:
      - name: orderId
        in: path
        required: true
        schema: { type: string }
        example: ord_demo
  • Mutating 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.

    Loading the index…