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 +6 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
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'
|
|
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_)
|
|
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:
|
|
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;
|