swaggie 1.9.0-alpha.13 → 1.9.0-alpha.14
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/cli.js +1 -4
- package/dist/gen/genOperations.js +36 -17
- package/dist/gen/genTypes.js +6 -5
- package/dist/gen/index.js +8 -4
- package/dist/swagger/operations.js +16 -7
- package/dist/swagger/typesExtractor.js +12 -12
- package/dist/types.d.ts +1 -1
- package/dist/utils/documentLoader.js +1 -3
- package/dist/utils/refResolver.js +9 -21
- package/dist/utils/templateEngine.js +1 -3
- package/dist/utils/utils.js +19 -13
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -20,10 +20,7 @@ const testingFrameworkOption = new (0, _commander.Option)(
|
|
|
20
20
|
|
|
21
21
|
const packageJson = readPackageJson();
|
|
22
22
|
|
|
23
|
-
const modeOption = new (0, _commander.Option)('-m, --mode <mode>', 'Generation mode').choices([
|
|
24
|
-
'full',
|
|
25
|
-
'schemas',
|
|
26
|
-
]);
|
|
23
|
+
const modeOption = new (0, _commander.Option)('-m, --mode <mode>', 'Generation mode').choices(['full', 'schemas']);
|
|
27
24
|
const schemaStyleOption = new (0, _commander.Option)(
|
|
28
25
|
'-d, --schemaStyle <style>',
|
|
29
26
|
'Schema object declaration style'
|
|
@@ -15,6 +15,12 @@ var _createBarrel = require('./createBarrel');
|
|
|
15
15
|
var _header = require('./header');
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
18
24
|
var _jsDocs = require('./jsDocs');
|
|
19
25
|
|
|
20
26
|
/**
|
|
@@ -115,9 +121,13 @@ function prepareClient(
|
|
|
115
121
|
|
|
116
122
|
try {
|
|
117
123
|
const [respObject, responseContentType] = _utils.getBestResponse.call(void 0, op, components);
|
|
118
|
-
const returnType =
|
|
124
|
+
const returnType = respObject
|
|
125
|
+
? _swagger.getParameterType.call(void 0, respObject, options)
|
|
126
|
+
: options.preferAny
|
|
127
|
+
? 'any'
|
|
128
|
+
: 'unknown';
|
|
119
129
|
|
|
120
|
-
const body = getRequestBody(op.requestBody, components, options);
|
|
130
|
+
const body = op.requestBody ? getRequestBody(op.requestBody, components, options) : null;
|
|
121
131
|
const queryParams = getParams(op.parameters , options, ['query']);
|
|
122
132
|
let params = getParams(op.parameters , options);
|
|
123
133
|
let queryParamObject;
|
|
@@ -127,22 +137,24 @@ function prepareClient(
|
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
// If all parameters have 'x-position' defined, sort them by it
|
|
130
|
-
if (params.every((p) => p.original
|
|
131
|
-
params.sort(
|
|
140
|
+
if (params.every((p) => p.original && 'x-position' in p.original)) {
|
|
141
|
+
params.sort(
|
|
142
|
+
(a, b) =>
|
|
143
|
+
(a.original )['x-position'] -
|
|
144
|
+
(b.original )['x-position']
|
|
145
|
+
);
|
|
132
146
|
}
|
|
133
147
|
|
|
134
|
-
if (
|
|
148
|
+
if (
|
|
149
|
+
shouldGroupQueryParams(queryParams, options.queryParamsSerialization.queryParamsAsObject)
|
|
150
|
+
) {
|
|
135
151
|
queryParamObject = createQueryParamObject(queryParams);
|
|
136
152
|
params = replaceQueryParamsWithObject(params, queryParamObject);
|
|
137
153
|
}
|
|
138
154
|
|
|
139
155
|
markParametersAsSkippable(params);
|
|
140
156
|
|
|
141
|
-
const headers = getParams(
|
|
142
|
-
op.parameters ,
|
|
143
|
-
options,
|
|
144
|
-
['header']
|
|
145
|
-
);
|
|
157
|
+
const headers = getParams(op.parameters , options, ['header']);
|
|
146
158
|
// Some libraries need explicit Content-Type for request bodies.
|
|
147
159
|
if (_optionalChain([body, 'optionalAccess', _2 => _2.contentType]) === 'urlencoded') {
|
|
148
160
|
upsertFixedHeader(headers, 'Content-Type', 'application/x-www-form-urlencoded');
|
|
@@ -155,7 +167,7 @@ function prepareClient(
|
|
|
155
167
|
returnType,
|
|
156
168
|
responseContentType,
|
|
157
169
|
method: op.method.toUpperCase(),
|
|
158
|
-
name: getOperationName(op.operationId, op.group),
|
|
170
|
+
name: getOperationName(_nullishCoalesce(op.operationId, () => ( null)), op.group),
|
|
159
171
|
url: prepareUrl(op.path),
|
|
160
172
|
parameters: params,
|
|
161
173
|
query: queryParams,
|
|
@@ -218,7 +230,8 @@ function replaceQueryParamsWithObject(
|
|
|
218
230
|
params,
|
|
219
231
|
queryParamObject
|
|
220
232
|
) {
|
|
221
|
-
const isQueryParam = (param) =>
|
|
233
|
+
const isQueryParam = (param) =>
|
|
234
|
+
!!param.original && 'in' in param.original && param.original.in === 'query';
|
|
222
235
|
|
|
223
236
|
const firstQueryParamIndex = params.findIndex(isQueryParam);
|
|
224
237
|
if (firstQueryParamIndex < 0) {
|
|
@@ -275,7 +288,11 @@ function prepareUrl(path) {
|
|
|
275
288
|
* it can happen very easily and we need to handle it gracefully.
|
|
276
289
|
*/
|
|
277
290
|
function fixDuplicateOperations(operations) {
|
|
278
|
-
if (!operations
|
|
291
|
+
if (!operations) {
|
|
292
|
+
return [];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (operations.length < 2) {
|
|
279
296
|
return operations;
|
|
280
297
|
}
|
|
281
298
|
|
|
@@ -360,7 +377,7 @@ function prepareUrl(path) {
|
|
|
360
377
|
*/
|
|
361
378
|
function getParamName(name) {
|
|
362
379
|
if (!name) {
|
|
363
|
-
return name;
|
|
380
|
+
return _nullishCoalesce(name, () => ( ''));
|
|
364
381
|
}
|
|
365
382
|
|
|
366
383
|
return _utils.escapeIdentifier.call(void 0,
|
|
@@ -397,13 +414,15 @@ function getRequestBody(
|
|
|
397
414
|
const isFormData = contentType === 'form-data';
|
|
398
415
|
|
|
399
416
|
if (bodyContent) {
|
|
417
|
+
const reqBodyAny = reqBody ;
|
|
418
|
+
const xName = reqBodyAny['x-name'];
|
|
400
419
|
return {
|
|
401
|
-
originalName: _nullishCoalesce(
|
|
402
|
-
name: getParamName(_nullishCoalesce(
|
|
420
|
+
originalName: _nullishCoalesce(xName, () => ( 'body')),
|
|
421
|
+
name: getParamName(_nullishCoalesce(xName, () => ( 'body'))),
|
|
403
422
|
type: isFormData ? 'FormData' : _swagger.getParameterType.call(void 0, bodyContent, options),
|
|
404
423
|
optional: !reqBody.required,
|
|
405
424
|
original: reqBody,
|
|
406
|
-
contentType,
|
|
425
|
+
contentType: _nullishCoalesce(contentType, () => ( undefined)),
|
|
407
426
|
};
|
|
408
427
|
}
|
|
409
428
|
|
package/dist/gen/genTypes.js
CHANGED
|
@@ -204,8 +204,9 @@ function generateItemsType(schema, options) {
|
|
|
204
204
|
function renderExtendedEnumType(name, def) {
|
|
205
205
|
const isString = def.type === 'string';
|
|
206
206
|
let res = `export enum ${name} {\n`;
|
|
207
|
-
const
|
|
208
|
-
const
|
|
207
|
+
const defAny = def ;
|
|
208
|
+
const enumNames = _nullishCoalesce(_nullishCoalesce(defAny['x-enumNames'], () => ( defAny['x-enum-varnames'])), () => ( []));
|
|
209
|
+
const enumValues = (_nullishCoalesce(def.enum, () => ( []))).map((el) => (isString ? `"${el}"` : el));
|
|
209
210
|
|
|
210
211
|
for (let index = 0; index < enumNames.length; index++) {
|
|
211
212
|
res += ` ${_utils.escapePropName.call(void 0, enumNames[index])} = ${enumValues[index]},\n`;
|
|
@@ -221,7 +222,7 @@ function renderEnumType(name, def, options) {
|
|
|
221
222
|
return renderStringEnumDeclaration(name, def, options);
|
|
222
223
|
}
|
|
223
224
|
|
|
224
|
-
const values = def.enum.map((v) => (typeof v === 'number' ? v : `"${v}"`)).join(' | ');
|
|
225
|
+
const values = (_nullishCoalesce(def.enum, () => ( []))).map((v) => (typeof v === 'number' ? v : `"${v}"`)).join(' | ');
|
|
225
226
|
return `export type ${name} = ${values};\n`;
|
|
226
227
|
}
|
|
227
228
|
|
|
@@ -272,7 +273,7 @@ function toPascalCase(value) {
|
|
|
272
273
|
*/
|
|
273
274
|
function renderOpenApi31Enum(name, def) {
|
|
274
275
|
let res = `export enum ${name} {\n`;
|
|
275
|
-
for (const v of def.oneOf) {
|
|
276
|
+
for (const v of _nullishCoalesce(def.oneOf, () => ( []))) {
|
|
276
277
|
if ('const' in v) {
|
|
277
278
|
res += ` ${_utils.escapePropName.call(void 0, v.title)} = ${
|
|
278
279
|
typeof v.const === 'string' ? `"${v.const}"` : v.const
|
|
@@ -383,7 +384,7 @@ function getMergedCompositeObjects(schema) {
|
|
|
383
384
|
}
|
|
384
385
|
|
|
385
386
|
function isObject(item) {
|
|
386
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
|
387
|
+
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
387
388
|
}
|
|
388
389
|
function deepMerge(target, ...sources) {
|
|
389
390
|
if (!sources.length) return target;
|
package/dist/gen/index.js
CHANGED
|
@@ -24,15 +24,19 @@ var _utils = require('../utils');
|
|
|
24
24
|
|
|
25
25
|
if (options.out) {
|
|
26
26
|
const destFile = _utils.prepareOutputFilename.call(void 0, options.out);
|
|
27
|
-
|
|
27
|
+
if (destFile) {
|
|
28
|
+
await _utils.saveFile.call(void 0, destFile, fileContents);
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
if (options.mocks && options.testingFramework && options.out) {
|
|
31
33
|
const resolvedMocksPath = _utils.prepareOutputFilename.call(void 0, options.mocks);
|
|
32
34
|
const resolvedOutPath = _utils.prepareOutputFilename.call(void 0, options.out);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if (resolvedMocksPath && resolvedOutPath) {
|
|
36
|
+
const relativeApiImport = _utils.deriveRelativeImport.call(void 0, resolvedMocksPath, resolvedOutPath);
|
|
37
|
+
const mockContents = _genMocks2.default.call(void 0, spec, options, relativeApiImport);
|
|
38
|
+
await _utils.saveFile.call(void 0, resolvedMocksPath, mockContents);
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
return fileContents;
|
|
@@ -53,11 +53,15 @@ function inheritPathParams(op, inheritableParams) {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
if (!op.parameters) {
|
|
57
|
+
op.parameters = [];
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
for (const pathParam of inheritableParams) {
|
|
57
61
|
// If the operation doesn't have a parameter with the same name and in, then add it
|
|
58
62
|
if (
|
|
59
63
|
!op.parameters.some(
|
|
60
|
-
(p) => p.name === pathParam.name && p.in === pathParam.in
|
|
64
|
+
(p) => !('$ref' in p) && (p ).name === pathParam.name && (p ).in === pathParam.in
|
|
61
65
|
)
|
|
62
66
|
) {
|
|
63
67
|
op.parameters.push(Object.assign({}, pathParam));
|
|
@@ -70,9 +74,10 @@ function getPathOperation(
|
|
|
70
74
|
pathInfo,
|
|
71
75
|
spec
|
|
72
76
|
) {
|
|
77
|
+
const pathOp = pathInfo[method];
|
|
73
78
|
const op = Object.assign(
|
|
74
|
-
{ method, path: pathInfo.path, parameters: [], group: getOperationGroupName(
|
|
75
|
-
|
|
79
|
+
{ method, path: pathInfo.path, parameters: [], group: getOperationGroupName(pathOp) },
|
|
80
|
+
pathOp
|
|
76
81
|
);
|
|
77
82
|
|
|
78
83
|
// if there's no explicit operationId given, create one based on the method and path
|
|
@@ -83,13 +88,13 @@ function getPathOperation(
|
|
|
83
88
|
.replace(/[\/}\-]/g, '');
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
const pathLevelParams = _nullishCoalesce(spec.paths[pathInfo.path].parameters, () => ( []));
|
|
91
|
+
const pathLevelParams = _nullishCoalesce(_optionalChain([spec, 'access', _2 => _2.paths, 'optionalAccess', _3 => _3[pathInfo.path], 'optionalAccess', _4 => _4.parameters]), () => ( []));
|
|
87
92
|
|
|
88
93
|
// Replace the path level parameters references with the actual parameters
|
|
89
|
-
replaceReferencedParams(pathLevelParams, _nullishCoalesce(_optionalChain([spec, 'access',
|
|
94
|
+
replaceReferencedParams(pathLevelParams, _nullishCoalesce(_optionalChain([spec, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.parameters]), () => ( {})));
|
|
90
95
|
|
|
91
96
|
// Replace the operation parameters references with the actual parameters
|
|
92
|
-
replaceReferencedParams(op.parameters, _nullishCoalesce(_optionalChain([spec, 'access',
|
|
97
|
+
replaceReferencedParams(op.parameters, _nullishCoalesce(_optionalChain([spec, 'access', _7 => _7.components, 'optionalAccess', _8 => _8.parameters]), () => ( {})));
|
|
93
98
|
|
|
94
99
|
// At this stage path level parameters are already replaced with the actual parameters
|
|
95
100
|
inheritPathParams(op, pathLevelParams );
|
|
@@ -103,7 +108,7 @@ function getPathOperation(
|
|
|
103
108
|
* Removes invalid characters and ensures the name doesn't start with a number.
|
|
104
109
|
*/
|
|
105
110
|
function getOperationGroupName(op) {
|
|
106
|
-
let name = _optionalChain([op, 'access',
|
|
111
|
+
let name = _optionalChain([op, 'access', _9 => _9.tags, 'optionalAccess', _10 => _10.length]) ? op.tags[0] : 'default';
|
|
107
112
|
name = name.replace(/[^$_a-z0-9]+/gi, '');
|
|
108
113
|
return name.replace(/^[0-9]+/m, '');
|
|
109
114
|
}
|
|
@@ -117,6 +122,10 @@ function replaceReferencedParams(
|
|
|
117
122
|
parameters,
|
|
118
123
|
componentParams
|
|
119
124
|
) {
|
|
125
|
+
if (!parameters || !componentParams) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
120
129
|
for (let index = 0; index < parameters.length; index++) {
|
|
121
130
|
const param = parameters[index];
|
|
122
131
|
|
|
@@ -25,7 +25,7 @@ var _utils = require('../utils/utils');
|
|
|
25
25
|
return unknownType;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return getTypeFromSchemaResolved(param.schema, options, `${context}.schema`);
|
|
28
|
+
return getTypeFromSchemaResolved(param.schema , options, `${context}.schema`);
|
|
29
29
|
} exports.getParameterType = getParameterType;
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -172,7 +172,7 @@ function getTypeFromSchemaInternal(
|
|
|
172
172
|
return getTypeFromObject(schema, options, undefined, context);
|
|
173
173
|
}
|
|
174
174
|
if ('enum' in schema) {
|
|
175
|
-
return `${schema.enum.map((v) => JSON.stringify(v)).join(' | ')}`;
|
|
175
|
+
return `${(_nullishCoalesce(schema.enum, () => ( []))).map((v) => JSON.stringify(v)).join(' | ')}`;
|
|
176
176
|
}
|
|
177
177
|
if (schema.type === 'integer' || schema.type === 'number') {
|
|
178
178
|
return 'number';
|
|
@@ -368,26 +368,26 @@ function isRequiredOnlyCompositeBranch(schema) {
|
|
|
368
368
|
* It is used only for `allOf` property, as it enforces extending types.
|
|
369
369
|
*/
|
|
370
370
|
function getRefCompositeTypes(schema) {
|
|
371
|
-
return schema.allOf
|
|
371
|
+
return (_nullishCoalesce(schema.allOf, () => ( [])))
|
|
372
372
|
.filter((v) => '$ref' in v)
|
|
373
373
|
.map((s) => getSafeIdentifier(s.$ref.split('/').pop()));
|
|
374
374
|
} exports.getRefCompositeTypes = getRefCompositeTypes;
|
|
375
375
|
|
|
376
376
|
/** Default values applied to every field of AppOptions that has a default. */
|
|
377
377
|
const APP_DEFAULTS = {
|
|
378
|
-
template: 'axios',
|
|
378
|
+
template: 'axios' ,
|
|
379
379
|
servicePrefix: '',
|
|
380
|
-
nullableStrategy: 'ignore',
|
|
381
|
-
generationMode: 'full',
|
|
382
|
-
schemaDeclarationStyle: 'interface',
|
|
383
|
-
enumDeclarationStyle: 'union',
|
|
384
|
-
enumNamesStyle: 'original',
|
|
380
|
+
nullableStrategy: 'ignore' ,
|
|
381
|
+
generationMode: 'full' ,
|
|
382
|
+
schemaDeclarationStyle: 'interface' ,
|
|
383
|
+
enumDeclarationStyle: 'union' ,
|
|
384
|
+
enumNamesStyle: 'original' ,
|
|
385
385
|
queryParamsSerialization: {
|
|
386
386
|
allowDots: true,
|
|
387
|
-
arrayFormat: 'repeat',
|
|
388
|
-
queryParamsAsObject: false,
|
|
387
|
+
arrayFormat: 'repeat' ,
|
|
388
|
+
queryParamsAsObject: false ,
|
|
389
389
|
},
|
|
390
|
-
}; exports.APP_DEFAULTS = APP_DEFAULTS;
|
|
390
|
+
} ; exports.APP_DEFAULTS = APP_DEFAULTS;
|
|
391
391
|
|
|
392
392
|
/**
|
|
393
393
|
* Fills in all AppOptions defaults for a partial ClientOptions object.
|
package/dist/types.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ async function loadFromUrl(url) {
|
|
|
35
35
|
|
|
36
36
|
async function readLocalFile(filePath) {
|
|
37
37
|
const contents = await new Promise((res, rej) =>
|
|
38
|
-
_nodefs2.default.readFile(filePath, 'utf8', (err, loadedContents) =>
|
|
39
|
-
err ? rej(err) : res(loadedContents)
|
|
40
|
-
)
|
|
38
|
+
_nodefs2.default.readFile(filePath, 'utf8', (err, loadedContents) => (err ? rej(err) : res(loadedContents)))
|
|
41
39
|
);
|
|
42
40
|
const spec = parseFileContents(contents , filePath) ;
|
|
43
41
|
|
|
@@ -5,10 +5,6 @@ var _yaml = require('yaml');
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
8
|
const SUPPORTED_COMPONENT_SECTIONS = new Set([
|
|
13
9
|
'schemas',
|
|
14
10
|
'parameters',
|
|
@@ -26,8 +22,6 @@ const SUPPORTED_COMPONENT_SECTIONS = new Set([
|
|
|
26
22
|
|
|
27
23
|
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
25
|
/**
|
|
32
26
|
* Resolves external file refs into local component refs.
|
|
33
27
|
* For now we only support local file refs (no http/https) and component targets.
|
|
@@ -109,9 +103,7 @@ async function resolveRef(
|
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
if (!fragment) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`External refs must include a JSON pointer fragment: '${rawRef}'`
|
|
114
|
-
);
|
|
106
|
+
throw new Error(`External refs must include a JSON pointer fragment: '${rawRef}'`);
|
|
115
107
|
}
|
|
116
108
|
|
|
117
109
|
if (!fragment.startsWith('/')) {
|
|
@@ -136,9 +128,7 @@ async function importRefFromFile(
|
|
|
136
128
|
|
|
137
129
|
if (!targetInfo) {
|
|
138
130
|
if (context.resolvingRefs.has(importKey)) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
`Circular non-component external ref is not supported: '${rawRef}'`
|
|
141
|
-
);
|
|
131
|
+
throw new Error(`Circular non-component external ref is not supported: '${rawRef}'`);
|
|
142
132
|
}
|
|
143
133
|
|
|
144
134
|
const targetCopy = structuredClone(target);
|
|
@@ -172,10 +162,7 @@ async function importRefFromFile(
|
|
|
172
162
|
}
|
|
173
163
|
|
|
174
164
|
function parseImportTarget(pointer) {
|
|
175
|
-
const parts = pointer
|
|
176
|
-
.replace(/^#\//, '')
|
|
177
|
-
.split('/')
|
|
178
|
-
.map(unescapePointerSegment);
|
|
165
|
+
const parts = pointer.replace(/^#\//, '').split('/').map(unescapePointerSegment);
|
|
179
166
|
|
|
180
167
|
if (parts.length === 2) {
|
|
181
168
|
const [legacySection, name] = parts;
|
|
@@ -250,12 +237,13 @@ function getOrCreateComponentAlias(
|
|
|
250
237
|
return candidate;
|
|
251
238
|
}
|
|
252
239
|
|
|
253
|
-
async function getValueByPointer(
|
|
240
|
+
async function getValueByPointer(
|
|
241
|
+
filePath,
|
|
242
|
+
pointer,
|
|
243
|
+
context
|
|
244
|
+
) {
|
|
254
245
|
const doc = await loadDocument(filePath, context);
|
|
255
|
-
const parts = pointer
|
|
256
|
-
.replace(/^#\//, '')
|
|
257
|
-
.split('/')
|
|
258
|
-
.map(unescapePointerSegment);
|
|
246
|
+
const parts = pointer.replace(/^#\//, '').split('/').map(unescapePointerSegment);
|
|
259
247
|
|
|
260
248
|
let current = doc;
|
|
261
249
|
for (const part of parts) {
|
|
@@ -34,9 +34,7 @@ let loadedFiles = null;
|
|
|
34
34
|
}
|
|
35
35
|
return (
|
|
36
36
|
templateFile in loadedFiles ||
|
|
37
|
-
Object.keys(loadedFiles).some(
|
|
38
|
-
(k) => _optionalChain([k, 'access', _9 => _9.split, 'call', _10 => _10('/'), 'access', _11 => _11.pop, 'call', _12 => _12(), 'optionalAccess', _13 => _13.split, 'call', _14 => _14('\\'), 'access', _15 => _15.pop, 'call', _16 => _16()]) === templateFile
|
|
39
|
-
)
|
|
37
|
+
Object.keys(loadedFiles).some((k) => _optionalChain([k, 'access', _9 => _9.split, 'call', _10 => _10('/'), 'access', _11 => _11.pop, 'call', _12 => _12(), 'optionalAccess', _13 => _13.split, 'call', _14 => _14('\\'), 'access', _15 => _15.pop, 'call', _16 => _16()]) === templateFile)
|
|
40
38
|
);
|
|
41
39
|
} exports.hasTemplateFile = hasTemplateFile;
|
|
42
40
|
|
package/dist/utils/utils.js
CHANGED
|
@@ -74,7 +74,7 @@ const reservedKeywords = new Set([
|
|
|
74
74
|
*/
|
|
75
75
|
function escapeIdentifier(name) {
|
|
76
76
|
if (!name) {
|
|
77
|
-
return name;
|
|
77
|
+
return _nullishCoalesce(name, () => ( ''));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (reservedKeywords.has(name) || /^[0-9]/.test(name)) {
|
|
@@ -139,10 +139,11 @@ const reservedKeywords = new Set([
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
return operations.reduce((groups, op) => {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
const groupKey = _nullishCoalesce(op.group, () => ( 'default'));
|
|
143
|
+
if (!groups[groupKey]) {
|
|
144
|
+
groups[groupKey] = [];
|
|
144
145
|
}
|
|
145
|
-
groups[
|
|
146
|
+
groups[groupKey].push(op);
|
|
146
147
|
return groups;
|
|
147
148
|
}, {});
|
|
148
149
|
} exports.groupOperationsByGroupName = groupOperationsByGroupName;
|
|
@@ -219,11 +220,13 @@ function resolveResponseRef(
|
|
|
219
220
|
return [];
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
return arr.concat().sort(
|
|
223
|
+
return arr.concat().sort((a, b) => {
|
|
224
|
+
const aVal = (a )[key] ;
|
|
225
|
+
const bVal = (b )[key] ;
|
|
226
|
+
return aVal != null && bVal != null ? (aVal > bVal ? 1 : bVal > aVal ? -1 : 0) : 0;
|
|
227
|
+
});
|
|
223
228
|
} exports.orderBy = orderBy;
|
|
224
229
|
|
|
225
|
-
const sortByKey = (key) => (a, b) => (a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0);
|
|
226
|
-
|
|
227
230
|
const orderedContentTypes = [
|
|
228
231
|
'text/plain',
|
|
229
232
|
'application/x-www-form-urlencoded',
|
|
@@ -233,32 +236,35 @@ const preferredJsonContentTypes = ['application/json', 'text/json'];
|
|
|
233
236
|
function getBestContentType(
|
|
234
237
|
reqBody
|
|
235
238
|
) {
|
|
236
|
-
const
|
|
239
|
+
const content = _nullishCoalesce(reqBody.content, () => ( {}));
|
|
240
|
+
const contentTypes = Object.keys(content);
|
|
237
241
|
if (contentTypes.length === 0) {
|
|
238
242
|
return [null, null];
|
|
239
243
|
}
|
|
240
244
|
|
|
241
|
-
const preferredJsonContentType = preferredJsonContentTypes.find((ct) =>
|
|
245
|
+
const preferredJsonContentType = preferredJsonContentTypes.find((ct) =>
|
|
246
|
+
contentTypes.includes(ct)
|
|
247
|
+
);
|
|
242
248
|
if (preferredJsonContentType) {
|
|
243
|
-
const typeObject =
|
|
249
|
+
const typeObject = content[preferredJsonContentType];
|
|
244
250
|
const type = getContentType(preferredJsonContentType);
|
|
245
251
|
return [typeObject, type];
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
const jsonLikeContentType = contentTypes.find(isJsonLikeContentType);
|
|
249
255
|
if (jsonLikeContentType) {
|
|
250
|
-
const typeObject =
|
|
256
|
+
const typeObject = content[jsonLikeContentType];
|
|
251
257
|
return [typeObject, 'json'];
|
|
252
258
|
}
|
|
253
259
|
|
|
254
260
|
const firstContentType = orderedContentTypes.find((ct) => contentTypes.includes(ct));
|
|
255
261
|
if (firstContentType) {
|
|
256
|
-
const typeObject =
|
|
262
|
+
const typeObject = content[firstContentType];
|
|
257
263
|
const type = getContentType(firstContentType);
|
|
258
264
|
return [typeObject, type];
|
|
259
265
|
}
|
|
260
266
|
|
|
261
|
-
const typeObject =
|
|
267
|
+
const typeObject = content[contentTypes[0]];
|
|
262
268
|
const type = getContentType(contentTypes[0]);
|
|
263
269
|
return [typeObject, type];
|
|
264
270
|
} exports.getBestContentType = getBestContentType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swaggie",
|
|
3
|
-
"version": "1.9.0-alpha.
|
|
3
|
+
"version": "1.9.0-alpha.14",
|
|
4
4
|
"description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Piotr Dabrowski",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"build": "bun run bundle-templates && sucrase ./src -d ./dist --transforms typescript,imports && bun run rm-tests && bun run types",
|
|
41
41
|
"bundle-templates": "bun scripts/bundle-templates.ts",
|
|
42
42
|
"rm-tests": "find dist/ \\( -name '*.spec.js' -o -name 'types.js' \\) -type f -delete",
|
|
43
|
-
"types": "tsc
|
|
43
|
+
"types": "tsc --project tsconfig.types.json && cp test/index.d.ts ./dist/",
|
|
44
44
|
"docs:build": "vitepress build docs",
|
|
45
45
|
"docs:dev": "vitepress dev docs",
|
|
46
46
|
"docs:preview": "vitepress preview docs"
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"bun-types": "1.3.11",
|
|
80
80
|
"openapi-types": "^12.1.3",
|
|
81
81
|
"sucrase": "3.35.1",
|
|
82
|
-
"typescript": "
|
|
82
|
+
"typescript": "6.0.2",
|
|
83
83
|
"vitepress": "^2.0.0-alpha.17",
|
|
84
84
|
"vitepress-plugin-tabs": "0.8.0"
|
|
85
85
|
}
|