directus-extension-api-docs 1.3.1 → 1.3.3

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
@@ -26,16 +26,16 @@ Create a `oasconfig.js` file under `/extensions/endpoints` folder.
26
26
 
27
27
  Options:
28
28
 
29
- - `docsPath` path where the interface will be
30
- - `tags` openapi custom tags
31
- - `paths` openapi custom paths
32
- - `components` openapi custom components (you can ref to directus standard components declaring them empty)
29
+ - `docsPath` _optional_ path where the interface will be (default 'api-docs')
30
+ - `tags` _optional_ openapi custom tags
31
+ - `paths` _optional_ openapi custom paths
32
+ - `components` _optional_ openapi custom components (you can ref to directus standard components declaring them empty)
33
33
 
34
34
  Example below:
35
35
 
36
36
  ```
37
37
  module.exports = {
38
- docsPath: 'api-docs', // optional default 'api-docs'
38
+ docsPath: 'api-docs'
39
39
  tags: [
40
40
  {
41
41
  name: 'MyCustomTag',
@@ -101,7 +101,7 @@ You can enable a request validations middleware based on your custom definitions
101
101
 
102
102
  Call `validate` function inside your custom endpoint registration.
103
103
 
104
- Pass your `router`, `services`, `schema` and (_optional_) a list of endpoints you want to validate.
104
+ Pass your `router`, `services`, `schema` and a list (_optional_) of endpoints you want to validate.
105
105
 
106
106
  Example below:
107
107
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("swagger-ui-express"),s=require("express-openapi-validator"),{findWorkspaceDir:n}=require("@pnpm/find-workspace-dir"),t=require("path"),o=process.cwd();let i;const a=function(){try{return require(t.join(o,"./extensions/endpoints/oasconfig.json"))}catch(e){return{}}}();async function r(e,s){if(i)return JSON.parse(i);const{SpecificationService:n}=e,t=new n({accountability:{admin:!0},schema:s});return i=JSON.stringify(await t.oas.generate()),JSON.parse(i)}function c(e,s){for(const n of Object.keys(s))s[n]instanceof Object&&Object.assign(s[n],c(e[n],s[n]));return Object.assign(e||{},s),e}const p=(null==a?void 0:a.docsPath)||"api-docs";var u={id:p,validate:async function(e,n,t,o){if(null==a?void 0:a.paths){const i=await r(n,t);if(o)for(const e of o)i.paths[e]=a.paths[e];else i.paths=a.paths;a.components?i.components=a.components:(delete i.components.definitions,delete i.components.schemas),e.use(s.middleware({apiSpec:i})),e.use(((e,s,n,t)=>{n.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(s,{services:t,exceptions:o,logger:i,getSchema:u})=>{const{ServiceUnavailableException:f}=o,d={swaggerOptions:{url:`/${p}/oas`}};s.use("/",e.serve),s.get("/",e.setup({},d)),s.get("/oas",(async(e,s,o)=>{try{const e=await u(),o=await r(t,e),p=require(`${await n(".")}/package.json`);o.info.title=p.name,o.info.version=p.version,o.info.description=p.description;try{if(null==a?void 0:a.paths)for(const e in a.paths)o.paths[e]=a.paths[e];if(null==a?void 0:a.tags)for(const e of a.tags)o.tags.push(e);(null==a?void 0:a.components)&&(o.components=c(a.components,o.components))}catch(e){i.info("No custom definitions")}s.json(o)}catch(e){return o(new f(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("path"),o=process.cwd();let i;const r=function(){try{return require(n.join(o,"./extensions/endpoints/oasconfig.js"))}catch(e){return{}}}();async function a(e,s){if(i)return JSON.parse(i);const{SpecificationService:t}=e,n=new t({accountability:{admin:!0},schema:s});return i=JSON.stringify(await n.oas.generate()),JSON.parse(i)}function c(e,s){return Object.entries(s).reduce(((e,[s,t])=>(e[s]=t&&"object"==typeof t?c(e[s]=e[s]||(Array.isArray(t)?[]:{}),t):t,e)),e)}const p=(null==r?void 0:r.docsPath)||"api-docs";var u={id:p,validate:async function(e,t,n,o){if(null==r?void 0:r.paths){const i=await a(t,n);if(o)for(const e of o)i.paths[e]=r.paths[e];else i.paths=r.paths;r.components?i.components=r.components:(delete i.components.definitions,delete i.components.schemas),e.use(s.middleware({apiSpec:i})),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:o,logger:i,getSchema:u})=>{const{ServiceUnavailableException:d}=o,f={swaggerOptions:{url:`/${p}/oas`}};s.use("/",e.serve),s.get("/",e.setup({},f)),s.get("/oas",(async(e,s,o)=>{try{const e=await u(),o=await a(n,e),p=require(`${await t(".")}/package.json`);o.info.title=p.name,o.info.version=p.version,o.info.description=p.description;try{if(null==r?void 0:r.paths)for(const e in r.paths)o.paths[e]=r.paths[e];if(null==r?void 0:r.tags)for(const e of r.tags)o.tags.push(e);(null==r?void 0:r.components)&&(o.components=c(r.components,o.components))}catch(e){i.info("No custom definitions")}s.json(o)}catch(e){return o(new d(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.3.1",
3
+ "version": "1.3.3",
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",