Endpoint and Schema Extensions
Add deprecation details, rename parameters, describe pagination and event streams, and name and describe enums, discriminators, and error models.
These extensions add details to operations, parameters, responses, and schemas.
Add deprecation details
When an operation has deprecated: true, x-deprecation-details in its Operation Object adds more about the deprecation. APIMatic ignores the extension on operations that aren't deprecated.
| Property | Type | Description |
|---|---|---|
message | string | More information, such as the reason or the operation to use instead |
deprecatedInVersion | string | Version in which the operation was deprecated |
paths:
/pets:
post:
operationId: addPet
deprecated: true
x-deprecation-details:
message: Use createPet instead.
deprecatedInVersion: "2.0"Split the request body into parameters
OpenAPI allows one request body per operation. Set x-unwrap-body: true in the Operation Object to import each property of the body schema as a separate body parameter. The request still sends the parameters together as one object.
APIMatic unwraps the body only when its schema is an object with properties.
paths:
/pets:
post:
operationId: addPet
x-unwrap-body: true
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/NewPet"Rename a parameter
x-unique-name in a Parameter Object (OpenAPI 3.x) gives the parameter a different name in SDKs and docs. The request still uses the original name. Use it to tell apart parameters that share a name, or to replace a long or unclear name.
parameters:
- name: id
in: path
required: true
schema:
type: string
x-unique-name: orderId
- name: id
in: query
schema:
type: string
x-unique-name: customerIdPick a name that no other parameter of the operation uses. The OpenAPI v3 APIMatic Linting rule unique-parameter-name reports parameters whose names clash.
Add a parameter example
Swagger 2.0 has no example property for parameters. Set x-example in the Parameter Object instead.
parameters:
- name: status
in: query
type: string
x-example: availableDescribe pagination
x-pagination describes how an endpoint returns its results in pages. Add it to the Media Type Object of the success response, next to schema. It's an array with one entry per pagination strategy the endpoint supports.
| Property | Type | Used by | Description |
|---|---|---|---|
type | offset, page, cursor, or link | All | Pagination strategy |
result | pointer | All | Location of the items in the response |
input | pointer | offset, page, cursor | Request parameter that sets the offset, page number, or cursor |
output | pointer | cursor | Location of the next cursor in the response |
next | pointer | link | Location of the link to the next page in the response |
limit | pointer | offset, page | Optional. Request parameter that sets the page size. Must be an integer. |
totalItems | pointer | offset | Optional. Total number of items in the response. Must be an integer. |
totalPages | pointer | page | Optional. Total number of pages in the response. Must be an integer. |
hasMore | pointer | offset, page, cursor | Optional. Response value that says whether more results exist. Must be a boolean. |
A pointer is a runtime expression followed by a JSON pointer:
- Request values:
$request.query#/,$request.path#/,$request.headers#/, or$request.body#/, followed by the name, for example$request.query#/offset. - Response values:
$response.bodyfor the whole body, or$response.body#/or$response.headers#/followed by a path, for example$response.body#/data.
paths:
/payments:
get:
parameters:
- name: offset
in: query
schema:
type: integer
- name: limit
in: query
schema:
type: integer
responses:
"200":
description: A page of payments
content:
application/json:
schema:
$ref: "#/components/schemas/PaymentList"
x-pagination:
- type: offset
input: $request.query#/offset
limit: $request.query#/limit
result: $response.body#/data
totalItems: $response.body#/totalA cursor strategy reads the next cursor from the response:
x-pagination:
- type: cursor
input: $request.query#/cursor
output: $response.body#/next_cursor
result: $response.body#/data
hasMore: $response.body#/has_moreThe pagination rules are in the Pagination section of OpenAPI v3 APIMatic Linting. For which SDK languages support pagination, see Languages & Features.
Mark the end of an event stream
Some Server-Sent Events streams end with a frame that carries a fixed value, such as [DONE]. Set x-sse-sentinel in the text/event-stream Media Type Object of the success response to the exact data value of that frame.
responses:
"200":
description: A stream of completion chunks
content:
text/event-stream:
schema:
$ref: "#/components/schemas/CompletionChunk"
x-sse-sentinel: "[DONE]"In YAML, quote values that contain characters such as [ and ], so they're read as strings.
Name and describe enum values
x-enum-elements gives each value of an enum a name and a description. List one element per enum value, in the same order as enum. If the counts don't match, APIMatic ignores the extension.
components:
schemas:
Priority:
type: integer
enum: [1, 2, 3]
x-enum-elements:
- name: Low
description: Handle when convenient.
- name: Medium
description: Handle today.
- name: High
description: Handle now.In OpenAPI 3.x, add it to the Schema Object. In Swagger 2.0, add it to the Schema Object or to a Parameter Object that has an enum.
Name an enum model
APIMatic creates a model for each enum. To set the model's name:
- In OpenAPI 3.x, set
x-enum-model-namein the Schema Object. - In Swagger 2.0, set
x-enum-model-namein a Parameter Object that has anenum.
parameters:
- name: status
in: query
schema:
type: string
enum: [available, pending, sold]
x-enum-model-name: PetStatusSet a discriminator value
By default, the discriminator value of a schema is its name. To use a different value, set x-discriminator-value. In OpenAPI 3.x, add it to the Discriminator Object. In Swagger 2.0, add it to the Schema Object, next to discriminator.
components:
schemas:
Pet:
type: object
required: [petType]
properties:
petType:
type: string
discriminator:
propertyName: petType
x-discriminator-value: GenericPetMark a schema as dynamic
When a schema's shape isn't known or can't be described, set x-is-dynamic: true in its Schema Object. APIMatic imports it as a dynamic type instead of a typed model.
responses:
"200":
description: Any JSON value
content:
application/json:
schema:
type: object
x-is-dynamic: trueName an error model
APIMatic creates an error model from each schema that an error response uses. By default, the model is named after the schema, with an _Error suffix. To use a different name, set x-exception-model-name in the Schema Object.
components:
schemas:
BadRequest:
type: object
x-exception-model-name: ValidationError
properties:
message:
type: stringDate-time formats
OpenAPI's date-time format means RFC 3339. APIMatic reads two more values of the standard format property as date-time types:
| Type | Format | Meaning |
|---|---|---|
string | date-time | RFC 3339 date-time (standard) |
string | date-time-rfc1123 | RFC 1123 date-time |
number | unix-timestamp | Unix timestamp |
properties:
createdAt:
type: number
format: unix-timestampServer 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.
Webhook and Callback Extensions
Group webhooks and callbacks, route incoming events by a discriminator, and describe how to verify their signatures with x-webhooks and x-callbacks.