directus-extension-api-docs 1.2.5 → 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 +3 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
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,
|
|
110
|
+
handler: async function registerEndpoint(router, { services, getSchema }) {
|
|
111
111
|
|
|
112
|
-
|
|
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"),
|
|
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;
|