Server variables

Server variable object

Server variables are used when you need to make a substitution into the server URL such as when the subdomain is unique per tenant.

Field Name Type Description
default string REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the Schema Object's treatment of default values, because in those cases parameter values are optional. If the enum is defined, the value MUST exist in the enum's values.
enum [string] An enumeration of string values to be used if the substitution options are from a limited set. The array MUST NOT be empty. If defined, the array MUST contain the default value.
description string An optional description for the server variable.

Visuals

The following example defines a server variable project with a default value of app.

Copy
Copied
servers:
  - url: https://{project}.redoc.ly
    description: Hosted docs
    variables:
      project:
        default: app
        description: The project name

The default server variable value displays in the documentation when expandDefaultServerVariables: true.

default server variable substituted into server url

The placeholder server variable value displays in the documentation when expandDefaultServerVariables: false.

server variable substituted into server url

The try it console has server variable fields regardless of that setting.

try it console server variable fields

Types

  • ServerVariable
Copy
Copied
const ServerVariable: NodeType = {
  properties: {
    enum: {
      type: 'array',
      items: { type: 'string' },
    },
    default: { type: 'string' },
    description: null,
  },
  required: ['default'],
};