openapi-jsonrpc-jsdoc 1.1.2 → 1.2.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/LICENSE +1 -1
- package/README.md +1 -0
- package/index.js +36 -15
- package/package.json +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
13
13
|
dictionaries: ['jsdoc'],
|
|
14
14
|
hierarchy: true,
|
|
15
15
|
});
|
|
16
|
+
const tags = new Set();
|
|
16
17
|
const temporaryDocument = {
|
|
17
18
|
'x-send-defaults': true,
|
|
18
19
|
'openapi': '3.0.0',
|
|
@@ -21,7 +22,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
21
22
|
'x-explorer-enabled': true,
|
|
22
23
|
'x-proxy-enabled': true,
|
|
23
24
|
'x-samples-enabled': true,
|
|
24
|
-
'x-samples-languages': ['
|
|
25
|
+
'x-samples-languages': ['node', 'javascript'],
|
|
25
26
|
'info': {
|
|
26
27
|
version: package_.version,
|
|
27
28
|
title: package_.name,
|
|
@@ -60,15 +61,31 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
60
61
|
],
|
|
61
62
|
'tags': [],
|
|
62
63
|
};
|
|
63
|
-
|
|
64
|
+
const requiredSchema = ['method', 'id', 'jsonrpc'];
|
|
65
|
+
prepare: for (const module of documents) {
|
|
66
|
+
let isJsonRpc = false;
|
|
67
|
+
|
|
68
|
+
if (module.tags && Array.isArray(module.tags)) {
|
|
69
|
+
for (const {title, value} of module.tags) {
|
|
70
|
+
if (title === 'json-rpc') {
|
|
71
|
+
isJsonRpc = true;
|
|
72
|
+
} else if (title === 'tags' && value) {
|
|
73
|
+
value.split(',').map(t => t.trim()).forEach(t => tags.add(t));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!isJsonRpc) {
|
|
78
|
+
continue prepare;
|
|
79
|
+
}
|
|
64
80
|
const apiName = module.meta.filename.replace(/.js$/, '');
|
|
81
|
+
|
|
65
82
|
const schema = {
|
|
66
83
|
post: {
|
|
67
84
|
operationId: `${module.meta.filename}`,
|
|
68
85
|
deprecated: module.deprecated || false,
|
|
69
86
|
summary: `/${apiName}`,
|
|
70
87
|
description: module.description,
|
|
71
|
-
tags:
|
|
88
|
+
tags: Array.from(tags),
|
|
72
89
|
parameters: [],
|
|
73
90
|
responses: {
|
|
74
91
|
'200': {
|
|
@@ -97,7 +114,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
97
114
|
'application/json': {
|
|
98
115
|
schema: {
|
|
99
116
|
type: 'object',
|
|
100
|
-
required:
|
|
117
|
+
required: requiredSchema,
|
|
101
118
|
properties: {
|
|
102
119
|
method: {
|
|
103
120
|
type: 'string',
|
|
@@ -114,7 +131,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
114
131
|
jsonrpc: {
|
|
115
132
|
type: 'string',
|
|
116
133
|
default: '2.0',
|
|
117
|
-
description: 'JSON-RPC
|
|
134
|
+
description: 'JSON-RPC 2.0 protocol',
|
|
118
135
|
},
|
|
119
136
|
},
|
|
120
137
|
},
|
|
@@ -124,10 +141,15 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
124
141
|
},
|
|
125
142
|
};
|
|
126
143
|
if (module.params) {
|
|
144
|
+
let exampleJSON = null;
|
|
145
|
+
if (module.examples?.length) {
|
|
146
|
+
exampleJSON = JSON.parse(module.examples[0]);
|
|
147
|
+
}
|
|
148
|
+
|
|
127
149
|
const propertiesParameters = module.params.reduce(
|
|
128
150
|
(accumulator, parameter) => {
|
|
129
151
|
if (!parameter.type) {
|
|
130
|
-
throw new Error('
|
|
152
|
+
throw new Error('JSDoc parameter error: ' + apiName);
|
|
131
153
|
}
|
|
132
154
|
// todo поддержать не только object поле в аргументе функции
|
|
133
155
|
if (parameter.type.names[0] === 'object') {
|
|
@@ -141,7 +163,9 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
141
163
|
} catch {
|
|
142
164
|
name = parameter.name;
|
|
143
165
|
}
|
|
144
|
-
|
|
166
|
+
if (!parameter.optional) {
|
|
167
|
+
accumulator.required.push(name);
|
|
168
|
+
}
|
|
145
169
|
accumulator.properties = {
|
|
146
170
|
...accumulator.properties,
|
|
147
171
|
[name]: {
|
|
@@ -154,17 +178,14 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
154
178
|
{
|
|
155
179
|
title: 'Parameters',
|
|
156
180
|
type: 'object',
|
|
157
|
-
'default':
|
|
158
|
-
required:
|
|
181
|
+
'default': exampleJSON,
|
|
182
|
+
required: requiredSchema,
|
|
159
183
|
properties: {},
|
|
160
184
|
},
|
|
161
185
|
);
|
|
162
|
-
schema.post.requestBody.content['application/json'].schema
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
schema.post.requestBody.content[
|
|
166
|
-
'application/json'
|
|
167
|
-
].schema.properties.params = propertiesParameters;
|
|
186
|
+
const schemaPostJsdoc = schema.post.requestBody.content['application/json'].schema;
|
|
187
|
+
schemaPostJsdoc.required.push('params');
|
|
188
|
+
schemaPostJsdoc.properties.params = propertiesParameters;
|
|
168
189
|
}
|
|
169
190
|
temporaryDocument.paths[`${api}${apiName}`] = schema;
|
|
170
191
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-jsonrpc-jsdoc",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "OpenAPI
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Transform JSDoc-annotated JSON-RPC 2.0 methods into OpenAPI 3.0 specifications. Auto-generates REST API documentation with complete schemas, parameters, and endpoint definitions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "NODE_NO_WARNINGS=1 ava test/*.test.js"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"ava": "~3.15.0",
|
|
35
35
|
"express": "~5.1.0",
|
|
36
|
-
"express-openapi-validator": "~5.
|
|
36
|
+
"express-openapi-validator": "~5.6.0"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">= 18"
|
|
40
40
|
}
|
|
41
41
|
}
|