openapi-jsonrpc-jsdoc 1.2.0 → 1.2.2
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 +1 -0
- package/index.js +35 -12
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
13
13
|
dictionaries: ['jsdoc'],
|
|
14
14
|
hierarchy: true,
|
|
15
15
|
});
|
|
16
|
-
const tags =
|
|
16
|
+
const tags = new Set();
|
|
17
17
|
const temporaryDocument = {
|
|
18
18
|
'x-send-defaults': true,
|
|
19
19
|
'openapi': '3.0.0',
|
|
@@ -59,17 +59,25 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
59
59
|
BasicAuth: [],
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
|
-
'tags':
|
|
62
|
+
'tags': [],
|
|
63
63
|
};
|
|
64
|
-
const requiredSchema = ['method', '
|
|
65
|
-
for (const module of documents) {
|
|
66
|
-
|
|
64
|
+
const requiredSchema = ['method', 'jsonrpc'];
|
|
65
|
+
prepare: for (const module of documents) {
|
|
66
|
+
let isJsonRpc = false;
|
|
67
67
|
|
|
68
68
|
if (module.tags && Array.isArray(module.tags)) {
|
|
69
|
-
for (const
|
|
70
|
-
|
|
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
|
+
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
77
|
+
if (!isJsonRpc) {
|
|
78
|
+
continue prepare;
|
|
79
|
+
}
|
|
80
|
+
const apiName = module.meta.filename.replace(/.js$/, '');
|
|
73
81
|
|
|
74
82
|
const schema = {
|
|
75
83
|
post: {
|
|
@@ -77,7 +85,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
77
85
|
deprecated: module.deprecated || false,
|
|
78
86
|
summary: `/${apiName}`,
|
|
79
87
|
description: module.description,
|
|
80
|
-
tags: tags,
|
|
88
|
+
tags: Array.from(tags),
|
|
81
89
|
parameters: [],
|
|
82
90
|
responses: {
|
|
83
91
|
'200': {
|
|
@@ -113,7 +121,6 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
113
121
|
default: apiName,
|
|
114
122
|
description: `API method ${apiName}`,
|
|
115
123
|
},
|
|
116
|
-
// todo делать разграничение для notification request (без id)
|
|
117
124
|
id: {
|
|
118
125
|
type: 'integer',
|
|
119
126
|
default: 1,
|
|
@@ -147,7 +154,23 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
147
154
|
if (parameter.type.names[0] === 'object') {
|
|
148
155
|
return accumulator;
|
|
149
156
|
}
|
|
150
|
-
|
|
157
|
+
let [type] = parameter.type.names;
|
|
158
|
+
let items;
|
|
159
|
+
switch (type) {
|
|
160
|
+
case 'Array.<string>': {
|
|
161
|
+
type = 'array';
|
|
162
|
+
items = { type: 'number' };
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case 'Array.<number>': {
|
|
166
|
+
type = 'array';
|
|
167
|
+
items = { type: 'string' };
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
default: {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
151
174
|
const description = parameter.description;
|
|
152
175
|
let name;
|
|
153
176
|
try {
|
|
@@ -163,6 +186,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
163
186
|
[name]: {
|
|
164
187
|
type,
|
|
165
188
|
description,
|
|
189
|
+
items,
|
|
166
190
|
},
|
|
167
191
|
};
|
|
168
192
|
return accumulator;
|
|
@@ -171,12 +195,11 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
171
195
|
title: 'Parameters',
|
|
172
196
|
type: 'object',
|
|
173
197
|
'default': exampleJSON,
|
|
174
|
-
required:
|
|
198
|
+
required: [],
|
|
175
199
|
properties: {},
|
|
176
200
|
},
|
|
177
201
|
);
|
|
178
202
|
const schemaPostJsdoc = schema.post.requestBody.content['application/json'].schema;
|
|
179
|
-
schemaPostJsdoc.required.push('params');
|
|
180
203
|
schemaPostJsdoc.properties.params = propertiesParameters;
|
|
181
204
|
}
|
|
182
205
|
temporaryDocument.paths[`${api}${apiName}`] = schema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-jsonrpc-jsdoc",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
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": {
|