directus-extension-api-docs 1.2.10 → 1.3.0
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 +63 -58
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,73 +22,77 @@ Ref: https://github.com/directus/directus
|
|
|
22
22
|
|
|
23
23
|
For include you custom endpoints.
|
|
24
24
|
|
|
25
|
-
Create a `oasconfig.
|
|
25
|
+
Create a `oasconfig.js` file under `/extensions/endpoints` folder.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
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)
|
|
26
33
|
|
|
27
34
|
Example below:
|
|
28
35
|
|
|
29
36
|
```
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
module.exports = {
|
|
38
|
+
docsPath: 'api-docs', // optional default 'api-docs'
|
|
39
|
+
tags: [
|
|
33
40
|
{
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
name: 'MyCustomTag',
|
|
42
|
+
description: 'MyCustomTag description',
|
|
36
43
|
},
|
|
37
44
|
],
|
|
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
|
-
}
|
|
45
|
+
paths: {
|
|
46
|
+
'/my-custom-path/my-endpoint': {
|
|
47
|
+
post: {
|
|
48
|
+
summary: 'do something',
|
|
49
|
+
description: 'do something',
|
|
50
|
+
requestBody: {
|
|
51
|
+
content: {
|
|
52
|
+
'application/json': {
|
|
53
|
+
schema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
required: ['field'],
|
|
56
|
+
properties: {
|
|
57
|
+
field: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
74
63
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
responses: {
|
|
65
|
+
'200': {
|
|
66
|
+
description: 'Successful request',
|
|
67
|
+
content: {
|
|
68
|
+
'application/json': {
|
|
69
|
+
schema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
field: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
'401': {
|
|
81
|
+
description: 'Unauthorized',
|
|
82
|
+
content: {},
|
|
83
|
+
},
|
|
84
|
+
'404': {
|
|
85
|
+
description: 'Not Found',
|
|
86
|
+
content: {},
|
|
87
|
+
},
|
|
78
88
|
},
|
|
79
|
-
|
|
80
|
-
"description": "Not Found",
|
|
81
|
-
"content": {}
|
|
82
|
-
}
|
|
89
|
+
tags: ['MyCustomTag', 'Assets'],
|
|
83
90
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
components: {},
|
|
95
|
+
};
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
## Validations (optional)
|
|
@@ -96,7 +100,8 @@ Example below:
|
|
|
96
100
|
You can enable a request validations middleware based on your custom definitions.
|
|
97
101
|
|
|
98
102
|
Call `validate` function inside your custom endpoint registration.
|
|
99
|
-
|
|
103
|
+
|
|
104
|
+
Pass your `router`, `services`, `schema` and (_optional_) a list of endpoints you want to validate.
|
|
100
105
|
|
|
101
106
|
Example below:
|
|
102
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("
|
|
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;
|