OpenAPI
Reference OpenAPI endpoints in your docs pages
To describe your endpoints with OpenAPI, make sure you have a valid OpenAPI document in either JSON or YAML format that follows the OpenAPI specification.
Your document must follow OpenAPI specification 3.0+.
Configuration Quickstart
The fastest way to get started with OpenAPI is to add an openapi field to api in the settings file.
This field can contain either the relative path to an OpenAPI document in your docs or the URL of a hosted OpenAPI document.
This will create a new route based on your OpenAPI specification at docs/api/rest/*.
You can also use URL-based paths to OpenAPI spec instead of local files.
Multi Spec Configuration
Creating multi API specs for more advanced use cases is also possible:
Thanks to this configuration, you'll have two routes: docs/api/rest/* and docs/api/webhooks/*.
API Docs Generation Guides
- The generator automatically creates documentation based on your OpenAPI specification
- Uses OpenAPI tags to create logical groups of endpoints
- Generates clean URLs from
operationIdwhen available - Organizes endpoints by path when no tags are specified
- Groups related schemas with their endpoints
- Links response schemas to their corresponding endpoints
All defaults can be overridden using the x-docs extension
X-Docs Extension
The x-docs extension provides additional configuration options to customize your API documentation beyond the standard OpenAPI specification. Use it to control sidebar structure, code snippets, and endpoint visibility.
Navigation Customization
To make your OpenAPI documentation more organized and user-friendly, you can customize the navigation structure using the x-docs extension. This allows you to group endpoints and schemas into logical sections and control their URLs.
Since xyd creates a sidebar by default based on tags and other OpenAPI Spec, x-docs gives you more control.
You can define a complete navigation structure using the sidebar property in the x-docs extension:
above example will create sidebar:
Learn MoreNavigation Customization Details
Route
The route property defines the base URL path for your API documentation. This is where all your API documentation pages will be served from.
If you define route in docs.json it will overwrite the route in OpenAPI spec.
Type
The type property in the sidebar configuration specifies what kind of content will be displayed. There are two main types:
-
endpoint: Used for API endpoints. Thekeycan be either:- A path and method combination (e.g.,
GET /users) - An
operationIdfrom your OpenAPI spec
- A path and method combination (e.g.,
-
object: Used for schema definitions. Thekeyshould match the schema name in your OpenAPI spec
Example:
Path
Adding a path for each of pages helps to create a clean and organized URLs in your API documentation. The path property determines the URL segment for each page in your documentation.
For example:
this configuration will generate URLs like:
/docs/api/rest/users/get/docs/api/rest/users/get-by-id
The final URL is constructed by combining the base route with the path segments from each level of the sidebar configuration.
Request Code Snippets
You can also specify supported programming languages for request code snippets using x-docs.codeLanguages:
this method generates code snippets based on specific request for defined languges.
Code Samples
If you have a code snippet already and dont wan't a generic, autogenerated one you can use x-codeSamples:
WebhooksComing Soon
Support for OpenAPI webhook documentation is currently in development and will be available in the future.
API Docs Demo
You can also check out our interactive API Docs Demo to see these features in action and experiment with different OpenAPI configurations in real-time.
OpenAPI Samples
Learn how to setup OpenAPI pages.
Show your support! Star us on GitHub ⭐️