|
| 1 | +--- |
| 2 | +title: OpenAPI Specification |
| 3 | +description: Generate and access the OpenAPI 3.0 specification for the Plane public REST API using drf-spectacular. |
| 4 | +keywords: plane, developer tools, openapi, api specification, swagger, redoc, drf-spectacular, api documentation |
| 5 | +--- |
| 6 | + |
| 7 | +# OpenAPI Specification |
| 8 | + |
| 9 | +Plane uses [drf-spectacular](https://drf-spectacular.readthedocs.io/) to generate an OpenAPI 3.0 specification for the public REST API (`/api/v1/`). The feature is **disabled by default** and must be explicitly enabled. |
| 10 | + |
| 11 | +## Enable the OpenAPI spec |
| 12 | + |
| 13 | +Add the following to your `.env` file (at the project root or `apps/api/.env`): |
| 14 | + |
| 15 | +```env |
| 16 | +ENABLE_DRF_SPECTACULAR=1 |
| 17 | +``` |
| 18 | + |
| 19 | +Then restart the API server so it picks up the new variable. |
| 20 | + |
| 21 | +| Variable | Required value | Default | Description | |
| 22 | +| ------------------------ | -------------- | ------- | ------------------------------------------------------------ | |
| 23 | +| `ENABLE_DRF_SPECTACULAR` | `1` | `0` | Activates drf-spectacular and registers the schema endpoints | |
| 24 | + |
| 25 | +No other environment variables are needed — everything else (schema path prefix, tags, auth schemes, servers) is pre-configured in `apps/api/plane/settings/openapi.py`. |
| 26 | + |
| 27 | +## Access the OpenAPI spec |
| 28 | + |
| 29 | +> Replace `{domain_name}` below with your self-hosted Plane domain (e.g. `plane.example.com`). |
| 30 | +
|
| 31 | +Once the API server is running with the variable enabled, three endpoints are available: |
| 32 | + |
| 33 | +| Endpoint | URL | Description | |
| 34 | +| ----------------------------- | ---------------------------------------------- | -------------------------- | |
| 35 | +| `GET /api/schema/` | `https://{domain_name}/api/schema/` | Raw OpenAPI schema (YAML) | |
| 36 | +| `GET /api/schema/swagger-ui/` | `https://{domain_name}/api/schema/swagger-ui/` | Interactive Swagger UI | |
| 37 | +| `GET /api/schema/redoc/` | `https://{domain_name}/api/schema/redoc/` | ReDoc documentation viewer | |
| 38 | + |
| 39 | +## Download the OpenAPI spec |
| 40 | + |
| 41 | +### Browser |
| 42 | + |
| 43 | +Open `https://{domain_name}/api/schema/` and save the page. The default format is YAML. |
| 44 | + |
| 45 | +For JSON, append the `format` query parameter: |
| 46 | + |
| 47 | +```text |
| 48 | +https://{domain_name}/api/schema/?format=openapi-json |
| 49 | +``` |
| 50 | + |
| 51 | +### curl |
| 52 | + |
| 53 | +```bash |
| 54 | +# YAML |
| 55 | +curl -o openapi.yaml https://{domain_name}/api/schema/ |
| 56 | + |
| 57 | +# JSON |
| 58 | +curl -o openapi.json https://{domain_name}/api/schema/?format=openapi-json |
| 59 | +``` |
| 60 | + |
| 61 | +### Management command (offline, no running server required) |
| 62 | + |
| 63 | +```bash |
| 64 | +# From apps/api/ |
| 65 | +ENABLE_DRF_SPECTACULAR=1 python manage.py spectacular --file openapi.yaml |
| 66 | +ENABLE_DRF_SPECTACULAR=1 python manage.py spectacular --file openapi.json --format openapi-json |
| 67 | +``` |
0 commit comments