swaggie 1.5.3-beta.4 → 1.5.3-beta.5
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 +41 -19
- package/dist/utils/utils.js +35 -4
- package/package.json +1 -1
|
@@ -34,7 +34,7 @@ var _jsDocs = require('./jsDocs');
|
|
|
34
34
|
|
|
35
35
|
for (const name in groups) {
|
|
36
36
|
const group = groups[name];
|
|
37
|
-
const clientData = prepareClient(servicePrefix + name, group, options);
|
|
37
|
+
const clientData = prepareClient(servicePrefix + name, group, spec.components, options);
|
|
38
38
|
|
|
39
39
|
if (!clientData) {
|
|
40
40
|
continue;
|
|
@@ -56,9 +56,10 @@ var _jsDocs = require('./jsDocs');
|
|
|
56
56
|
function prepareClient(
|
|
57
57
|
name,
|
|
58
58
|
operations,
|
|
59
|
+
components,
|
|
59
60
|
options
|
|
60
61
|
) {
|
|
61
|
-
const preparedOperations = prepareOperations(operations, options);
|
|
62
|
+
const preparedOperations = prepareOperations(operations, options, components);
|
|
62
63
|
|
|
63
64
|
if (preparedOperations.length === 0) {
|
|
64
65
|
return null;
|
|
@@ -84,7 +85,11 @@ function prepareClient(
|
|
|
84
85
|
* @param options
|
|
85
86
|
* @returns List of operations prepared for client generation
|
|
86
87
|
*/
|
|
87
|
-
function prepareOperations(
|
|
88
|
+
function prepareOperations(
|
|
89
|
+
operations,
|
|
90
|
+
options,
|
|
91
|
+
components
|
|
92
|
+
) {
|
|
88
93
|
let ops = fixDuplicateOperations(operations);
|
|
89
94
|
|
|
90
95
|
if (options.skipDeprecated) {
|
|
@@ -92,10 +97,10 @@ function prepareClient(
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
return ops.map((op) => {
|
|
95
|
-
const [respObject, responseContentType] = _utils.getBestResponse.call(void 0, op);
|
|
100
|
+
const [respObject, responseContentType] = _utils.getBestResponse.call(void 0, op, components);
|
|
96
101
|
const returnType = _swagger.getParameterType.call(void 0, respObject, options);
|
|
97
102
|
|
|
98
|
-
const body = getRequestBody(op.requestBody, options);
|
|
103
|
+
const body = getRequestBody(op.requestBody, components, options);
|
|
99
104
|
const queryParams = getParams(op.parameters , options, ['query']);
|
|
100
105
|
const params = getParams(op.parameters , options);
|
|
101
106
|
|
|
@@ -276,23 +281,40 @@ function prepareUrl(path) {
|
|
|
276
281
|
} exports.getParamName = getParamName;
|
|
277
282
|
|
|
278
283
|
function getRequestBody(
|
|
279
|
-
|
|
284
|
+
rawReqBody,
|
|
285
|
+
components,
|
|
280
286
|
options
|
|
281
287
|
) {
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
contentType,
|
|
294
|
-
};
|
|
288
|
+
if (!rawReqBody) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let reqBody;
|
|
293
|
+
if ('$ref' in rawReqBody) {
|
|
294
|
+
const refName = rawReqBody.$ref.replace('#/components/requestBodies/', '');
|
|
295
|
+
const resolved = _optionalChain([components, 'optionalAccess', _8 => _8.requestBodies, 'optionalAccess', _9 => _9[refName]]);
|
|
296
|
+
if (!resolved || '$ref' in resolved) {
|
|
297
|
+
console.error(`RequestBody $ref '${rawReqBody.$ref}' not found in components/requestBodies`);
|
|
298
|
+
return null;
|
|
295
299
|
}
|
|
300
|
+
reqBody = resolved;
|
|
301
|
+
} else {
|
|
302
|
+
reqBody = rawReqBody;
|
|
296
303
|
}
|
|
304
|
+
|
|
305
|
+
const [bodyContent, contentType] = _utils.getBestContentType.call(void 0, reqBody);
|
|
306
|
+
const isFormData = contentType === 'form-data';
|
|
307
|
+
|
|
308
|
+
if (bodyContent) {
|
|
309
|
+
return {
|
|
310
|
+
originalName: _nullishCoalesce(reqBody['x-name'], () => ( 'body')),
|
|
311
|
+
name: getParamName(_nullishCoalesce(reqBody['x-name'], () => ( 'body'))),
|
|
312
|
+
type: isFormData ? 'FormData' : _swagger.getParameterType.call(void 0, bodyContent, options),
|
|
313
|
+
optional: !reqBody.required,
|
|
314
|
+
original: reqBody,
|
|
315
|
+
contentType,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
297
319
|
return null;
|
|
298
320
|
}
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _nodefs = require('node:fs');
|
|
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; }var _nodefs = require('node:fs');
|
|
2
2
|
var _nodepath = require('node:path');
|
|
3
3
|
|
|
4
4
|
|
|
@@ -171,11 +171,15 @@ const reservedKeywords = new Set([
|
|
|
171
171
|
* Other media types are not supported at this time.
|
|
172
172
|
* @returns Response or reference of the success response
|
|
173
173
|
*/
|
|
174
|
-
function getBestResponse(
|
|
174
|
+
function getBestResponse(
|
|
175
|
+
op,
|
|
176
|
+
components
|
|
177
|
+
) {
|
|
175
178
|
const NOT_FOUND = 100000;
|
|
176
179
|
const lowestCode = _nullishCoalesce(Object.keys(op.responses).sort().shift(), () => ( NOT_FOUND));
|
|
177
180
|
|
|
178
|
-
const
|
|
181
|
+
const rawResp = lowestCode === NOT_FOUND ? op.responses[0] : op.responses[lowestCode.toString()];
|
|
182
|
+
const resp = resolveResponseRef(rawResp, components);
|
|
179
183
|
|
|
180
184
|
if (resp && 'content' in resp) {
|
|
181
185
|
return getBestContentType(resp);
|
|
@@ -183,6 +187,33 @@ const reservedKeywords = new Set([
|
|
|
183
187
|
return [null, null];
|
|
184
188
|
} exports.getBestResponse = getBestResponse;
|
|
185
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Resolves a $ref in a response object to the actual response object from components/responses.
|
|
192
|
+
* If the response is already an object (not a reference), it is returned as-is.
|
|
193
|
+
*/
|
|
194
|
+
function resolveResponseRef(
|
|
195
|
+
resp,
|
|
196
|
+
components
|
|
197
|
+
) {
|
|
198
|
+
if (!resp) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!('$ref' in resp)) {
|
|
203
|
+
return resp;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const refName = resp.$ref.replace('#/components/responses/', '');
|
|
207
|
+
const resolved = _optionalChain([components, 'optionalAccess', _ => _.responses, 'optionalAccess', _2 => _2[refName]]);
|
|
208
|
+
|
|
209
|
+
if (!resolved) {
|
|
210
|
+
console.error(`Response $ref '${resp.$ref}' not found in components/responses`);
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return resolved ;
|
|
215
|
+
}
|
|
216
|
+
|
|
186
217
|
/** This method tries to fix potentially wrong out parameter given from commandline */
|
|
187
218
|
function prepareOutputFilename(out) {
|
|
188
219
|
if (!out) {
|
|
@@ -206,7 +237,7 @@ const reservedKeywords = new Set([
|
|
|
206
237
|
return arr.concat().sort(sortByKey(key));
|
|
207
238
|
} exports.orderBy = orderBy;
|
|
208
239
|
|
|
209
|
-
const sortByKey = (key) => (a, b) => a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0;
|
|
240
|
+
const sortByKey = (key) => (a, b) => (a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0);
|
|
210
241
|
|
|
211
242
|
const orderedContentTypes = [
|
|
212
243
|
'application/json',
|