Skip to content

Commit 8dd543a

Browse files
committed
upd. documentation
1 parent 6277a72 commit 8dd543a

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

README.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,41 @@
22

33
> Compatible with latest Directus versions and packaged extensions.
44
5-
Directus Extension to include:
5+
Directus Extension providing:
66

7-
- a Swagger interface
8-
- configurable autogenerated openapi specifications file
9-
-- including custom endpoints definitions
10-
- validation middleware on your custom endpoints (based on your openapi specifications). See below for details
7+
- a Swagger UI interface (OpenAPI 3.x)
8+
- an autogenerated OpenAPI specification file (merged core + your custom endpoints)
9+
-- including custom endpoint definitions
10+
- optional validation middleware for your custom endpoints (based on merged OpenAPI spec). See details below
1111

1212
![workspace](assets/swagger.png)
1313

1414
## Prerequisites
1515

16-
Working in a Directus nodejs project
16+
You must already have a Directus Node.js project running.
1717

1818
Ref: https://github.com/directus/directus
1919

2020
## Installation
2121

22-
npm install directus-extension-api-docs
22+
npm install directus-extension-api-docs
2323

2424
- Swagger interface: by default `http://localhost:8055/api-docs`
2525
- Openapi documentation: by default `http://localhost:8055/api-docs/oas`
2626

2727
## Configuration (optional)
2828

29-
To include you custom endpoints in your documentation.
30-
31-
Create a `oasconfig.yaml` file under `/extensions` folder.
29+
To include your custom endpoints in the documentation, create an `oasconfig.yaml` file directly under the `/extensions` folder (recommended structure). Avoid placing it under `/extensions/endpoints` unless using Legacy mode.
3230

3331
Options:
3432

35-
- `docsPath` _optional_ path where the interface will be (default 'api-docs')
33+
- `docsPath` _optional_ interface base path (default 'api-docs'). Resulting URLs: `/<docsPath>` and `/<docsPath>/oas`.
3634
- `info` _optional_ openapi server info (default extract from package.json)
3735
- `tags` _optional_ openapi custom tags (will be merged with all standard and all customs tags)
38-
- `publishedTags` _optional_ if specified, will be published definitions only for specified tags
39-
- `paths` _optional_ openapi custom paths (will be merged with all standard and all customs paths)
40-
- `components` _optional_ openapi custom components (will be merged with all standard and all customs tags)
41-
- `useAuthentication` _optional_ (default false). When enabled, access to `/api-docs` and `/api-docs/oas` requires a Directus admin cookie, static token, or Bearer JWT. Authorization is applied per endpoint based on Directus Access Policies, ensuring users only see endpoints they are allowed to access.
36+
- `publishedTags` _optional_ if specified, only operations containing at least one of these tags are kept; all other paths and unused tags are removed.
37+
- `paths` _optional_ custom path objects keyed by full path (e.g. `/my-custom-path/my-endpoint`). These are merged into Directus core paths.
38+
- `components` _optional_ custom components (schemas, securitySchemes, etc.) shallow-merged over core components.
39+
- `useAuthentication` _optional_ (default false). When true, `/api-docs` and `/api-docs/oas` stay publicly reachable: without valid auth they list only anonymous/public paths (no custom endpoints); with auth they list only paths permitted to that user under Directus Access Policies and custom endpoints.
4240

4341
Example below:
4442

@@ -71,15 +69,15 @@ components:
7169

7270
## Definitions (optional)
7371

74-
For each endpoint extension, you can define api's including a file `oas.yaml` in root path of your extension endpoint folder.
72+
For each endpoint extension, you can define OpenAPI partials by adding an `oas.yaml` file in the root of that endpoint's folder.
7573

7674
Properties:
7775

7876
- `tags` _optional_ openapi custom tags
7977
- `paths` _optional_ openapi custom paths
8078
- `components` _optional_ openapi custom components
8179

82-
Exemple below (`./extensions/my-endpoint-extensions/oas.yaml`) :
80+
Example below (`./extensions/my-endpoint-extensions/oas.yaml`):
8381

8482
```
8583
tags:
@@ -129,7 +127,7 @@ components:
129127

130128
### Legacy mode
131129

132-
Configuration and definitions can also be managed in this structure:
130+
Configuration and definitions can also be managed in this legacy structure (still supported, but prefer the simplified root placement):
133131

134132
```
135133
- ./extensions/
@@ -143,11 +141,11 @@ Configuration and definitions can also be managed in this structure:
143141

144142
## Validations (optional)
145143

146-
You can enable a request validations middleware based on your custom definitions.
144+
You can enable a request validation middleware based on your merged custom definitions.
147145

148-
Call `validate` function inside your custom endpoint source (`./extensions/my-endpoint-extensions/src/index.js`).
146+
Call the `validate` function inside your custom endpoint source (`./extensions/my-endpoint-extensions/src/index.js`).
149147

150-
Pass your `router`, `services`, `schema` and a list (_optional_) of endpoints you want to validate.
148+
Arguments: `validate(router, services, schema, paths?)`. `paths` (optional array) lets you restrict validation to only specific path keys from `oasconfig.yaml` instead of all custom paths.
151149

152150
Example below:
153151

tests/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('filterPaths', () => {
7878
const oasConfig: oasConfig = {
7979
docsPath: 'api-docs',
8080
info: {},
81+
useAuthentication: true,
8182
tags: [],
8283
components: {},
8384
publishedTags: ['tag2'],

0 commit comments

Comments
 (0)