directus-extension-api-docs 1.2.2 → 1.2.4
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 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Ref: https://github.com/directus/directus
|
|
|
22
22
|
|
|
23
23
|
For include you custom endpoints.
|
|
24
24
|
|
|
25
|
-
Create a `
|
|
25
|
+
Create a `oasconfig.json` file under `/extensions/endpoints` folder.
|
|
26
26
|
|
|
27
27
|
Example below:
|
|
28
28
|
|
|
@@ -109,6 +109,10 @@ module.exports = {
|
|
|
109
109
|
id,
|
|
110
110
|
handler: function registerEndpoint(router, { services, exceptions, logger }) {
|
|
111
111
|
|
|
112
|
+
router.post('/my-endpoint-not-validated', async (req, res, next) => {
|
|
113
|
+
...
|
|
114
|
+
});
|
|
115
|
+
|
|
112
116
|
validate(router, [`/${id}/my-endpoint`]);
|
|
113
117
|
|
|
114
118
|
router.post('/my-endpoint', async (req, res, next) => {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("swagger-ui-express"),s=require("express-openapi-validator"),{findWorkspaceDir:
|
|
1
|
+
"use strict";const e=require("swagger-ui-express"),s=require("express-openapi-validator"),{findWorkspaceDir:t}=require("@pnpm/find-workspace-dir"),i=require("fs"),n=require("path"),r=process.cwd();let a;const o=function(){try{const e=n.join(r,"./extensions/endpoints/oasconfig.json");return JSON.parse(i.readFileSync(e,"utf-8"))}catch(e){return{}}}();async function c(e){if(a)return JSON.parse(a);const{SpecificationService:s}=e,t=new s({accountability:{admin:!0}});return a=JSON.stringify(await t.oas.generate()),JSON.parse(a)}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 n=await c(t);for(const e of i)n.paths[e]=o.paths[e];e.use(s.middleware({apiSpec:n})),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:n,logger:r})=>{const{ServiceUnavailableException:a}=n,u={swaggerOptions:{url:`/${p}/oas`}};s.use("/",e.serve),s.get("/",e.setup({},u)),s.get("/oas",(async(e,s,n)=>{try{const e=await c(i),n=require(`${await t(".")}/package.json`);e.info.title=n.name,e.info.version=n.version,e.info.description=n.description;try{if(null==o?void 0:o.paths)for(const s in o.paths)e.paths[s]=o.paths[s];if(null==o?void 0:o.tags)for(const s of o.tags)e.tags.push(s)}catch(e){r.info("No custom definitions")}s.json(e)}catch(e){return n(new a(e.message||e[0].message))}}))}};module.exports=u;
|