Import OpenAPI Guide
Overview#
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.
Apache APISIX Dashboard supports importing OpenApi3.0(we will use OAS3.0 for short) files, both json and yaml are supported, to create one or more Routes. Currently we support most of the OpenApi specifications, but there are some differences, which are in terms of compatibility and extended fields.
Extended fields#
There are some fields required in APISIX Route but are not included in the properties of OAS3.0, in order to provide convenience for extending custom route entities based on OAS3.0, we added some extended fields such as upstream, plugins, hosts and so on. All extensions start with x-apisix.
| Extended fields | APISIX Route Properties |
|---|---|
| x-apisix-plugins | plugins |
| x-apisix-script | script |
| x-apisix-upstream | upstream |
| x-apisix-host | host |
| x-apisix-hosts | hosts |
| x-apisix-remote_addr | remote_addr |
| x-apisix-priority | priority |
| x-apisix-vars | vars |
| x-apisix-filter_func | filter_func |
| x-apisix-labels | labels |
| x-apisix-enable_websocket | enable_websocket |
| x-apisix-status | status |
| x-apisix-service_id | service_id |
| x-apisix-upstream_id | upstream_id |
Please pay attention that we only extended the first level of the field, and the sub level fields will still keep the same. Just take x-apisix-upstream for an example.
See reference for more details of the APISIX Route Properties
OAS3.0 Compatibility#
When we import routes from OAS3.0, some fields in OAS3.0 will be missed because there are not corresponding fields in APISIX's Route:
- API General Info: used to describe the general information about your API, some times, a OAS3.0 file contains a series of apis which belong to a app, so this info is different from the api's name and extra basic info.
Example:
- API server and base path: upsream url + url prefix(options).
Example:
- Path params: api params described in path.
Example:
- Query params: api params described in query.
Example:
- Responses description and links: Define the responses for a API operations.
Example:
Examples about how to Configure the OAS3.0 in different user scenarios#
Configure a basic published route#
notice: the default status of the imported route will be unpublished, which means the route can not be accessed, if you want to import a published route, you should add x-apisix-status: 1 in you OAS3.0 file
configure a route with plugins#
notice: most plugins supported by extended field x-apisix-plugins
configure a route with parameters validation#
notice: for plugin request-validation, we will use Parameter Serialization for header parameters validation and Describing Request Body for body parameters validation in OAS3.0
configure a route with auth plugins#
notice: for plugin basic-auth、jwt-auth and key-auth we will use Authentication in OAS3.0
configure a route with exist service or upstream#
notice: if the service_id or upstream_id does not exist in APISIX, import route from the config file will get an error
configure more than one route#
FAQ#
- What is the default strategy when import a duplicate route?
Currently we reject import duplicate route, that is to say when you import a route which has the same attributes, all of the URI、Host、URIs、Host、RemoteAddrs、RemoteAddr、Priority、Vars and FilterFunc, as the existing route, you will get an error while importing a route from OAS3.0.