directus-extension-api-docs 1.2.6 → 1.2.7

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 CHANGED
@@ -107,13 +107,10 @@ const id = 'my-custom-path';
107
107
 
108
108
  module.exports = {
109
109
  id,
110
- handler: function registerEndpoint(router, { services, exceptions, logger }) {
110
+ handler: async function registerEndpoint(router, { services, getSchema }) {
111
111
 
112
- router.post('/my-endpoint-not-validated', async (req, res, next) => {
113
- ...
114
- });
115
-
116
- validate(router, [`/${id}/my-endpoint`]);
112
+ const schema = await getSchema();
113
+ await validate(router, services, schema); // Enable validator for custom endpoints
117
114
 
118
115
  router.post('/my-endpoint', async (req, res, next) => {
119
116
  ...
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("swagger-ui-express"),s=require("express-openapi-validator"),{findWorkspaceDir:t}=require("@pnpm/find-workspace-dir"),i=require("fs"),a=require("path"),n=process.cwd();let r;const o=function(){try{const e=a.join(n,"./extensions/endpoints/oasconfig.json");return JSON.parse(i.readFileSync(e,"utf-8"))}catch(e){return{}}}();async function c(e,s){if(r)return JSON.parse(r);const{SpecificationService:t}=e,i=new t({accountability:{admin:!0},schema:s});return r=JSON.stringify(await i.oas.generate()),JSON.parse(r)}const p=(null==o?void 0:o.docsPath)||"api-docs";var u={id:p,validate:async function(e,t,i){if(null==o?void 0:o.paths){const a=await c(t,i);a.paths=o.paths,e.use(s.middleware({apiSpec:a})),e.use(((e,s,t,i)=>{t.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(s,{services:i,exceptions:a,logger:n,getSchema:r})=>{const{ServiceUnavailableException:u}=a,d={swaggerOptions:{url:`/${p}/oas`}};s.use("/",e.serve),s.get("/",e.setup({},d)),s.get("/oas",(async(e,s,a)=>{try{const e=await r(),a=await c(i,e),p=require(`${await t(".")}/package.json`);a.info.title=p.name,a.info.version=p.version,a.info.description=p.description;try{if(null==o?void 0:o.paths)for(const e in o.paths)a.paths[e]=o.paths[e];if(null==o?void 0:o.tags)for(const e of o.tags)a.tags.push(e)}catch(e){n.info("No custom definitions")}s.json(a)}catch(e){return a(new u(e.message||e[0].message))}}))}};module.exports=u;
1
+ "use strict";const e=require("swagger-ui-express"),s=require("express-openapi-validator"),{findWorkspaceDir:t}=require("@pnpm/find-workspace-dir"),n=require("fs"),i=require("path"),a=process.cwd();let o;const r=function(){try{const e=i.join(a,"./extensions/endpoints/oasconfig.json");return JSON.parse(n.readFileSync(e,"utf-8"))}catch(e){return{}}}();async function c(e,s){if(o)return JSON.parse(o);const{SpecificationService:t}=e,n=new t({accountability:{admin:!0},schema:s});return o=JSON.stringify(await n.oas.generate()),JSON.parse(o)}const p=(null==r?void 0:r.docsPath)||"api-docs";var u={id:p,validate:async function(e,t,n,i){if(null==r?void 0:r.paths){const a=await c(t,n);if(delete a.components.definitions,delete a.components.schemas,i)for(const e of i)a.paths[e]=r.paths[e];else a.paths=r.paths;e.use(s.middleware({apiSpec:a})),e.use(((e,s,t,n)=>{t.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(s,{services:n,exceptions:i,logger:a,getSchema:o})=>{const{ServiceUnavailableException:u}=i,d={swaggerOptions:{url:`/${p}/oas`}};s.use("/",e.serve),s.get("/",e.setup({},d)),s.get("/oas",(async(e,s,i)=>{try{const e=await o(),i=await c(n,e),p=require(`${await t(".")}/package.json`);i.info.title=p.name,i.info.version=p.version,i.info.description=p.description;try{if(null==r?void 0:r.paths)for(const e in r.paths)i.paths[e]=r.paths[e];if(null==r?void 0:r.tags)for(const e of r.tags)i.tags.push(e)}catch(e){a.info("No custom definitions")}s.json(i)}catch(e){return i(new u(e.message||e[0].message))}}))}};module.exports=u;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-extension-api-docs",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
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",