openapi-jsonrpc-jsdoc 1.5.1 → 1.5.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/index.mjs +56 -27
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -43,6 +43,14 @@ function resolveSchemaFromTypeNames(names) {
|
|
|
43
43
|
items = {type: 'string'};
|
|
44
44
|
break;
|
|
45
45
|
}
|
|
46
|
+
case 'Array.<bigint>': {
|
|
47
|
+
type = 'array';
|
|
48
|
+
items = {
|
|
49
|
+
type: 'integer',
|
|
50
|
+
format: 'int64',
|
|
51
|
+
};
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
46
54
|
case 'Array.<number>': {
|
|
47
55
|
type = 'array';
|
|
48
56
|
items = {type: 'number'};
|
|
@@ -250,12 +258,11 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
250
258
|
|
|
251
259
|
const schema = {
|
|
252
260
|
post: {
|
|
253
|
-
operationId:
|
|
261
|
+
operationId: apiName,
|
|
254
262
|
deprecated: module.deprecated || false,
|
|
255
|
-
summary: `/${apiName}`,
|
|
263
|
+
summary: module.summary ?? `/${apiName}`,
|
|
256
264
|
description: module.description,
|
|
257
265
|
tags: Array.from(tags),
|
|
258
|
-
parameters: [],
|
|
259
266
|
responses: {
|
|
260
267
|
'200': {
|
|
261
268
|
description: 'OK',
|
|
@@ -307,9 +314,12 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
307
314
|
},
|
|
308
315
|
};
|
|
309
316
|
if (module.params) {
|
|
310
|
-
|
|
317
|
+
const prevObject = {};
|
|
311
318
|
if (module.examples?.length) {
|
|
312
|
-
exampleJSON = JSON.parse(module.examples[0]);
|
|
319
|
+
const exampleJSON = JSON.parse(module.examples[0]);
|
|
320
|
+
if (exampleJSON) {
|
|
321
|
+
prevObject['default'] = exampleJSON;
|
|
322
|
+
}
|
|
313
323
|
}
|
|
314
324
|
|
|
315
325
|
const propertiesParameters = module.params.reduce(
|
|
@@ -320,15 +330,16 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
320
330
|
if (!parameter.type) {
|
|
321
331
|
throw new Error('JSDoc parameter error: ' + apiName);
|
|
322
332
|
}
|
|
323
|
-
//
|
|
324
|
-
if (parameter.type.names
|
|
333
|
+
// если главный параметр объявлен как объект - пропускаем его
|
|
334
|
+
if (parameter.type.names.every(name => name.toLowerCase() === 'object')) {
|
|
325
335
|
return accumulator;
|
|
326
336
|
}
|
|
337
|
+
const isPlain = !parameter.name.includes('.');
|
|
327
338
|
|
|
328
339
|
const name = extractName(parameter.name);
|
|
329
|
-
|
|
340
|
+
const prop = {};
|
|
330
341
|
const description = parameter.description;
|
|
331
|
-
|
|
342
|
+
let defaultValue = parameter.defaultvalue;
|
|
332
343
|
|
|
333
344
|
const {
|
|
334
345
|
items,
|
|
@@ -339,45 +350,63 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
339
350
|
nullable,
|
|
340
351
|
} = resolveSchemaFromTypeNames(parameter.type.names)
|
|
341
352
|
if (!parameter.optional) {
|
|
353
|
+
if (!accumulator.required) {
|
|
354
|
+
accumulator.required = [];
|
|
355
|
+
}
|
|
342
356
|
accumulator.required.push(name);
|
|
343
357
|
}
|
|
344
358
|
if (nullable) {
|
|
345
|
-
|
|
359
|
+
prop.nullable = nullable;
|
|
346
360
|
}
|
|
347
|
-
if (defaultValue) {
|
|
348
|
-
|
|
361
|
+
if (defaultValue !== undefined) {
|
|
362
|
+
// fix for array type if it is not properly closed in JSDoc
|
|
363
|
+
if (typeof defaultValue === 'string' && defaultValue.startsWith('[') && !defaultValue.endsWith(']')) {
|
|
364
|
+
defaultValue += ']';
|
|
365
|
+
}
|
|
366
|
+
prop.default = JSON.parse(defaultValue);
|
|
349
367
|
}
|
|
350
368
|
if (constant) {
|
|
351
|
-
|
|
369
|
+
prop.const = constant;
|
|
352
370
|
}
|
|
353
371
|
if (format) {
|
|
354
|
-
|
|
372
|
+
prop.format = format;
|
|
355
373
|
}
|
|
356
374
|
if (enumData) {
|
|
357
|
-
|
|
375
|
+
prop.enum = enumData;
|
|
358
376
|
}
|
|
359
377
|
if (type) {
|
|
360
|
-
|
|
378
|
+
prop.type = type;
|
|
361
379
|
}
|
|
362
380
|
if (description) {
|
|
363
|
-
|
|
381
|
+
prop.description = description;
|
|
364
382
|
}
|
|
365
383
|
if (items) {
|
|
366
|
-
|
|
384
|
+
prop.items = items;
|
|
367
385
|
}
|
|
386
|
+
if (isPlain) {
|
|
387
|
+
accumulator = Object.assign(accumulator, prop);
|
|
388
|
+
} else if (accumulator.properties) {
|
|
389
|
+
accumulator.properties[name] = prop;
|
|
390
|
+
} else {
|
|
391
|
+
accumulator.properties = {
|
|
392
|
+
[name]: prop,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
368
396
|
return accumulator;
|
|
369
397
|
},
|
|
370
|
-
|
|
371
|
-
title: 'Parameters',
|
|
372
|
-
type: 'object',
|
|
373
|
-
'default': exampleJSON,
|
|
374
|
-
required: [],
|
|
375
|
-
properties: {},
|
|
376
|
-
},
|
|
398
|
+
prevObject,
|
|
377
399
|
);
|
|
378
|
-
if (
|
|
400
|
+
if (Object.keys(propertiesParameters).length) {
|
|
379
401
|
const schemaPostJsdoc = schema.post.requestBody.content['application/json'].schema;
|
|
380
|
-
|
|
402
|
+
if (propertiesParameters.properties) {
|
|
403
|
+
schemaPostJsdoc.properties.params = {
|
|
404
|
+
type: 'object',
|
|
405
|
+
...propertiesParameters,
|
|
406
|
+
};
|
|
407
|
+
} else {
|
|
408
|
+
schemaPostJsdoc.properties.params = propertiesParameters;
|
|
409
|
+
}
|
|
381
410
|
}
|
|
382
411
|
}
|
|
383
412
|
temporaryDocument.paths[`${api}${apiName}`] = schema;
|