openapi-jsonrpc-jsdoc 1.1.2 → 1.2.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/LICENSE +1 -1
- package/index.js +28 -15
- package/package.json +4 -4
package/LICENSE
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 = [];
|
|
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,
|
|
@@ -58,17 +59,25 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
58
59
|
BasicAuth: [],
|
|
59
60
|
},
|
|
60
61
|
],
|
|
61
|
-
'tags':
|
|
62
|
+
'tags': tags,
|
|
62
63
|
};
|
|
64
|
+
const requiredSchema = ['method', 'id', 'jsonrpc'];
|
|
63
65
|
for (const module of documents) {
|
|
64
66
|
const apiName = module.meta.filename.replace(/.js$/, '');
|
|
67
|
+
|
|
68
|
+
if (module.tags && Array.isArray(module.tags)) {
|
|
69
|
+
for (const tag of module.tags) {
|
|
70
|
+
tags.push(...new Set(tag.value.split(',').map(t => t.trim())));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
const schema = {
|
|
66
75
|
post: {
|
|
67
76
|
operationId: `${module.meta.filename}`,
|
|
68
77
|
deprecated: module.deprecated || false,
|
|
69
78
|
summary: `/${apiName}`,
|
|
70
79
|
description: module.description,
|
|
71
|
-
tags:
|
|
80
|
+
tags: tags,
|
|
72
81
|
parameters: [],
|
|
73
82
|
responses: {
|
|
74
83
|
'200': {
|
|
@@ -97,7 +106,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
97
106
|
'application/json': {
|
|
98
107
|
schema: {
|
|
99
108
|
type: 'object',
|
|
100
|
-
required:
|
|
109
|
+
required: requiredSchema,
|
|
101
110
|
properties: {
|
|
102
111
|
method: {
|
|
103
112
|
type: 'string',
|
|
@@ -114,7 +123,7 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
114
123
|
jsonrpc: {
|
|
115
124
|
type: 'string',
|
|
116
125
|
default: '2.0',
|
|
117
|
-
description: 'JSON-RPC
|
|
126
|
+
description: 'JSON-RPC 2.0 protocol',
|
|
118
127
|
},
|
|
119
128
|
},
|
|
120
129
|
},
|
|
@@ -124,10 +133,15 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
124
133
|
},
|
|
125
134
|
};
|
|
126
135
|
if (module.params) {
|
|
136
|
+
let exampleJSON = null;
|
|
137
|
+
if (module.examples?.length) {
|
|
138
|
+
exampleJSON = JSON.parse(module.examples[0]);
|
|
139
|
+
}
|
|
140
|
+
|
|
127
141
|
const propertiesParameters = module.params.reduce(
|
|
128
142
|
(accumulator, parameter) => {
|
|
129
143
|
if (!parameter.type) {
|
|
130
|
-
throw new Error('
|
|
144
|
+
throw new Error('JSDoc parameter error: ' + apiName);
|
|
131
145
|
}
|
|
132
146
|
// todo поддержать не только object поле в аргументе функции
|
|
133
147
|
if (parameter.type.names[0] === 'object') {
|
|
@@ -141,7 +155,9 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
141
155
|
} catch {
|
|
142
156
|
name = parameter.name;
|
|
143
157
|
}
|
|
144
|
-
|
|
158
|
+
if (!parameter.optional) {
|
|
159
|
+
accumulator.required.push(name);
|
|
160
|
+
}
|
|
145
161
|
accumulator.properties = {
|
|
146
162
|
...accumulator.properties,
|
|
147
163
|
[name]: {
|
|
@@ -154,17 +170,14 @@ async function openapiJsonrpcJsdoc({ files, securitySchemes = {}, packageUrl, se
|
|
|
154
170
|
{
|
|
155
171
|
title: 'Parameters',
|
|
156
172
|
type: 'object',
|
|
157
|
-
'default':
|
|
158
|
-
required:
|
|
173
|
+
'default': exampleJSON,
|
|
174
|
+
required: requiredSchema,
|
|
159
175
|
properties: {},
|
|
160
176
|
},
|
|
161
177
|
);
|
|
162
|
-
schema.post.requestBody.content['application/json'].schema
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
schema.post.requestBody.content[
|
|
166
|
-
'application/json'
|
|
167
|
-
].schema.properties.params = propertiesParameters;
|
|
178
|
+
const schemaPostJsdoc = schema.post.requestBody.content['application/json'].schema;
|
|
179
|
+
schemaPostJsdoc.required.push('params');
|
|
180
|
+
schemaPostJsdoc.properties.params = propertiesParameters;
|
|
168
181
|
}
|
|
169
182
|
temporaryDocument.paths[`${api}${apiName}`] = schema;
|
|
170
183
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-jsonrpc-jsdoc",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "OpenAPI
|
|
3
|
+
"version": "1.2.0",
|
|
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
|
}
|