Server and Authentication Extensions
Define environments and servers, set the server for an endpoint, add headers to every request, and extend Basic and OAuth 2.0 security schemes.
These extensions describe where your API runs and how clients authenticate with it.
Define environments and servers
x-server-configuration in the Info Object defines the environments your API runs in, the servers in each environment, and the parameters used in server URLs.
info:
title: Payments API
version: 1.0.0
x-server-configuration:
default-environment: production
default-server: api
environments:
- name: production
description: Live environment
servers:
- name: api
url: https://{region}.example.com
- name: auth
url: https://auth.example.com
- name: sandbox
servers:
- name: api
url: https://sandbox.example.com
- name: auth
url: https://auth.sandbox.example.com
parameters:
- name: region
description: Region the API is served from
schema:
type: string
enum: [us, eu]
default: us| Property | Type | Description |
|---|---|---|
default-environment | string | Environment used by default. Must be one of the environments below. |
default-server | string | Server used by default. Must exist in every environment. |
environments | array of Environment objects | The environments your API runs in |
parameters | array of Parameter Objects | Parameters used in server URLs, such as region in https://{region}.example.com |
An Environment object has a name, an optional description, and servers, an array of Server objects. Every environment must define the same set of server names.
A Server object has a name and a url. In OpenAPI 3.x, a server can also have its own parameters (Parameter Objects) or variables (Server Variable Objects) for the placeholders in its URL.
Give each URL parameter a default value. If a parameter has no default, APIMatic uses its example instead.
In OpenAPI 3.x, x-server-configuration replaces the root servers property: when the extension is present, APIMatic ignores servers. A ServerConfiguration override in the APIMatic Metadata file replaces the extension in turn.
Set the server for an endpoint
To send an endpoint's requests to a server other than the default server, set x-server-name in its Operation Object to the name of a server in your server configuration.
paths:
/token:
post:
operationId: createToken
x-server-name: authAdd headers to every request
x-additional-headers in a Security Scheme Object lists headers that are sent with every request, on top of the headers that authentication or parameters add.
components:
securitySchemes:
apiKey:
type: apiKey
in: header
name: X-API-Key
x-additional-headers:
- name: api-version
description: Version of the API to use
schema:
default: "2024-01-01"Each header has a name, an optional description, and a default value. In OpenAPI 3.x, put the default value in schema.default; in Swagger 2.0, put it in default.
Rename Basic authentication credentials
By default, Basic authentication takes a username and a password. To use different names, set these extensions in the Security Scheme Object:
| Extension | Type | Description |
|---|---|---|
x-rename-username-as | string | Name to use instead of username |
x-rename-password-as | string | Name to use instead of password |
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
x-rename-username-as: accountId
x-rename-password-as: apiSecretOAuth 2.0 extensions
In OpenAPI 3.x, add these extensions to an OAuth Flow Object inside flows. In Swagger 2.0, add them to the OAuth 2.0 Security Scheme Object.
| Extension | Type | Flows | Description |
|---|---|---|---|
x-skip-client-authentication | boolean | password | When true, the flow doesn't authenticate the client with a client ID and secret. |
x-oauth2-clientid-example | string | All except password with client authentication skipped | Example client ID |
x-oauth2-clientsecret-example | string | All except password with client authentication skipped | Example client secret |
x-oauth2-credentials-placement | header or body | All except password with client authentication skipped | Where the client ID and secret go when the client calls the token endpoint: in a Basic Authorization header or in the form-encoded request body. When you don't set it, the header placement from RFC 6749 applies. |
x-oauth2-username-example | string | password | Example username |
x-oauth2-password-example | string | password | Example password |
x-allow-additional-oauth-fields | boolean | All (3.x only) | When true, allows properties in the token response beyond the standard ones. |
x-additional-oauth-fields | map of Schema Objects | All (3.x only) | Additional properties that the token endpoint returns, by name |
x-revoke-token | object | All (3.x only) | The token revocation endpoint. See below. |
x-default-scopes | array of strings | All (3.x only) | Scopes used when the client doesn't choose any. Each must be one of the flow's scopes. |
x-revoke-token takes these properties. Their names are case-sensitive.
| Property | Type | Description |
|---|---|---|
Url | string | Required. URL of the token revocation endpoint. |
TokenType | string | Type of token to revoke, for example Refresh or Access |
TokenTypeHint | string | Hint about the type of the token sent for revocation |
components:
securitySchemes:
oauth2:
type: oauth2
flows:
clientCredentials:
tokenUrl: https://auth.example.com/oauth/token
scopes:
payments:read: Read payments
payments:write: Create payments
x-oauth2-clientid-example: my-client-id
x-oauth2-clientsecret-example: my-client-secret
x-oauth2-credentials-placement: body
x-default-scopes:
- payments:read
x-revoke-token:
Url: https://auth.example.com/oauth/revoke
TokenType: Access
x-additional-oauth-fields:
account_id:
type: stringName security options
Each item in a security array is a security option: a set of schemes that a client can use to authenticate. x-security-options-meta, next to security at the root or in an Operation Object, gives each option a name and a description.
security:
- {}
- apiKey: []
x-security-options-meta:
- name: No authentication
description: Limited access without credentials.
- name: API key
description: Full access with the API key from your account settings.The extension must have exactly one item per security option, in the same order. If the counts don't match, APIMatic ignores the extension and reports a warning.
APIMatic imports security options only when the ImportMultipleAuthentication import setting is true, which is the default. See Import and Export Settings.
OpenAPI Extensions Overview
The APIMatic extensions you can add to an OpenAPI 3.x or Swagger 2.0 definition, and what APIMatic imports from each.
Endpoint and Schema Extensions
Add deprecation details, rename parameters, describe pagination and event streams, and name and describe enums, discriminators, and error models.