directus-extension-api-docs 1.9.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +36 -16
  2. package/dist/index.js +4305 -1
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # directus-extension-api-docs
2
2
 
3
3
  Directus Extension to include
4
- - a Swagger interface
5
- - custom endpoints definitions
6
- - custom endpoints data validation based on your definitions
4
+
5
+ - a Swagger interface
6
+ - configurable autogenerated openapi documentation file
7
+ -- custom endpoint definitions included
8
+ - validation middleware on your custom endpoints (based on your openapi)
9
+
10
+ > Compatible with latest versions of Directus and monorepo installation with packaged extension.
7
11
 
8
12
  ![workspace](assets/swagger.png)
9
13
 
@@ -21,11 +25,14 @@ Ref: https://github.com/directus/directus
21
25
 
22
26
  npm install directus-extension-api-docs
23
27
 
28
+ - Swagger interface: by default `http:localhost:8055/api-docs`)
29
+ - Openapi documentation: by default `http://localhost:8055/api-docs/oas`)
30
+
24
31
  ## Configuration (optional)
25
32
 
26
- For include you custom endpoints.
33
+ To include you custom endpoints in your documentation.
27
34
 
28
- Create a `oasconfig.yaml` file under `/extensions/endpoints` folder.
35
+ Create a `oasconfig.yaml` file under `/extensions` folder.
29
36
 
30
37
  Options:
31
38
 
@@ -66,7 +73,7 @@ components:
66
73
 
67
74
  ## Definitions (optional)
68
75
 
69
- For each custom endpoints group, you can define api's including a file `oas.yaml` in root path of your group folder.
76
+ For each endpoint extension, you can define api's including a file `oas.yaml` in root path of your extension endpoint folder.
70
77
 
71
78
  Properties:
72
79
 
@@ -74,7 +81,7 @@ Properties:
74
81
  - `paths` _optional_ openapi custom paths
75
82
  - `components` _optional_ openapi custom components
76
83
 
77
- Exemple below (`./extensions/endpoints/my-custom-path/oas.yaml`) :
84
+ Exemple below (`./extensions/my-endpoint-extensions/oas.yaml`) :
78
85
 
79
86
  ```
80
87
  tags:
@@ -115,31 +122,44 @@ components:
115
122
  type: object # ref to standard components declaring it empty
116
123
  ```
117
124
 
125
+ ### Legacy mode
126
+
127
+ Configuration and definitions can also be managed in this structure:
128
+
129
+ ```
130
+ - ./extensions/
131
+ - endpoints/
132
+ - oasconfig.yaml
133
+ - my-endpoint-extensions/
134
+ - oas.yaml
135
+ - my-endpoint-extensions2/
136
+ - oas.yaml
137
+ ```
138
+
118
139
  ## Validations (optional)
119
140
 
120
141
  You can enable a request validations middleware based on your custom definitions.
121
142
 
122
- Call `validate` function inside your custom endpoint registration.
143
+ Call `validate` function inside your custom endpoint source (`./extensions/my-endpoint-extensions/src/index.js`).
123
144
 
124
145
  Pass your `router`, `services`, `schema` and a list (_optional_) of endpoints you want to validate.
125
146
 
126
147
  Example below:
127
148
 
128
149
  ```
129
- const { validate } = require('directus-extension-api-docs');
130
-
131
- const id = 'my-custom-path';
150
+ const { validate } = require('directus-extension-api-docs')
132
151
 
133
- module.exports = {
134
- id,
135
- handler: async function registerEndpoint(router, { services, getSchema }) {
152
+ const id = 'my-custom-path'
136
153
 
154
+ export default {
155
+ id: 'info',
156
+ handler: async (router, { services, getSchema }) => {
137
157
  const schema = await getSchema();
138
158
  await validate(router, services, schema); // Enable validator
139
159
 
140
160
  router.post('/my-endpoint', async (req, res, next) => {
141
161
  ...
142
- });
162
+ })
143
163
  },
144
- };
164
+ }
145
165
  ```