directus-extension-api-docs 1.4.4 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +7 -7
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.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;
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 r=require("swagger-ui-express"),c=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),l=function(){try{const o=n.join(t,"./extensions/endpoints/oasconfig.yaml"),i=e.load(s.readFileSync(o,{encoding:"utf-8"})),r=n.join(t,"./extensions/endpoints"),c=s.readdirSync(r,{withFileTypes:!0});for(const n of c){const t=`${r}/${n.name}/oas.yaml`;if(n.isDirectory()&&s.existsSync(t)){const n=e.load(s.readFileSync(t,{encoding:"utf-8"}));i.tags=[...i.tags,...n.tags],i.paths={...i.paths,...n.paths},i.components=a(i.components||{},n.components||{})}}return i}catch(e){return{}}}(),u=(null==l?void 0:l.docsPath)||"api-docs";var d={id:u,validate:async function(e,n,s,t){if(null==l?void 0:l.paths){const o=await i(n,s);if(t)for(const e of t)o.paths[e]=l.paths[e];else o.paths=l.paths;l.components?o.components=l.components:(delete o.components.definitions,delete o.components.schemas),e.use(c.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:c}=s,d={swaggerOptions:{url:`/${u}/oas`}};e.use("/",r.serve),e.get("/",r.setup({},d)),e.get("/oas",(async(e,s,r)=>{try{const e=await o(),r=await i(n,e);try{const e=require(`${await p(".")}/package.json`);(null==e?void 0:e.name)&&(r.info.title=null==e?void 0:e.name),(null==e?void 0:e.version)&&(r.info.version=null==e?void 0:e.version),(null==e?void 0:e.description)&&(r.info.description=null==e?void 0:e.description)}catch(e){}try{if(null==l?void 0:l.paths)for(const e in l.paths)r.paths[e]=l.paths[e];if(null==l?void 0:l.tags)for(const e of l.tags)r.tags.push(e);(null==l?void 0:l.components)&&(r.components=a(l.components,r.components))}catch(e){t.info("No custom definitions")}s.json(r)}catch(e){return r(new c(e.message||e[0].message))}}))}};module.exports=d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-extension-api-docs",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
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",
@@ -39,14 +39,13 @@
39
39
  "swagger-ui-express": "^4.6.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@babel/preset-env": "^7.20.2",
43
- "@directus/extensions-sdk": "^9.21.2",
42
+ "@directus/extensions-sdk": "^9.22.1",
43
+ "@directus/shared": "^9.22.1",
44
44
  "@types/express": "^4.17.15",
45
45
  "@types/jest": "^29.2.4",
46
- "@types/node": "^18.11.16",
47
- "@typescript-eslint/eslint-plugin": "^5.46.1",
48
- "@typescript-eslint/parser": "^5.46.1",
49
- "babel-jest": "^29.3.1",
46
+ "@types/node": "^18.11.18",
47
+ "@typescript-eslint/eslint-plugin": "^5.47.1",
48
+ "@typescript-eslint/parser": "^5.47.1",
50
49
  "eslint": "^8.30.0",
51
50
  "eslint-config-prettier": "^8.5.0",
52
51
  "eslint-plugin-import": "^2.26.0",
@@ -55,6 +54,7 @@
55
54
  "jest": "^29.3.1",
56
55
  "jest-extended": "^3.2.0",
57
56
  "openapi-schema-validator": "^12.1.0",
57
+ "pino": "^8.8.0",
58
58
  "prettier": "^2.8.1",
59
59
  "ts-jest": "^29.0.3",
60
60
  "ts-node": "^10.9.1",