swaggie 1.4.1-test.1 → 1.4.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/dist/gen/genOperations.js +7 -23
- package/dist/gen/jsDocs.js +3 -3
- package/dist/swagger/operations.js +51 -25
- package/package.json +1 -1
|
@@ -137,27 +137,6 @@ function prepareClient(
|
|
|
137
137
|
});
|
|
138
138
|
} exports.prepareOperations = prepareOperations;
|
|
139
139
|
|
|
140
|
-
/**
|
|
141
|
-
* Prepares content for the operation docs. We will use description and summary if they are defined
|
|
142
|
-
* in the spec. Additionally we will add deprecation tag if the operation is deprecated.
|
|
143
|
-
* This function should include JSDocs asterisks to make comments look nice.
|
|
144
|
-
*/
|
|
145
|
-
function getOperationDocs(op) {
|
|
146
|
-
const result = [];
|
|
147
|
-
const summary = _optionalChain([op, 'access', _3 => _3.summary, 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]);
|
|
148
|
-
const description = _optionalChain([op, 'access', _6 => _6.description, 'optionalAccess', _7 => _7.trim, 'call', _8 => _8()]);
|
|
149
|
-
if (summary) {
|
|
150
|
-
result.push(summary);
|
|
151
|
-
}
|
|
152
|
-
if (description && description !== summary) {
|
|
153
|
-
result.push(description);
|
|
154
|
-
}
|
|
155
|
-
if (op.deprecated) {
|
|
156
|
-
result.push('@deprecated');
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
140
|
/**
|
|
162
141
|
* Marks parameters as skippable based on their position relative to the last required parameter.
|
|
163
142
|
*
|
|
@@ -250,16 +229,17 @@ function prepareUrl(path) {
|
|
|
250
229
|
}
|
|
251
230
|
|
|
252
231
|
const result = params
|
|
253
|
-
.filter((p) => !where || where.includes(p.in))
|
|
232
|
+
.filter((p) => p.name && (!where || where.includes(p.in)))
|
|
254
233
|
.map((p) => ({
|
|
255
234
|
originalName: p.name,
|
|
256
235
|
name: getParamName(p.name),
|
|
257
236
|
type: _swagger.getParameterType.call(void 0, p, options),
|
|
258
237
|
optional: p.required === undefined || p.required === null ? true : !p.required,
|
|
259
238
|
original: p,
|
|
239
|
+
jsDoc: _optionalChain([p, 'access', _3 => _3.description, 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]),
|
|
260
240
|
}));
|
|
261
241
|
|
|
262
|
-
if (_optionalChain([options, 'access',
|
|
242
|
+
if (_optionalChain([options, 'access', _6 => _6.modifiers, 'optionalAccess', _7 => _7.parameters])) {
|
|
263
243
|
for (const [name, modifier] of Object.entries(options.modifiers.parameters)) {
|
|
264
244
|
const paramIndex = result.findIndex(
|
|
265
245
|
(p) => p.original.in !== 'path' && (p.originalName === name || p.name === name)
|
|
@@ -286,6 +266,10 @@ function prepareUrl(path) {
|
|
|
286
266
|
* Escapes param name so it can be used as a valid identifier in the generated code
|
|
287
267
|
*/
|
|
288
268
|
function getParamName(name) {
|
|
269
|
+
if (!name) {
|
|
270
|
+
return name;
|
|
271
|
+
}
|
|
272
|
+
|
|
289
273
|
return _utils.escapeIdentifier.call(void 0,
|
|
290
274
|
name
|
|
291
275
|
.split('.')
|
package/dist/gen/jsDocs.js
CHANGED
|
@@ -72,9 +72,9 @@ function stripSpecificHtmlTags(str) {
|
|
|
72
72
|
|
|
73
73
|
const result = docs;
|
|
74
74
|
for (const param of params) {
|
|
75
|
-
const paramLine = `@param ${param.name}
|
|
76
|
-
param.name !== param.originalName ? `(API name: ${param.originalName})` : ''
|
|
77
|
-
}`;
|
|
75
|
+
const paramLine = `@param ${param.name}${param.optional ? ' (optional)' : ''}${
|
|
76
|
+
param.name !== param.originalName ? ` (API name: ${param.originalName})` : ''
|
|
77
|
+
}${param.jsDoc ? ` - ${param.jsDoc}` : ''}`;
|
|
78
78
|
result.push(paramLine);
|
|
79
79
|
}
|
|
80
80
|
return renderComment(result.join('\n'));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const SUPPORTED_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'];
|
|
@@ -45,29 +45,22 @@ function getPathOperations(pathInfo, spec) {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Parameters can be defined on the path level and should be inherited by all operations
|
|
48
|
-
* contained in the path.
|
|
48
|
+
* contained in the path. If the operation has a parameter with the same name and in,
|
|
49
|
+
* then it won't be added to the operation parameters.
|
|
49
50
|
*/
|
|
50
|
-
function inheritPathParams(op,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (
|
|
64
|
-
!op.parameters
|
|
65
|
-
.filter((p) => 'name' in p)
|
|
66
|
-
.some((p) => p.name === pathParam.name && p.in === pathParam.in)
|
|
67
|
-
) {
|
|
68
|
-
op.parameters.push(Object.assign({}, pathParam));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
51
|
+
function inheritPathParams(op, inheritableParams) {
|
|
52
|
+
if (inheritableParams.length === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const pathParam of inheritableParams) {
|
|
57
|
+
// If the operation doesn't have a parameter with the same name and in, then add it
|
|
58
|
+
if (
|
|
59
|
+
!op.parameters.some(
|
|
60
|
+
(p) => p.name === pathParam.name && p.in === pathParam.in
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
op.parameters.push(Object.assign({}, pathParam));
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
66
|
}
|
|
@@ -90,7 +83,16 @@ function getPathOperation(
|
|
|
90
83
|
.replace(/[\/}\-]/g, '');
|
|
91
84
|
}
|
|
92
85
|
|
|
93
|
-
|
|
86
|
+
const pathLevelParams = _nullishCoalesce(spec.paths[pathInfo.path].parameters, () => ( []));
|
|
87
|
+
|
|
88
|
+
// Replace the path level parameters references with the actual parameters
|
|
89
|
+
replaceReferencedParams(pathLevelParams, _nullishCoalesce(_optionalChain([spec, 'access', _2 => _2.components, 'optionalAccess', _3 => _3.parameters]), () => ( {})));
|
|
90
|
+
|
|
91
|
+
// Replace the operation parameters references with the actual parameters
|
|
92
|
+
replaceReferencedParams(op.parameters, _nullishCoalesce(_optionalChain([spec, 'access', _4 => _4.components, 'optionalAccess', _5 => _5.parameters]), () => ( {})));
|
|
93
|
+
|
|
94
|
+
// At this stage path level parameters are already replaced with the actual parameters
|
|
95
|
+
inheritPathParams(op, pathLevelParams );
|
|
94
96
|
|
|
95
97
|
return op;
|
|
96
98
|
}
|
|
@@ -101,11 +103,35 @@ function getPathOperation(
|
|
|
101
103
|
* Removes invalid characters and ensures the name doesn't start with a number.
|
|
102
104
|
*/
|
|
103
105
|
function getOperationGroupName(op) {
|
|
104
|
-
let name = _optionalChain([op, 'access',
|
|
106
|
+
let name = _optionalChain([op, 'access', _6 => _6.tags, 'optionalAccess', _7 => _7.length]) ? op.tags[0] : 'default';
|
|
105
107
|
name = name.replace(/[^$_a-z0-9]+/gi, '');
|
|
106
108
|
return name.replace(/^[0-9]+/m, '');
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Replaces referenced parameters with the actual parameters from the components/parameters.
|
|
113
|
+
* It does replace them in place, because for parameters we only care about the actual parameter
|
|
114
|
+
* and not the reference object.
|
|
115
|
+
*/
|
|
116
|
+
function replaceReferencedParams(
|
|
117
|
+
parameters,
|
|
118
|
+
componentParams
|
|
119
|
+
) {
|
|
120
|
+
for (let index = 0; index < parameters.length; index++) {
|
|
121
|
+
const param = parameters[index];
|
|
122
|
+
|
|
123
|
+
if ('$ref' in param) {
|
|
124
|
+
const paramName = param.$ref.replace('#/components/parameters/', '');
|
|
125
|
+
const referencedParam = componentParams[paramName];
|
|
126
|
+
if (referencedParam) {
|
|
127
|
+
parameters[index] = Object.assign({}, referencedParam);
|
|
128
|
+
} else {
|
|
129
|
+
console.error(`Parameter ${paramName} reference not found in components parameters`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
109
135
|
|
|
110
136
|
|
|
111
137
|
|