directus-extension-api-docs 1.4.0 → 1.4.1
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 +7 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ components:
|
|
|
55
55
|
|
|
56
56
|
## Definitions (optional)
|
|
57
57
|
|
|
58
|
-
For each custom endpoints group, you can define
|
|
58
|
+
For each custom endpoints group, you can define api's including a file `oas.yaml` in root path of your group folder.
|
|
59
59
|
|
|
60
60
|
Properties:
|
|
61
61
|
|
|
@@ -81,14 +81,14 @@ paths:
|
|
|
81
81
|
content:
|
|
82
82
|
application/json:
|
|
83
83
|
schema:
|
|
84
|
-
"$ref": "#/components/schemas/
|
|
84
|
+
"$ref": "#/components/schemas/UserId"
|
|
85
85
|
responses:
|
|
86
86
|
'200':
|
|
87
87
|
description: Successful request
|
|
88
88
|
content:
|
|
89
89
|
application/json:
|
|
90
90
|
schema:
|
|
91
|
-
"$ref": "#/components/schemas/
|
|
91
|
+
"$ref": "#/components/schemas/Users"
|
|
92
92
|
'401':
|
|
93
93
|
description: Unauthorized
|
|
94
94
|
content: {}
|
|
@@ -98,6 +98,10 @@ paths:
|
|
|
98
98
|
'500':
|
|
99
99
|
description: Server Error
|
|
100
100
|
content: {}
|
|
101
|
+
components:
|
|
102
|
+
schemas:
|
|
103
|
+
Users:
|
|
104
|
+
type: object # you can ref to standard components declaring it empty
|
|
101
105
|
```
|
|
102
106
|
|
|
103
107
|
## Validations (optional)
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("js-yaml"),s=require("path"),n=require("fs"),t=process.cwd();let o;async function i(e,s){if(o)return JSON.parse(o);const{SpecificationService:n}=e,t=new n({accountability:{admin:!0},schema:s});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,s){return Object.entries(s).reduce(((e,[s,n])=>(e[s]=n&&"object"==typeof n?a(e[s]=e[s]||(Array.isArray(n)?[]:{}),n):n,e)),e)}const r=require("swagger-ui-express"),c=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),u=function(){try{const o=s.join(t,"./extensions/endpoints/oasconfig.
|
|
1
|
+
"use strict";const e=require("js-yaml"),s=require("path"),n=require("fs"),t=process.cwd();let o;async function i(e,s){if(o)return JSON.parse(o);const{SpecificationService:n}=e,t=new n({accountability:{admin:!0},schema:s});return o=JSON.stringify(await t.oas.generate()),JSON.parse(o)}function a(e,s){return Object.entries(s).reduce(((e,[s,n])=>(e[s]=n&&"object"==typeof n?a(e[s]=e[s]||(Array.isArray(n)?[]:{}),n):n,e)),e)}const r=require("swagger-ui-express"),c=require("express-openapi-validator"),{findWorkspaceDir:p}=require("@pnpm/find-workspace-dir"),u=function(){try{const o=s.join(t,"./extensions/endpoints/oasconfig.yaml"),i=e.load(n.readFileSync(o,{encoding:"utf-8"})),r=s.join(t,"./extensions/endpoints"),c=n.readdirSync(r,{withFileTypes:!0});for(const s of c){const t=`${r}/${s.name}/oas.yaml`;if(s.isDirectory()&&n.existsSync(t)){const s=e.load(n.readFileSync(t,{encoding:"utf-8"}));i.tags=[...i.tags,...s.tags],i.paths={...i.paths,...s.paths},i.components=a(i.components,s.components)}}return i}catch(e){return{}}}(),d=(null==u?void 0:u.docsPath)||"api-docs";var l={id:d,validate:async function(e,s,n,t){if(null==u?void 0:u.paths){const o=await i(s,n);if(t)for(const e of t)o.paths[e]=u.paths[e];else o.paths=u.paths;u.components?o.components=u.components:(delete o.components.definitions,delete o.components.schemas),e.use(c.middleware({apiSpec:o})),e.use(((e,s,n,t)=>{n.status(e.status||500).json({message:e.message,errors:e.errors})}))}return e},handler:(e,{services:s,exceptions:n,logger:t,getSchema:o})=>{const{ServiceUnavailableException:c}=n,l={swaggerOptions:{url:`/${d}/oas`}};e.use("/",r.serve),e.get("/",r.setup({},l)),e.get("/oas",(async(e,n,r)=>{try{const e=await o(),r=await i(s,e),c=require(`${await p(".")}/package.json`);r.info.title=c.name,r.info.version=c.version,r.info.description=c.description;try{if(null==u?void 0:u.paths)for(const e in u.paths)r.paths[e]=u.paths[e];if(null==u?void 0:u.tags)for(const e of u.tags)r.tags.push(e);(null==u?void 0:u.components)&&(r.components=a(u.components,r.components))}catch(e){t.info("No custom definitions")}n.json(r)}catch(e){return r(new c(e.message||e[0].message))}}))}};module.exports=l;
|