openapi-jsonrpc-jsdoc 1.4.2 → 1.4.3
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 -1
- package/index.mjs +36 -34
- package/package.json +2 -3
package/README.md
CHANGED
package/index.mjs
CHANGED
|
@@ -8,24 +8,27 @@ function extractName(name) {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function extractTypeName(names = []) {
|
|
12
|
+
let typeName;
|
|
13
|
+
if (names.length === 0) {
|
|
14
|
+
typeName = 'null';
|
|
15
|
+
} else if (names.length === 1) {
|
|
16
|
+
[typeName] = names;
|
|
17
|
+
} else {
|
|
18
|
+
typeName = 'enum';
|
|
19
|
+
}
|
|
20
|
+
return typeName;
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
function resolveSchemaFromTypeNames(names) {
|
|
12
24
|
let type;
|
|
13
25
|
let format;
|
|
14
26
|
let items;
|
|
15
|
-
let oneOf;
|
|
16
27
|
let nullable;
|
|
17
28
|
let constant;
|
|
18
29
|
let enumData;
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
type = 'null';
|
|
22
|
-
} else if (names.length === 1) {
|
|
23
|
-
[type] = names;
|
|
24
|
-
} else {
|
|
25
|
-
type = 'enum';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
switch (type) {
|
|
31
|
+
switch (extractTypeName(names)) {
|
|
29
32
|
case 'Array.<string>': {
|
|
30
33
|
type = 'array';
|
|
31
34
|
items = {type: 'string'};
|
|
@@ -67,7 +70,7 @@ function resolveSchemaFromTypeNames(names) {
|
|
|
67
70
|
nullable = true;
|
|
68
71
|
enumData = enumData.filter(n => n !== 'null');
|
|
69
72
|
}
|
|
70
|
-
|
|
73
|
+
enumData = enumData.map((n) => {
|
|
71
74
|
if (!Number.isNaN(Number(n))) {
|
|
72
75
|
return Number(n);
|
|
73
76
|
}
|
|
@@ -100,14 +103,11 @@ function resolveSchemaFromTypeNames(names) {
|
|
|
100
103
|
type = 'string';
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
if (enumData?.length === 1
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
[format] = enumData;
|
|
107
|
-
}
|
|
108
|
-
oneOf = undefined;
|
|
109
|
-
enumData = undefined;
|
|
106
|
+
if (enumData?.length === 1) {
|
|
107
|
+
if (!format) {
|
|
108
|
+
[format] = enumData;
|
|
110
109
|
}
|
|
110
|
+
enumData = undefined;
|
|
111
111
|
}
|
|
112
112
|
break;
|
|
113
113
|
}
|
|
@@ -119,7 +119,6 @@ function resolveSchemaFromTypeNames(names) {
|
|
|
119
119
|
return {
|
|
120
120
|
type,
|
|
121
121
|
format,
|
|
122
|
-
oneOf,
|
|
123
122
|
nullable,
|
|
124
123
|
items,
|
|
125
124
|
constant,
|
|
@@ -127,7 +126,14 @@ function resolveSchemaFromTypeNames(names) {
|
|
|
127
126
|
};
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
export default async function openapiJsonrpcJsdoc({
|
|
129
|
+
export default async function openapiJsonrpcJsdoc({
|
|
130
|
+
openapi = '3.1.0',
|
|
131
|
+
files,
|
|
132
|
+
securitySchemes = {},
|
|
133
|
+
packageUrl,
|
|
134
|
+
servers,
|
|
135
|
+
api = '/',
|
|
136
|
+
}) {
|
|
131
137
|
const allData = await jsdoc.explain({
|
|
132
138
|
files: Array.isArray(files) ? files : [files],
|
|
133
139
|
package: packageUrl,
|
|
@@ -136,12 +142,13 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
136
142
|
undocumented: false,
|
|
137
143
|
allowUnknownTags: true,
|
|
138
144
|
dictionaries: ['jsdoc'],
|
|
145
|
+
cache: true,
|
|
139
146
|
});
|
|
140
147
|
const package_ = allData.find(item => item.kind === 'package');
|
|
141
148
|
const documents = allData.filter(item => item.kind !== 'package');
|
|
142
149
|
const temporaryDocument = {
|
|
150
|
+
'openapi': openapi,
|
|
143
151
|
'x-send-defaults': true,
|
|
144
|
-
'openapi': '3.0.0',
|
|
145
152
|
'x-api-id': 'json-rpc-example',
|
|
146
153
|
'x-headers': [],
|
|
147
154
|
'x-explorer-enabled': true,
|
|
@@ -179,11 +186,7 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
179
186
|
},
|
|
180
187
|
}
|
|
181
188
|
},
|
|
182
|
-
'security': [
|
|
183
|
-
{
|
|
184
|
-
BasicAuth: [],
|
|
185
|
-
},
|
|
186
|
-
],
|
|
189
|
+
'security': Object.keys(securitySchemes).map(val => ({ [val]: [] })),
|
|
187
190
|
'tags': [],
|
|
188
191
|
};
|
|
189
192
|
const requiredSchema = ['method', 'jsonrpc'];
|
|
@@ -237,6 +240,7 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
237
240
|
}
|
|
238
241
|
},
|
|
239
242
|
requestBody: {
|
|
243
|
+
required: true,
|
|
240
244
|
content: {
|
|
241
245
|
'application/json': {
|
|
242
246
|
schema: {
|
|
@@ -249,9 +253,7 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
249
253
|
description: `API method ${apiName}`,
|
|
250
254
|
},
|
|
251
255
|
id: {
|
|
252
|
-
type: '
|
|
253
|
-
default: 1,
|
|
254
|
-
format: 'int32',
|
|
256
|
+
type: ['string'],
|
|
255
257
|
description: 'Request ID',
|
|
256
258
|
},
|
|
257
259
|
jsonrpc: {
|
|
@@ -285,9 +287,10 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
285
287
|
return accumulator;
|
|
286
288
|
}
|
|
287
289
|
|
|
288
|
-
const description = parameter.description;
|
|
289
290
|
const name = extractName(parameter.name);
|
|
290
291
|
accumulator.properties[name] = accumulator.properties[name] ?? {};
|
|
292
|
+
const description = parameter.description;
|
|
293
|
+
const defaultValue = parameter.defaultvalue;
|
|
291
294
|
|
|
292
295
|
const {
|
|
293
296
|
items,
|
|
@@ -295,7 +298,6 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
295
298
|
enumData,
|
|
296
299
|
type,
|
|
297
300
|
format,
|
|
298
|
-
oneOf,
|
|
299
301
|
nullable,
|
|
300
302
|
} = resolveSchemaFromTypeNames(parameter.type.names)
|
|
301
303
|
if (!parameter.optional) {
|
|
@@ -304,6 +306,9 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
304
306
|
if (nullable) {
|
|
305
307
|
accumulator.properties[name].nullable = nullable;
|
|
306
308
|
}
|
|
309
|
+
if (defaultValue) {
|
|
310
|
+
accumulator.properties[name].default = defaultValue;
|
|
311
|
+
}
|
|
307
312
|
if (constant) {
|
|
308
313
|
accumulator.properties[name].const = constant;
|
|
309
314
|
}
|
|
@@ -313,9 +318,6 @@ export default async function openapiJsonrpcJsdoc({ files, securitySchemes = {},
|
|
|
313
318
|
if (enumData) {
|
|
314
319
|
accumulator.properties[name].enum = enumData;
|
|
315
320
|
}
|
|
316
|
-
if (oneOf) {
|
|
317
|
-
accumulator.properties[name].oneOf = oneOf;
|
|
318
|
-
}
|
|
319
321
|
if (type) {
|
|
320
322
|
accumulator.properties[name].type = type;
|
|
321
323
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-jsonrpc-jsdoc",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Transform JSDoc-annotated JSON-RPC 2.0 methods into OpenAPI specifications.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"ava": "~6.4.1",
|
|
36
|
-
"express": "~5.2.1"
|
|
37
|
-
"express-openapi-validator": "~5.6.2"
|
|
36
|
+
"express": "~5.2.1"
|
|
38
37
|
},
|
|
39
38
|
"engines": {
|
|
40
39
|
"node": ">= 22"
|