# Scenarios and extensions

Source: https://apigenie.pl/docs/reference/server/scenarios
Part of the reference of [apigenie-server](https://apigenie.pl/docs/reference/server.md).
Its other pages: [Responses](https://apigenie.pl/docs/reference/server/responses.md), [Scripts](https://apigenie.pl/docs/reference/server/scripts.md), [Document store](https://apigenie.pl/docs/reference/server/store.md), [Several services](https://apigenie.pl/docs/reference/server/services.md), [Validation and security](https://apigenie.pl/docs/reference/server/validation.md), [Contract testing (validating proxy)](https://apigenie.pl/docs/reference/server/contract-testing.md), [Session recording and replay](https://apigenie.pl/docs/reference/server/recording.md), [AsyncAPI](https://apigenie.pl/docs/reference/server/asyncapi.md), [Protobuf / gRPC](https://apigenie.pl/docs/reference/server/grpc.md), [GraphQL](https://apigenie.pl/docs/reference/server/graphql.md), [Configuration](https://apigenie.pl/docs/reference/server/configuration.md), [Dashboard and admin API](https://apigenie.pl/docs/reference/server/dashboard.md), [TLS](https://apigenie.pl/docs/reference/server/tls.md).

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.

```yaml
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](/docs/reference/cli/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.

```yaml
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](/docs/reference/server/store#crud-resources)); on a response, `delay`, `latency`, `jitter` and `headers`.
