Scenarios and extensions

A scenario is a named set of rules switched on and off together. A rule matches requests (by operationId, method, path, tag, headers or query) and sets the status, an example, a literal body, headers, the network simulation, or a probability. Scenarios come from the configuration, from x-apigenie-mock in the document, or from the admin API.

paths:
  /orders:
    get:
      x-apigenie-mock:
        delay: 200
        headers: {X-Region: eu}
        scenarios:
          empty: {body: []}
          broken: {status: 500, drop: {probability: 0.5, mode: reset}}

A schema can name the faker provider that generates its values with x-apigenie-mock-faker or x-faker: a name (person.firstName, internet.email, location.city…), {"number.int": [1, 10]} with arguments by position, {"string.alpha": {length: 6}} with arguments by name, or {provider: number.int, args: [1, 10], options: {...}}. Arguments are numbers, strings and booleans. Names of older faker.js versions (name.firstName, address.city, datatype.uuid) work too. An unknown name, or arguments the provider doesn’t take, are answered with 500 and faker’s message. Records (person.profile, location.address, finance.card…) are objects, or their JSON text for a string schema.

properties:
  owner: {type: string, x-faker: person.fullName}
  age: {type: integer, x-faker: {number.int: [18, 90]}}
  code: {type: string, x-faker: {string.alpha: {length: 6, casing: upper}}}
  customer: {type: object, x-faker: {person.profile: {country: PL}}}

With generation.smart_names, plain string properties called like email, first_name, city, zip_code or phone get such values without an extension. generation.null_probability sets how often a schema with OAS 3.0 nullable: true is answered with null.

x-apigenie-mock on an operation (or its path item) accepts status, example, dynamic, body, body_file, headers, latency, jitter, drop, bandwidth, delay, probability, validate_request, scenarios and resource (see CRUD resources); on a response, delay, latency, jitter and headers.

Was this helpful?