directus-extension-api-docs 1.4.6 → 1.5.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.
- package/README.md +5 -0
- package/dist/index.js +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ Create a `oasconfig.yaml` file under `/extensions/endpoints` folder.
|
|
|
27
27
|
Options:
|
|
28
28
|
|
|
29
29
|
- `docsPath` _optional_ path where the interface will be (default 'api-docs')
|
|
30
|
+
- `info` _optional_ openapi server info (default extract from package.json)
|
|
30
31
|
- `tags` _optional_ openapi custom tags (will be merged with all standard and all customs tags)
|
|
31
32
|
- `paths` _optional_ openapi custom paths (will be merged with all standard and all customs paths)
|
|
32
33
|
- `components` _optional_ openapi custom components (will be merged with all standard and all customs tags)
|
|
@@ -35,6 +36,10 @@ Example below:
|
|
|
35
36
|
|
|
36
37
|
```
|
|
37
38
|
docsPath: 'api-docs'
|
|
39
|
+
info:
|
|
40
|
+
title: my-directus-bo
|
|
41
|
+
version: 1.5.0
|
|
42
|
+
description: my server description
|
|
38
43
|
tags:
|
|
39
44
|
- name: MyCustomTag
|
|
40
45
|
description: MyCustomTag description
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("js-yaml"),n=require("path"),s=require("fs"),t=process.cwd();let o;async function i(e,n){if(o)return JSON.parse(o);const{SpecificationService:s}=e,t=new s({accountability:{admin:!0},schema:n});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,n){return Object.entries(n).reduce(((e,[n,s])=>(e[n]=s&&"object"==typeof s?a(e[n]=e[n]||(Array.isArray(s)?[]:{}),s):s,e)),e)}const
|
|
1
|
+
"use strict";const e=require("js-yaml"),n=require("path"),s=require("fs"),t=()=>process.cwd();let o;async function i(e,n){if(o)return JSON.parse(o);const{SpecificationService:s}=e,t=new s({accountability:{admin:!0},schema:n});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,n){return Object.entries(n).reduce(((e,[n,s])=>(e[n]=s&&"object"==typeof s?a(e[n]=e[n]||(Array.isArray(s)?[]:{}),s):s,e)),e)}const c=require("swagger-ui-express"),r=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),d=function(){const o=function(){const o={docsPath:"api-docs",info:{},tags:[],paths:{},components:{}};try{const i=n.join(t(),"./extensions/endpoints/oasconfig.yaml"),a=e.load(s.readFileSync(i,{encoding:"utf-8"}));return a.docsPath=a.docsPath||o.docsPath,a.info=a.info||o.info,a.tags=a.tags||o.tags,a.paths=a.paths||o.paths,a.components=a.components||o.components,a}catch{return o}}();try{const i=n.join(t(),"./extensions/endpoints"),c=s.readdirSync(i,{withFileTypes:!0});for(const n of c){const t=`${i}/${n.name}/oas.yaml`;if(n.isDirectory()&&s.existsSync(t)){const n=e.load(s.readFileSync(t,{encoding:"utf-8"}));o.tags=[...o.tags,...n.tags],o.paths={...o.paths,...n.paths},o.components=a(o.components||{},n.components||{})}}return o}catch(e){return o}}(),u=d.docsPath;var f={id:u,validate:async function(e,n,s,t){if(null==d?void 0:d.paths){const o=await i(n,s);if(t)for(const e of t)o.paths[e]=d.paths[e];else o.paths=d.paths;d.components?o.components=d.components:(delete o.components.definitions,delete o.components.schemas),e.use(r.middleware({apiSpec:o})),e.use(((e,n,s,t)=>{s.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(e,{services:n,exceptions:s,logger:t,getSchema:o})=>{const{ServiceUnavailableException:r}=s,f={swaggerOptions:{url:`/${u}/oas`}};e.use("/",c.serve),e.get("/",c.setup({},f)),e.get("/oas",(async(e,s,c)=>{try{const e=await o(),c=await i(n,e);try{const e=require(`${await p(".")}/package.json`);c.info.title=d.info.title||(null==e?void 0:e.name)||c.info.title,c.info.version=d.info.version||(null==e?void 0:e.version)||c.info.version,c.info.description=d.info.description||(null==e?void 0:e.description)||c.info.description}catch(e){}try{if(null==d?void 0:d.paths)for(const e in d.paths)c.paths[e]=d.paths[e];if(null==d?void 0:d.tags)for(const e of d.tags)c.tags.push(e);(null==d?void 0:d.components)&&(c.components=a(d.components,c.components))}catch(e){t.info("No custom definitions")}s.json(c)}catch(e){return c(new r(e.message||e[0].message))}}))}};module.exports=f;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-extension-api-docs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "directus extension for swagger interface and custom endpoints definitions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,23 +41,23 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@directus/extensions-sdk": "^9.22.4",
|
|
43
43
|
"@directus/shared": "^9.22.3",
|
|
44
|
-
"@types/express": "^4.17.
|
|
44
|
+
"@types/express": "^4.17.17",
|
|
45
45
|
"@types/jest": "^29.4.0",
|
|
46
|
-
"@types/node": "^18.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
-
"eslint": "^8.
|
|
46
|
+
"@types/node": "^18.13.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
49
|
+
"eslint": "^8.34.0",
|
|
50
50
|
"eslint-config-prettier": "^8.6.0",
|
|
51
51
|
"eslint-plugin-import": "^2.27.5",
|
|
52
52
|
"eslint-plugin-prettier": "^4.2.1",
|
|
53
53
|
"express": "^4.18.2",
|
|
54
|
-
"jest": "^29.4.
|
|
54
|
+
"jest": "^29.4.2",
|
|
55
55
|
"jest-extended": "^3.2.3",
|
|
56
56
|
"openapi-schema-validator": "^12.1.0",
|
|
57
|
-
"pino": "^8.
|
|
58
|
-
"prettier": "^2.8.
|
|
57
|
+
"pino": "^8.10.0",
|
|
58
|
+
"prettier": "^2.8.4",
|
|
59
59
|
"ts-jest": "^29.0.5",
|
|
60
60
|
"ts-node": "^10.9.1",
|
|
61
|
-
"typescript": "^4.9.
|
|
61
|
+
"typescript": "^4.9.5"
|
|
62
62
|
}
|
|
63
63
|
}
|