directus-extension-api-docs 1.6.4 → 1.6.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 +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";const{findWorkspaceDir:s}=require("@pnpm/find-workspace-dir"),t=require("js-yaml"),e=require("path"),n=require("fs"),o=()=>process.cwd();let a;async function i(s,t){if(a)return JSON.parse(a);const{SpecificationService:e}=s,n=new e({accountability:{admin:!0},schema:t});return a=JSON.stringify(await n.oas.generate()),JSON.parse(a)}function r(s,t){return Object.entries(t).reduce(((s,[t,e])=>(s[t]=e&&"object"==typeof e?r(s[t]=s[t]||(Array.isArray(e)?[]:{}),e):e,s)),s)}const c=require("swagger-ui-express"),p=require("express-openapi-validator"),u=function(){const s=function(){const s={docsPath:"api-docs",info:{},tags:[],publishedTags:[],paths:{},components:{}};try{const a=e.join(o(),"./extensions/endpoints/oasconfig.yaml"),i=t.load(n.readFileSync(a,{encoding:"utf-8"}));return i.docsPath=i.docsPath||s.docsPath,i.info=i.info||s.info,i.tags=i.tags||s.tags,i.paths=i.paths||s.paths,i.components=i.components||s.components,i}catch{return s}}();try{const a=e.join(o(),"./extensions/endpoints"),i=n.readdirSync(a,{withFileTypes:!0});for(const e of i){const o=`${a}/${e.name}/oas.yaml`;if(e.isDirectory()&&n.existsSync(o)){const e=t.load(n.readFileSync(o,{encoding:"utf-8"}));s.tags=[...s.tags,...e.tags||[]],s.paths={...s.paths,...e.paths||{}},s.components=r(s.components||{},e.components||{})}}return s}catch(t){return s}}(),d=u.docsPath;var f={id:d,validate:async function(s,t,e,n){if(null==u?void 0:u.paths){const o=await i(t,e);if(n)for(const s of n)o.paths[s]=u.paths[s];else o.paths=u.paths;u.components?o.components=u.components:(delete o.components.definitions,delete o.components.schemas),s.use(p.middleware({apiSpec:o})),s.use(((s,t,e,n)=>{e.status(s.status||500).json({message:s.message,errors:s.errors})}))}return s},handler:(t,{services:e,exceptions:n,logger:a,getSchema:p})=>{const{ServiceUnavailableException:f}=n,h={swaggerOptions:{url:`/${d}/oas`}};t.use("/",c.serve),t.get("/",c.setup({},h)),t.get("/oas",(async(t,n,c)=>{try{const t=await p(),c=await i(e,t),d=await async function(){try{const t=await s(".");return require(`${t||o()}/package.json`)}catch(s){return{}}}();c.info.title=u.info.title||(null==d?void 0:d.name)||c.info.title,c.info.version=u.info.version||(null==d?void 0:d.version)||c.info.version,c.info.description=u.info.description||(null==d?void 0:d.description)||c.info.description;try{for(const s in u.paths)c.paths[s]=u.paths[s];for(const s of u.tags)c.tags.push(s);c.components=r(u.components,c.components)}catch(s){a.info("No custom definitions")}u.publishedTags&&function(s,t){for(const e in t.paths)for(const n in t.paths[e]){let o=!1;t.paths[e][n].tags.forEach((t=>{o=o||s.publishedTags.includes(t)})),t.paths[e][n].tags&&(t.paths[e][n].tags=t.paths[e][n].tags.filter((t=>s.publishedTags.includes(t)))),o||delete t.paths[e][n]}t.tags=t.tags.filter((t=>s.publishedTags.includes(t.name)))}(u,c),n.json(c)}catch(s){return c(new f(s.message||s[0].message))}}))}};module.exports=f;
1
+ "use strict";const{findWorkspaceDir:s}=require("@pnpm/find-workspace-dir"),t=require("js-yaml"),e=require("path"),n=require("fs"),o=()=>process.cwd();let a;async function i(s,t){if(a)return JSON.parse(a);const{SpecificationService:e}=s,n=new e({accountability:{admin:!0},schema:t});return a=JSON.stringify(await n.oas.generate()),JSON.parse(a)}function r(s,t){return Object.entries(t).reduce(((s,[t,e])=>(s[t]=e&&"object"==typeof e?r(s[t]=s[t]||(Array.isArray(e)?[]:{}),e):e,s)),s)}const c=require("swagger-ui-express"),p=require("express-openapi-validator"),u=function(){const s=function(){const s={docsPath:"api-docs",info:{},tags:[],publishedTags:[],paths:{},components:{}};try{const a=e.join(o(),"./extensions/endpoints/oasconfig.yaml"),i=t.load(n.readFileSync(a,{encoding:"utf-8"}));return i.docsPath=i.docsPath||s.docsPath,i.info=i.info||s.info,i.tags=i.tags||s.tags,i.paths=i.paths||s.paths,i.components=i.components||s.components,i}catch{return s}}();try{const a=e.join(o(),"./extensions/endpoints"),i=n.readdirSync(a,{withFileTypes:!0});for(const e of i){const o=`${a}/${e.name}/oas.yaml`;if(e.isDirectory()&&n.existsSync(o)){const e=t.load(n.readFileSync(o,{encoding:"utf-8"}));s.tags=[...s.tags,...e.tags||[]],s.paths={...s.paths,...e.paths||{}},s.components=r(s.components||{},e.components||{})}}return s}catch(t){return s}}(),d=u.docsPath;var f={id:d,validate:async function(s,t,e,n){if(null==u?void 0:u.paths){const o=await i(t,e);if(n)for(const s of n)o.paths[s]=u.paths[s];else o.paths=u.paths;u.components?o.components=u.components:(delete o.components.definitions,delete o.components.schemas),s.use(p.middleware({apiSpec:o})),s.use(((s,t,e,n)=>{e.status(s.status||500).json({message:s.message,errors:s.errors})}))}return s},handler:(t,{services:e,exceptions:n,logger:a,getSchema:p})=>{const{ServiceUnavailableException:f}=n,l={swaggerOptions:{url:`/${d}/oas`}};t.use("/",c.serve),t.get("/",c.setup({},l)),t.get("/oas",(async(t,n,c)=>{var d;try{const t=await p(),c=await i(e,t),f=await async function(){try{const t=await s(".");return require(`${t||o()}/package.json`)}catch(s){return{}}}();c.info.title=u.info.title||(null==f?void 0:f.name)||c.info.title,c.info.version=u.info.version||(null==f?void 0:f.version)||c.info.version,c.info.description=u.info.description||(null==f?void 0:f.description)||c.info.description;try{for(const s in u.paths)c.paths[s]=u.paths[s];for(const s of u.tags)c.tags.push(s);c.components=r(u.components,c.components)}catch(s){a.info("No custom definitions")}(null==(d=u.publishedTags)?void 0:d.length)&&function(s,t){for(const e in t.paths)for(const n in t.paths[e]){let o=!1;t.paths[e][n].tags.forEach((t=>{o=o||s.publishedTags.includes(t)})),t.paths[e][n].tags&&(t.paths[e][n].tags=t.paths[e][n].tags.filter((t=>s.publishedTags.includes(t)))),o||delete t.paths[e][n]}t.tags=t.tags.filter((t=>s.publishedTags.includes(t.name)))}(u,c),n.json(c)}catch(s){return c(new f(s.message||s[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.6.4",
3
+ "version": "1.6.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",