directus-extension-api-docs 1.3.3 → 1.3.5
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.
- package/README.md +125 -125
- package/dist/index.js +1 -1
- package/package.json +61 -61
package/README.md
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
# directus-extension-api-docs
|
|
2
|
-
|
|
3
|
-
Directus Extension to include a Swagger interface and custom endpoints definitions
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
All directus endpoints are autogenerated on runtime.
|
|
8
|
-
|
|
9
|
-
**You can enable validations middleware based on your custom definitions. See below**
|
|
10
|
-
|
|
11
|
-
## Prerequisites
|
|
12
|
-
|
|
13
|
-
Working in a Directus nodejs project
|
|
14
|
-
|
|
15
|
-
Ref: https://github.com/directus/directus
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
npm install directus-extension-api-docs
|
|
20
|
-
|
|
21
|
-
## Configuration (optional)
|
|
22
|
-
|
|
23
|
-
For include you custom endpoints.
|
|
24
|
-
|
|
25
|
-
Create a `oasconfig.js` file under `/extensions/endpoints` folder.
|
|
26
|
-
|
|
27
|
-
Options:
|
|
28
|
-
|
|
29
|
-
- `docsPath` _optional_ path where the interface will be (default 'api-docs')
|
|
30
|
-
- `tags` _optional_ openapi custom tags
|
|
31
|
-
- `paths` _optional_ openapi custom paths
|
|
32
|
-
- `components` _optional_ openapi custom components (you can ref to directus standard components declaring them empty)
|
|
33
|
-
|
|
34
|
-
Example below:
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
module.exports = {
|
|
38
|
-
docsPath: 'api-docs'
|
|
39
|
-
tags: [
|
|
40
|
-
{
|
|
41
|
-
name: 'MyCustomTag',
|
|
42
|
-
description: 'MyCustomTag description',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
paths: {
|
|
46
|
-
'/my-custom-path/my-endpoint': {
|
|
47
|
-
post: {
|
|
48
|
-
summary: 'do something',
|
|
49
|
-
description: 'do something',
|
|
50
|
-
requestBody: {
|
|
51
|
-
content: {
|
|
52
|
-
'application/json': {
|
|
53
|
-
schema: {
|
|
54
|
-
type: 'object',
|
|
55
|
-
required: ['field'],
|
|
56
|
-
properties: {
|
|
57
|
-
field: {
|
|
58
|
-
type: 'string',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
responses: {
|
|
65
|
-
'200': {
|
|
66
|
-
description: 'Successful request',
|
|
67
|
-
content: {
|
|
68
|
-
'application/json': {
|
|
69
|
-
schema: {
|
|
70
|
-
type: 'object',
|
|
71
|
-
properties: {
|
|
72
|
-
field: {
|
|
73
|
-
type: 'string',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
'401': {
|
|
81
|
-
description: 'Unauthorized',
|
|
82
|
-
content: {},
|
|
83
|
-
},
|
|
84
|
-
'404': {
|
|
85
|
-
description: 'Not Found',
|
|
86
|
-
content: {},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
tags: ['MyCustomTag', 'Assets'],
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
components: {},
|
|
95
|
-
};
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Validations (optional)
|
|
99
|
-
|
|
100
|
-
You can enable a request validations middleware based on your custom definitions.
|
|
101
|
-
|
|
102
|
-
Call `validate` function inside your custom endpoint registration.
|
|
103
|
-
|
|
104
|
-
Pass your `router`, `services`, `schema` and a list (_optional_) of endpoints you want to validate.
|
|
105
|
-
|
|
106
|
-
Example below:
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
const { validate } = require('directus-extension-api-docs');
|
|
110
|
-
|
|
111
|
-
const id = 'my-custom-path';
|
|
112
|
-
|
|
113
|
-
module.exports = {
|
|
114
|
-
id,
|
|
115
|
-
handler: async function registerEndpoint(router, { services, getSchema }) {
|
|
116
|
-
|
|
117
|
-
const schema = await getSchema();
|
|
118
|
-
await validate(router, services, schema); // Enable validator for custom endpoints
|
|
119
|
-
|
|
120
|
-
router.post('/my-endpoint', async (req, res, next) => {
|
|
121
|
-
...
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
```
|
|
1
|
+
# directus-extension-api-docs
|
|
2
|
+
|
|
3
|
+
Directus Extension to include a Swagger interface and custom endpoints definitions
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
All directus endpoints are autogenerated on runtime.
|
|
8
|
+
|
|
9
|
+
**You can enable validations middleware based on your custom definitions. See below**
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
|
|
13
|
+
Working in a Directus nodejs project
|
|
14
|
+
|
|
15
|
+
Ref: https://github.com/directus/directus
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
npm install directus-extension-api-docs
|
|
20
|
+
|
|
21
|
+
## Configuration (optional)
|
|
22
|
+
|
|
23
|
+
For include you custom endpoints.
|
|
24
|
+
|
|
25
|
+
Create a `oasconfig.js` file under `/extensions/endpoints` folder.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
|
|
29
|
+
- `docsPath` _optional_ path where the interface will be (default 'api-docs')
|
|
30
|
+
- `tags` _optional_ openapi custom tags
|
|
31
|
+
- `paths` _optional_ openapi custom paths
|
|
32
|
+
- `components` _optional_ openapi custom components (you can ref to directus standard components declaring them empty)
|
|
33
|
+
|
|
34
|
+
Example below:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
module.exports = {
|
|
38
|
+
docsPath: 'api-docs'
|
|
39
|
+
tags: [
|
|
40
|
+
{
|
|
41
|
+
name: 'MyCustomTag',
|
|
42
|
+
description: 'MyCustomTag description',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
paths: {
|
|
46
|
+
'/my-custom-path/my-endpoint': {
|
|
47
|
+
post: {
|
|
48
|
+
summary: 'do something',
|
|
49
|
+
description: 'do something',
|
|
50
|
+
requestBody: {
|
|
51
|
+
content: {
|
|
52
|
+
'application/json': {
|
|
53
|
+
schema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
required: ['field'],
|
|
56
|
+
properties: {
|
|
57
|
+
field: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
responses: {
|
|
65
|
+
'200': {
|
|
66
|
+
description: 'Successful request',
|
|
67
|
+
content: {
|
|
68
|
+
'application/json': {
|
|
69
|
+
schema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
field: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
'401': {
|
|
81
|
+
description: 'Unauthorized',
|
|
82
|
+
content: {},
|
|
83
|
+
},
|
|
84
|
+
'404': {
|
|
85
|
+
description: 'Not Found',
|
|
86
|
+
content: {},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
tags: ['MyCustomTag', 'Assets'],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
components: {},
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Validations (optional)
|
|
99
|
+
|
|
100
|
+
You can enable a request validations middleware based on your custom definitions.
|
|
101
|
+
|
|
102
|
+
Call `validate` function inside your custom endpoint registration.
|
|
103
|
+
|
|
104
|
+
Pass your `router`, `services`, `schema` and a list (_optional_) of endpoints you want to validate.
|
|
105
|
+
|
|
106
|
+
Example below:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
const { validate } = require('directus-extension-api-docs');
|
|
110
|
+
|
|
111
|
+
const id = 'my-custom-path';
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
id,
|
|
115
|
+
handler: async function registerEndpoint(router, { services, getSchema }) {
|
|
116
|
+
|
|
117
|
+
const schema = await getSchema();
|
|
118
|
+
await validate(router, services, schema); // Enable validator for custom endpoints
|
|
119
|
+
|
|
120
|
+
router.post('/my-endpoint', async (req, res, next) => {
|
|
121
|
+
...
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("
|
|
1
|
+
"use strict";const e=require("path"),s=process.cwd();let t;async function n(e,s){if(t)return JSON.parse(t);const{SpecificationService:n}=e,o=new n({accountability:{admin:!0},schema:s});return t=JSON.stringify(await o.oas.generate()),JSON.parse(t)}function o(e,s){return Object.entries(s).reduce(((e,[s,t])=>(e[s]=t&&"object"==typeof t?o(e[s]=e[s]||(Array.isArray(t)?[]:{}),t):t,e)),e)}const i=require("swagger-ui-express"),r=require("express-openapi-validator"),{findWorkspaceDir:a}=require("@pnpm/find-workspace-dir"),c=function(){try{return require(e.join(s,"./extensions/endpoints/oasconfig.js"))}catch(e){return{}}}(),p=(null==c?void 0:c.docsPath)||"api-docs";var u={id:p,validate:async function(e,s,t,o){if(null==c?void 0:c.paths){const i=await n(s,t);if(o)for(const e of o)i.paths[e]=c.paths[e];else i.paths=c.paths;c.components?i.components=c.components:(delete i.components.definitions,delete i.components.schemas),e.use(r.middleware({apiSpec:i})),e.use(((e,s,t,n)=>{t.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(e,{services:s,exceptions:t,logger:r,getSchema:u})=>{const{ServiceUnavailableException:d}=t,f={swaggerOptions:{url:`/${p}/oas`}};e.use("/",i.serve),e.get("/",i.setup({},f)),e.get("/oas",(async(e,t,i)=>{try{const e=await u(),i=await n(s,e),p=require(`${await a(".")}/package.json`);i.info.title=p.name,i.info.version=p.version,i.info.description=p.description;try{if(null==c?void 0:c.paths)for(const e in c.paths)i.paths[e]=c.paths[e];if(null==c?void 0:c.tags)for(const e of c.tags)i.tags.push(e);(null==c?void 0:c.components)&&(i.components=o(c.components,i.components))}catch(e){r.info("No custom definitions")}t.json(i)}catch(e){return i(new d(e.message||e[0].message))}}))}};module.exports=u;
|
package/package.json
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "directus-extension-api-docs",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "directus extension for swagger interface and custom endpoints definitions",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"!*.map"
|
|
10
|
-
],
|
|
11
|
-
"repository": "https://github.com/sacconazzo/directus-extension-api-docs",
|
|
12
|
-
"homepage": "https://github.com/sacconazzo/directus-extension-api-docs#readme",
|
|
13
|
-
"keywords": [
|
|
14
|
-
"directus",
|
|
15
|
-
"directus-extension",
|
|
16
|
-
"directus-custom-endpoint",
|
|
17
|
-
"swagger",
|
|
18
|
-
"custom endpoints",
|
|
19
|
-
"openapi definition",
|
|
20
|
-
"openapi"
|
|
21
|
-
],
|
|
22
|
-
"directus:extension": {
|
|
23
|
-
"type": "endpoint",
|
|
24
|
-
"path": "dist/index.js",
|
|
25
|
-
"source": "src/index.ts",
|
|
26
|
-
"host": "^9.19.2"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"test": "jest --verbose=true",
|
|
30
|
-
"lint": "eslint --ignore-path .gitignore --ext .ts tests/ src/",
|
|
31
|
-
"lint:fix": "pnpm lint --fix",
|
|
32
|
-
"build": "directus-extension build",
|
|
33
|
-
"dev": "directus-extension build -w --no-minify"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@pnpm/find-workspace-dir": "^5.0.0",
|
|
37
|
-
"express-openapi-validator": "^4.13.8",
|
|
38
|
-
"swagger-ui-express": "^4.6.0"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@babel/preset-env": "^7.20.2",
|
|
42
|
-
"@directus/extensions-sdk": "^9.20.4",
|
|
43
|
-
"@types/express": "^4.17.14",
|
|
44
|
-
"@types/jest": "^29.2.2",
|
|
45
|
-
"@types/node": "^18.11.9",
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
47
|
-
"@typescript-eslint/parser": "^5.
|
|
48
|
-
"babel-jest": "^29.3.1",
|
|
49
|
-
"eslint": "^8.27.0",
|
|
50
|
-
"eslint-config-prettier": "^8.5.0",
|
|
51
|
-
"eslint-plugin-import": "^2.26.0",
|
|
52
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
53
|
-
"express": "^4.18.2",
|
|
54
|
-
"jest": "^29.3.1",
|
|
55
|
-
"jest-extended": "^3.1.0",
|
|
56
|
-
"openapi-schema-validator": "^12.0.2",
|
|
57
|
-
"prettier": "^2.7.1",
|
|
58
|
-
"ts-jest": "^29.0.3",
|
|
59
|
-
"ts-node": "^10.9.1",
|
|
60
|
-
"typescript": "^4.8.4"
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "directus-extension-api-docs",
|
|
3
|
+
"version": "1.3.5",
|
|
4
|
+
"description": "directus extension for swagger interface and custom endpoints definitions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"!*.map"
|
|
10
|
+
],
|
|
11
|
+
"repository": "https://github.com/sacconazzo/directus-extension-api-docs",
|
|
12
|
+
"homepage": "https://github.com/sacconazzo/directus-extension-api-docs#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"directus",
|
|
15
|
+
"directus-extension",
|
|
16
|
+
"directus-custom-endpoint",
|
|
17
|
+
"swagger",
|
|
18
|
+
"custom endpoints",
|
|
19
|
+
"openapi definition",
|
|
20
|
+
"openapi"
|
|
21
|
+
],
|
|
22
|
+
"directus:extension": {
|
|
23
|
+
"type": "endpoint",
|
|
24
|
+
"path": "dist/index.js",
|
|
25
|
+
"source": "src/index.ts",
|
|
26
|
+
"host": "^9.19.2"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "jest --verbose=true",
|
|
30
|
+
"lint": "eslint --ignore-path .gitignore --ext .ts tests/ src/",
|
|
31
|
+
"lint:fix": "pnpm lint --fix",
|
|
32
|
+
"build": "directus-extension build",
|
|
33
|
+
"dev": "directus-extension build -w --no-minify"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@pnpm/find-workspace-dir": "^5.0.0",
|
|
37
|
+
"express-openapi-validator": "^4.13.8",
|
|
38
|
+
"swagger-ui-express": "^4.6.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/preset-env": "^7.20.2",
|
|
42
|
+
"@directus/extensions-sdk": "^9.20.4",
|
|
43
|
+
"@types/express": "^4.17.14",
|
|
44
|
+
"@types/jest": "^29.2.2",
|
|
45
|
+
"@types/node": "^18.11.9",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.43.0",
|
|
48
|
+
"babel-jest": "^29.3.1",
|
|
49
|
+
"eslint": "^8.27.0",
|
|
50
|
+
"eslint-config-prettier": "^8.5.0",
|
|
51
|
+
"eslint-plugin-import": "^2.26.0",
|
|
52
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
53
|
+
"express": "^4.18.2",
|
|
54
|
+
"jest": "^29.3.1",
|
|
55
|
+
"jest-extended": "^3.1.0",
|
|
56
|
+
"openapi-schema-validator": "^12.0.2",
|
|
57
|
+
"prettier": "^2.7.1",
|
|
58
|
+
"ts-jest": "^29.0.3",
|
|
59
|
+
"ts-node": "^10.9.1",
|
|
60
|
+
"typescript": "^4.8.4"
|
|
61
|
+
}
|
|
62
62
|
}
|