directus-extension-api-docs 1.2.10 → 1.2.11
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 +52 -56
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,68 +27,64 @@ Create a `oasconfig.json` file under `/extensions/endpoints` folder.
|
|
|
27
27
|
Example below:
|
|
28
28
|
|
|
29
29
|
```
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
module.exports = {
|
|
31
|
+
docsPath: 'api-docs',
|
|
32
|
+
tags: [
|
|
33
33
|
{
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
name: 'MyCustomTag',
|
|
35
|
+
description: 'MyCustomTag description',
|
|
36
36
|
},
|
|
37
37
|
],
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"responses": {
|
|
60
|
-
"200": {
|
|
61
|
-
"description": "Successful request",
|
|
62
|
-
"content": {
|
|
63
|
-
"application/json": {
|
|
64
|
-
"schema": {
|
|
65
|
-
"type": "object",
|
|
66
|
-
"properties": {
|
|
67
|
-
"field": {
|
|
68
|
-
"type": "string"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
38
|
+
paths: {
|
|
39
|
+
'/my-custom-path/my-endpoint': {
|
|
40
|
+
post: {
|
|
41
|
+
summary: 'do something',
|
|
42
|
+
description: 'do something',
|
|
43
|
+
requestBody: {
|
|
44
|
+
content: {
|
|
45
|
+
'application/json': {
|
|
46
|
+
schema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
required: ['field'],
|
|
49
|
+
properties: {
|
|
50
|
+
field: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
74
56
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
responses: {
|
|
58
|
+
'200': {
|
|
59
|
+
description: 'Successful request',
|
|
60
|
+
content: {
|
|
61
|
+
'application/json': {
|
|
62
|
+
schema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
field: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
'401': {
|
|
74
|
+
description: 'Unauthorized',
|
|
75
|
+
content: {},
|
|
76
|
+
},
|
|
77
|
+
'404': {
|
|
78
|
+
description: 'Not Found',
|
|
79
|
+
content: {},
|
|
80
|
+
},
|
|
78
81
|
},
|
|
79
|
-
|
|
80
|
-
"description": "Not Found",
|
|
81
|
-
"content": {}
|
|
82
|
-
}
|
|
82
|
+
tags: ['MyCustomTag', 'Assets'],
|
|
83
83
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
92
88
|
```
|
|
93
89
|
|
|
94
90
|
## Validations (optional)
|
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("
|
|
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;
|
package/package.json
CHANGED