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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +28 -15
  3. package/package.json +4 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Deni Baskovsky
3
+ Copyright (c) 2019 Denis Baskovsky
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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': ['curl', 'node', 'javascript'],
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: ['JSONRPC'],
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: ['method', 'id', 'jsonrpc'],
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 Version (2.0)',
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('JSDOC parameter error: ' + apiName);
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
- accumulator.required.push(name);
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': module.examples?.length ? JSON.parse(module.examples[0]) : null,
158
- required: ['method', 'id', 'jsonrpc'],
173
+ 'default': exampleJSON,
174
+ required: requiredSchema,
159
175
  properties: {},
160
176
  },
161
177
  );
162
- schema.post.requestBody.content['application/json'].schema.required.push(
163
- 'params',
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.1.2",
4
- "description": "OpenAPI generator",
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.5.3"
36
+ "express-openapi-validator": "~5.6.0"
37
37
  },
38
38
  "engines": {
39
- "node": ">= 16"
39
+ "node": ">= 18"
40
40
  }
41
41
  }