directus-extension-api-docs 1.4.0 → 1.4.2
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 +8 -4
- package/dist/index.js +1 -1
- package/package.json +62 -62
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ components:
|
|
|
55
55
|
|
|
56
56
|
## Definitions (optional)
|
|
57
57
|
|
|
58
|
-
For each custom endpoints group, you can define
|
|
58
|
+
For each custom endpoints group, you can define api's including a file `oas.yaml` in root path of your group folder.
|
|
59
59
|
|
|
60
60
|
Properties:
|
|
61
61
|
|
|
@@ -81,14 +81,14 @@ paths:
|
|
|
81
81
|
content:
|
|
82
82
|
application/json:
|
|
83
83
|
schema:
|
|
84
|
-
"$ref": "#/components/schemas/
|
|
84
|
+
"$ref": "#/components/schemas/UserId"
|
|
85
85
|
responses:
|
|
86
86
|
'200':
|
|
87
87
|
description: Successful request
|
|
88
88
|
content:
|
|
89
89
|
application/json:
|
|
90
90
|
schema:
|
|
91
|
-
"$ref": "#/components/schemas/
|
|
91
|
+
"$ref": "#/components/schemas/Users"
|
|
92
92
|
'401':
|
|
93
93
|
description: Unauthorized
|
|
94
94
|
content: {}
|
|
@@ -98,6 +98,10 @@ paths:
|
|
|
98
98
|
'500':
|
|
99
99
|
description: Server Error
|
|
100
100
|
content: {}
|
|
101
|
+
components:
|
|
102
|
+
schemas:
|
|
103
|
+
Users:
|
|
104
|
+
type: object # ref to standard components declaring it empty
|
|
101
105
|
```
|
|
102
106
|
|
|
103
107
|
## Validations (optional)
|
|
@@ -120,7 +124,7 @@ module.exports = {
|
|
|
120
124
|
handler: async function registerEndpoint(router, { services, getSchema }) {
|
|
121
125
|
|
|
122
126
|
const schema = await getSchema();
|
|
123
|
-
await validate(router, services, schema); // Enable validator
|
|
127
|
+
await validate(router, services, schema); // Enable validator
|
|
124
128
|
|
|
125
129
|
router.post('/my-endpoint', async (req, res, next) => {
|
|
126
130
|
...
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("js-yaml"),s=require("path"),n=require("fs"),t=process.cwd();let o;async function i(e,s){if(o)return JSON.parse(o);const{SpecificationService:n}=e,t=new n({accountability:{admin:!0},schema:s});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,s){return Object.entries(s).reduce(((e,[s,n])=>(e[s]=n&&"object"==typeof n?a(e[s]=e[s]||(Array.isArray(n)?[]:{}),n):n,e)),e)}const r=require("swagger-ui-express"),c=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),u=function(){try{const o=s.join(t,"./extensions/endpoints/oasconfig.
|
|
1
|
+
"use strict";const e=require("js-yaml"),s=require("path"),n=require("fs"),t=process.cwd();let o;async function i(e,s){if(o)return JSON.parse(o);const{SpecificationService:n}=e,t=new n({accountability:{admin:!0},schema:s});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,s){return Object.entries(s).reduce(((e,[s,n])=>(e[s]=n&&"object"==typeof n?a(e[s]=e[s]||(Array.isArray(n)?[]:{}),n):n,e)),e)}const r=require("swagger-ui-express"),c=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),u=function(){try{const o=s.join(t,"./extensions/endpoints/oasconfig.yaml"),i=e.load(n.readFileSync(o,{encoding:"utf-8"})),r=s.join(t,"./extensions/endpoints"),c=n.readdirSync(r,{withFileTypes:!0});for(const s of c){const t=`${r}/${s.name}/oas.yaml`;if(s.isDirectory()&&n.existsSync(t)){const s=e.load(n.readFileSync(t,{encoding:"utf-8"}));i.tags=[...i.tags,...s.tags],i.paths={...i.paths,...s.paths},i.components=a(i.components||{},s.components||{})}}return i}catch(e){return{}}}(),d=(null==u?void 0:u.docsPath)||"api-docs";var l={id:d,validate:async function(e,s,n,t){if(null==u?void 0:u.paths){const o=await i(s,n);if(t)for(const e of t)o.paths[e]=u.paths[e];else o.paths=u.paths;u.components?o.components=u.components:(delete o.components.definitions,delete o.components.schemas),e.use(c.middleware({apiSpec:o})),e.use(((e,s,n,t)=>{n.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(e,{services:s,exceptions:n,logger:t,getSchema:o})=>{const{ServiceUnavailableException:c}=n,l={swaggerOptions:{url:`/${d}/oas`}};e.use("/",r.serve),e.get("/",r.setup({},l)),e.get("/oas",(async(e,n,r)=>{try{const e=await o(),r=await i(s,e),c=require(`${await p(".")}/package.json`);r.info.title=c.name,r.info.version=c.version,r.info.description=c.description;try{if(null==u?void 0:u.paths)for(const e in u.paths)r.paths[e]=u.paths[e];if(null==u?void 0:u.tags)for(const e of u.tags)r.tags.push(e);(null==u?void 0:u.components)&&(r.components=a(u.components,r.components))}catch(e){t.info("No custom definitions")}n.json(r)}catch(e){return r(new c(e.message||e[0].message))}}))}};module.exports=l;
|
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "directus-extension-api-docs",
|
|
3
|
-
"version": "1.4.
|
|
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
|
-
"js-yaml": "^4.1.0",
|
|
39
|
-
"swagger-ui-express": "^4.6.0"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@babel/preset-env": "^7.20.2",
|
|
43
|
-
"@directus/extensions-sdk": "^9.20.4",
|
|
44
|
-
"@types/express": "^4.17.14",
|
|
45
|
-
"@types/jest": "^29.2.3",
|
|
46
|
-
"@types/node": "^18.11.9",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
48
|
-
"@typescript-eslint/parser": "^5.43.0",
|
|
49
|
-
"babel-jest": "^29.3.1",
|
|
50
|
-
"eslint": "^8.27.0",
|
|
51
|
-
"eslint-config-prettier": "^8.5.0",
|
|
52
|
-
"eslint-plugin-import": "^2.26.0",
|
|
53
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
54
|
-
"express": "^4.18.2",
|
|
55
|
-
"jest": "^29.3.1",
|
|
56
|
-
"jest-extended": "^3.1.0",
|
|
57
|
-
"openapi-schema-validator": "^12.0.2",
|
|
58
|
-
"prettier": "^2.7.1",
|
|
59
|
-
"ts-jest": "^29.0.3",
|
|
60
|
-
"ts-node": "^10.9.1",
|
|
61
|
-
"typescript": "^4.9.3"
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "directus-extension-api-docs",
|
|
3
|
+
"version": "1.4.2",
|
|
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
|
+
"js-yaml": "^4.1.0",
|
|
39
|
+
"swagger-ui-express": "^4.6.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@babel/preset-env": "^7.20.2",
|
|
43
|
+
"@directus/extensions-sdk": "^9.20.4",
|
|
44
|
+
"@types/express": "^4.17.14",
|
|
45
|
+
"@types/jest": "^29.2.3",
|
|
46
|
+
"@types/node": "^18.11.9",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.43.0",
|
|
49
|
+
"babel-jest": "^29.3.1",
|
|
50
|
+
"eslint": "^8.27.0",
|
|
51
|
+
"eslint-config-prettier": "^8.5.0",
|
|
52
|
+
"eslint-plugin-import": "^2.26.0",
|
|
53
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
54
|
+
"express": "^4.18.2",
|
|
55
|
+
"jest": "^29.3.1",
|
|
56
|
+
"jest-extended": "^3.1.0",
|
|
57
|
+
"openapi-schema-validator": "^12.0.2",
|
|
58
|
+
"prettier": "^2.7.1",
|
|
59
|
+
"ts-jest": "^29.0.3",
|
|
60
|
+
"ts-node": "^10.9.1",
|
|
61
|
+
"typescript": "^4.9.3"
|
|
62
|
+
}
|
|
63
63
|
}
|