@looker/sdk-codegen 21.9.0 → 21.9.3
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/CHANGELOG.md +38 -0
- package/lib/codeGen.d.ts +14 -0
- package/lib/codeGen.js +19 -0
- package/lib/codeGen.js.map +1 -1
- package/lib/codeGenerators.d.ts +2 -2
- package/lib/codeGenerators.js.map +1 -1
- package/lib/csharp.gen.js.map +1 -1
- package/lib/esm/codeGen.js +19 -0
- package/lib/esm/codeGen.js.map +1 -1
- package/lib/esm/codeGenerators.js.map +1 -1
- package/lib/esm/csharp.gen.js.map +1 -1
- package/lib/esm/exampleInfo.js.map +1 -1
- package/lib/esm/go.gen.js.map +1 -1
- package/lib/esm/kotlin.gen.js.map +1 -1
- package/lib/esm/pseudo.gen.js.map +1 -1
- package/lib/esm/python.gen.js +1 -1
- package/lib/esm/python.gen.js.map +1 -1
- package/lib/esm/sdkModels.js +380 -21
- package/lib/esm/sdkModels.js.map +1 -1
- package/lib/esm/specConverter.js +2 -2
- package/lib/esm/specConverter.js.map +1 -1
- package/lib/esm/specDiff.js +2 -0
- package/lib/esm/specDiff.js.map +1 -1
- package/lib/esm/swift.gen.js.map +1 -1
- package/lib/esm/typescript.gen.js +154 -10
- package/lib/esm/typescript.gen.js.map +1 -1
- package/lib/exampleInfo.d.ts +2 -14
- package/lib/exampleInfo.js.map +1 -1
- package/lib/go.gen.js.map +1 -1
- package/lib/kotlin.gen.js.map +1 -1
- package/lib/pseudo.gen.js.map +1 -1
- package/lib/python.gen.js +1 -1
- package/lib/python.gen.js.map +1 -1
- package/lib/sdkModels.d.ts +21 -1
- package/lib/sdkModels.js +382 -21
- package/lib/sdkModels.js.map +1 -1
- package/lib/specConverter.d.ts +4 -4
- package/lib/specConverter.js +2 -2
- package/lib/specConverter.js.map +1 -1
- package/lib/specDiff.js +2 -0
- package/lib/specDiff.js.map +1 -1
- package/lib/swift.gen.js.map +1 -1
- package/lib/typescript.gen.d.ts +13 -0
- package/lib/typescript.gen.js +153 -9
- package/lib/typescript.gen.js.map +1 -1
- package/package.json +6 -5
- package/lib/esm/testUtils/index.js +0 -2
- package/lib/esm/testUtils/index.js.map +0 -1
- package/lib/esm/testUtils/testUtils.js +0 -53
- package/lib/esm/testUtils/testUtils.js.map +0 -1
- package/lib/testUtils/index.js +0 -17
- package/lib/testUtils/index.js.map +0 -1
- package/lib/testUtils/testUtils.js +0 -64
- package/lib/testUtils/testUtils.js.map +0 -1
package/lib/esm/sdkModels.js
CHANGED
|
@@ -5,7 +5,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
6
|
import * as OAS from 'openapi3-ts';
|
|
7
7
|
import md5 from 'blueimp-md5';
|
|
8
|
-
import
|
|
8
|
+
import isEmpty from 'lodash/isEmpty';
|
|
9
|
+
import { DelimArray, ResponseMode, StatusCode, responseMode } from '@looker/sdk-rtl';
|
|
10
|
+
import { upgradeSpecObject } from './specConverter';
|
|
9
11
|
export var strBody = 'body';
|
|
10
12
|
export var strRequest = 'Request';
|
|
11
13
|
export var strWrite = 'Write';
|
|
@@ -21,6 +23,73 @@ export var TypeOfType = function (TypeOfType) {
|
|
|
21
23
|
TypeOfType[TypeOfType["Complex"] = 5] = "Complex";
|
|
22
24
|
return TypeOfType;
|
|
23
25
|
}({});
|
|
26
|
+
export var parseFields = fields => {
|
|
27
|
+
function splitConsideringParentheses(segment) {
|
|
28
|
+
var parts = [];
|
|
29
|
+
var currentPart = '';
|
|
30
|
+
var openParentheses = 0;
|
|
31
|
+
var lastChar = '';
|
|
32
|
+
function charCheck(char) {
|
|
33
|
+
if (lastChar === char) {
|
|
34
|
+
if (char === '(' || char === ')' && openParentheses < 0) {
|
|
35
|
+
throw new Error("Unexpected '".concat(char, "' after '").concat(currentPart, "' parens:").concat(openParentheses));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (var char of segment) {
|
|
40
|
+
if (char === '(') {
|
|
41
|
+
openParentheses++;
|
|
42
|
+
charCheck(char);
|
|
43
|
+
} else if (char === ')') {
|
|
44
|
+
openParentheses--;
|
|
45
|
+
charCheck(char);
|
|
46
|
+
}
|
|
47
|
+
if (char === ',' && openParentheses === 0) {
|
|
48
|
+
parts.push(currentPart);
|
|
49
|
+
currentPart = '';
|
|
50
|
+
} else {
|
|
51
|
+
currentPart += char;
|
|
52
|
+
}
|
|
53
|
+
lastChar = char;
|
|
54
|
+
}
|
|
55
|
+
if (currentPart) {
|
|
56
|
+
parts.push(currentPart);
|
|
57
|
+
}
|
|
58
|
+
return parts;
|
|
59
|
+
}
|
|
60
|
+
function parseSegment(segment) {
|
|
61
|
+
var parts = splitConsideringParentheses(segment);
|
|
62
|
+
var result = {};
|
|
63
|
+
parts.forEach(part => {
|
|
64
|
+
var [key, nestedStr] = part.split(/\((.+)/);
|
|
65
|
+
key = key.trim();
|
|
66
|
+
if (nestedStr) {
|
|
67
|
+
nestedStr = nestedStr.slice(0, -1);
|
|
68
|
+
if (key in result) {
|
|
69
|
+
throw new Error("Duplicate '".concat(key, "' found"));
|
|
70
|
+
}
|
|
71
|
+
result[key] = parseSegment(nestedStr);
|
|
72
|
+
} else {
|
|
73
|
+
var p = part.trim();
|
|
74
|
+
if (p in result) {
|
|
75
|
+
throw new Error("Duplicate '".concat(key, "' found"));
|
|
76
|
+
}
|
|
77
|
+
if (p) result[p] = p;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
if (typeof fields === 'string') {
|
|
83
|
+
fields = fields.trim();
|
|
84
|
+
if (!fields) return {};
|
|
85
|
+
return parseSegment(fields);
|
|
86
|
+
} else if (Array.isArray(fields)) {
|
|
87
|
+
var result = {};
|
|
88
|
+
fields.forEach(f => result[f] = f);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
return fields;
|
|
92
|
+
};
|
|
24
93
|
export var typeOfType = type => {
|
|
25
94
|
if (type.intrinsic) return TypeOfType.Intrinsic;
|
|
26
95
|
switch (type.className) {
|
|
@@ -56,12 +125,12 @@ export var camelCase = value => {
|
|
|
56
125
|
export var titleCase = value => {
|
|
57
126
|
if (!value) return '';
|
|
58
127
|
value = camelCase(value);
|
|
59
|
-
return value[0].toLocaleUpperCase() + value.
|
|
128
|
+
return value[0].toLocaleUpperCase() + value.substring(1);
|
|
60
129
|
};
|
|
61
130
|
export var firstCase = value => {
|
|
62
131
|
if (!value) return '';
|
|
63
132
|
value = camelCase(value);
|
|
64
|
-
return value[0].toLocaleUpperCase() + value.
|
|
133
|
+
return value[0].toLocaleUpperCase() + value.substring(1).toLocaleLowerCase();
|
|
65
134
|
};
|
|
66
135
|
var searchIt = value => value ? value + '\t' : '';
|
|
67
136
|
var localeSort = (a, b) => a.localeCompare(b);
|
|
@@ -274,6 +343,150 @@ class SchemadSymbol extends _Symbol {
|
|
|
274
343
|
return this.deprecated ? 'deprecated' : '';
|
|
275
344
|
}
|
|
276
345
|
}
|
|
346
|
+
var mockData = function mockData(propertyName, type, override) {
|
|
347
|
+
var _dataMocks$type$name;
|
|
348
|
+
var empty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
349
|
+
var over = override !== undefined;
|
|
350
|
+
var stringer = mocked => {
|
|
351
|
+
if (over) {
|
|
352
|
+
return String(override);
|
|
353
|
+
}
|
|
354
|
+
if (empty) {
|
|
355
|
+
return '';
|
|
356
|
+
}
|
|
357
|
+
return mocked;
|
|
358
|
+
};
|
|
359
|
+
var inter = mocked => {
|
|
360
|
+
if (over) {
|
|
361
|
+
return parseInt(override, 10);
|
|
362
|
+
}
|
|
363
|
+
if (empty) {
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
return mocked;
|
|
367
|
+
};
|
|
368
|
+
var floater = mocked => {
|
|
369
|
+
if (over) {
|
|
370
|
+
return parseFloat(override);
|
|
371
|
+
}
|
|
372
|
+
if (empty) {
|
|
373
|
+
return 0.0;
|
|
374
|
+
}
|
|
375
|
+
return mocked;
|
|
376
|
+
};
|
|
377
|
+
var dater = mocked => {
|
|
378
|
+
if (over) {
|
|
379
|
+
return new Date(override);
|
|
380
|
+
}
|
|
381
|
+
if (empty) {
|
|
382
|
+
return new Date(1970, 0, 1);
|
|
383
|
+
}
|
|
384
|
+
return mocked;
|
|
385
|
+
};
|
|
386
|
+
var booler = mocked => {
|
|
387
|
+
if (over) {
|
|
388
|
+
return Boolean(override);
|
|
389
|
+
}
|
|
390
|
+
if (empty) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return mocked;
|
|
394
|
+
};
|
|
395
|
+
var anyer = mocked => {
|
|
396
|
+
if (over) {
|
|
397
|
+
return override;
|
|
398
|
+
}
|
|
399
|
+
if (empty) {
|
|
400
|
+
return {};
|
|
401
|
+
}
|
|
402
|
+
return mocked;
|
|
403
|
+
};
|
|
404
|
+
var dataMocks = {
|
|
405
|
+
any: {
|
|
406
|
+
value: anyer({
|
|
407
|
+
a: 1,
|
|
408
|
+
b: 'two'
|
|
409
|
+
})
|
|
410
|
+
},
|
|
411
|
+
boolean: {
|
|
412
|
+
value: booler(true)
|
|
413
|
+
},
|
|
414
|
+
byte: {
|
|
415
|
+
value: stringer('A')
|
|
416
|
+
},
|
|
417
|
+
binary: {
|
|
418
|
+
value: stringer('01')
|
|
419
|
+
},
|
|
420
|
+
date: {
|
|
421
|
+
value: dater(new Date(2024, 0, 5))
|
|
422
|
+
},
|
|
423
|
+
datetime: {
|
|
424
|
+
value: dater(new Date(2024, 0, 5, 1))
|
|
425
|
+
},
|
|
426
|
+
double: {
|
|
427
|
+
value: floater(2.2)
|
|
428
|
+
},
|
|
429
|
+
float: {
|
|
430
|
+
value: floater(1.1)
|
|
431
|
+
},
|
|
432
|
+
int32: {
|
|
433
|
+
value: inter(32)
|
|
434
|
+
},
|
|
435
|
+
int64: {
|
|
436
|
+
value: inter(64)
|
|
437
|
+
},
|
|
438
|
+
integer: {
|
|
439
|
+
value: inter(1)
|
|
440
|
+
},
|
|
441
|
+
number: {
|
|
442
|
+
value: inter(2)
|
|
443
|
+
},
|
|
444
|
+
object: {
|
|
445
|
+
value: anyer({
|
|
446
|
+
[propertyName]: 1
|
|
447
|
+
})
|
|
448
|
+
},
|
|
449
|
+
password: {
|
|
450
|
+
value: stringer('*')
|
|
451
|
+
},
|
|
452
|
+
string: {
|
|
453
|
+
value: stringer(propertyName)
|
|
454
|
+
},
|
|
455
|
+
uri: {
|
|
456
|
+
value: stringer("urn:".concat(propertyName))
|
|
457
|
+
},
|
|
458
|
+
url: {
|
|
459
|
+
value: stringer("https://".concat(propertyName, ".mock"))
|
|
460
|
+
},
|
|
461
|
+
email: {
|
|
462
|
+
value: stringer("".concat(propertyName, "@example.com"))
|
|
463
|
+
},
|
|
464
|
+
uuid: {
|
|
465
|
+
value: stringer("uuid-".concat(propertyName))
|
|
466
|
+
},
|
|
467
|
+
hostname: {
|
|
468
|
+
value: stringer("https://".concat(propertyName))
|
|
469
|
+
},
|
|
470
|
+
ipv4: {
|
|
471
|
+
value: stringer('127.0.0.1')
|
|
472
|
+
},
|
|
473
|
+
ipv6: {
|
|
474
|
+
value: stringer('::1')
|
|
475
|
+
},
|
|
476
|
+
void: {
|
|
477
|
+
value: over ? override : null
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
return (_dataMocks$type$name = dataMocks[type.name]) !== null && _dataMocks$type$name !== void 0 ? _dataMocks$type$name : override;
|
|
481
|
+
};
|
|
482
|
+
var mockOptions = options => {
|
|
483
|
+
var _options$override, _options$empty;
|
|
484
|
+
return {
|
|
485
|
+
fields: options !== null && options !== void 0 && options.fields ? options === null || options === void 0 ? void 0 : options.fields : '',
|
|
486
|
+
override: (_options$override = options === null || options === void 0 ? void 0 : options.override) !== null && _options$override !== void 0 ? _options$override : {},
|
|
487
|
+
empty: (_options$empty = options === null || options === void 0 ? void 0 : options.empty) !== null && _options$empty !== void 0 ? _options$empty : false
|
|
488
|
+
};
|
|
489
|
+
};
|
|
277
490
|
export class Property extends SchemadSymbol {
|
|
278
491
|
constructor(name, type, schema) {
|
|
279
492
|
var _schema$required;
|
|
@@ -284,7 +497,7 @@ export class Property extends SchemadSymbol {
|
|
|
284
497
|
_defineProperty(this, "nullable", false);
|
|
285
498
|
_defineProperty(this, "readOnly", false);
|
|
286
499
|
_defineProperty(this, "writeOnly", false);
|
|
287
|
-
this.required =
|
|
500
|
+
this.required = Boolean(required.includes(name) || ((_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(name)));
|
|
288
501
|
this.nullable = this.schema.nullable || this.schema['x-looker-nullable'] || false;
|
|
289
502
|
this.readOnly = this.schema.readOnly || false;
|
|
290
503
|
this.writeOnly = this.schema.writeOnly || false;
|
|
@@ -307,6 +520,56 @@ export class Property extends SchemadSymbol {
|
|
|
307
520
|
search(rx, criteria) {
|
|
308
521
|
return rx.test(this.searchString(criteria)) || this.type.search(rx, criteria);
|
|
309
522
|
}
|
|
523
|
+
mock() {
|
|
524
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
525
|
+
var {
|
|
526
|
+
fields,
|
|
527
|
+
override,
|
|
528
|
+
empty
|
|
529
|
+
} = mockOptions(options);
|
|
530
|
+
if (isEmpty(fields) && !this.required) return undefined;
|
|
531
|
+
var keys = parseFields(fields);
|
|
532
|
+
if (!isEmpty(fields) && !(this.name in keys)) return undefined;
|
|
533
|
+
var type = this.type;
|
|
534
|
+
if (type.elementType) {
|
|
535
|
+
var el = type.elementType;
|
|
536
|
+
var over = el.intrinsic && el.isString ? this.name : override;
|
|
537
|
+
var scope = typeof keys[this.name] === 'string' ? undefined : keys[this.name];
|
|
538
|
+
var opts = el.intrinsic ? {
|
|
539
|
+
fields: el.name,
|
|
540
|
+
override: over
|
|
541
|
+
} : {
|
|
542
|
+
fields: scope,
|
|
543
|
+
override
|
|
544
|
+
};
|
|
545
|
+
var val = el.mock(opts);
|
|
546
|
+
switch (type.className) {
|
|
547
|
+
case 'ArrayType':
|
|
548
|
+
return empty ? [] : [val];
|
|
549
|
+
case 'HashType':
|
|
550
|
+
return empty ? {} : {
|
|
551
|
+
a: val
|
|
552
|
+
};
|
|
553
|
+
case 'DelimArrayType':
|
|
554
|
+
return empty ? new DelimArray([]) : new DelimArray([val]);
|
|
555
|
+
case 'EnumType':
|
|
556
|
+
return type.values[0];
|
|
557
|
+
}
|
|
558
|
+
throw new Error("Don't know how to handle: ".concat(JSON.stringify(type)));
|
|
559
|
+
}
|
|
560
|
+
if (type.name) {
|
|
561
|
+
if (type.intrinsic) {
|
|
562
|
+
var data = mockData(this.name, type, undefined, empty);
|
|
563
|
+
return data.value;
|
|
564
|
+
}
|
|
565
|
+
return type.mock({
|
|
566
|
+
override,
|
|
567
|
+
empty
|
|
568
|
+
});
|
|
569
|
+
} else {
|
|
570
|
+
throw new Error('Cannot output a nameless type.');
|
|
571
|
+
}
|
|
572
|
+
}
|
|
310
573
|
}
|
|
311
574
|
export class Parameter extends SchemadSymbol {
|
|
312
575
|
constructor(param, type) {
|
|
@@ -692,7 +955,7 @@ export class Type {
|
|
|
692
955
|
var type = prop.type;
|
|
693
956
|
var w = type.intrinsic ? undefined : api.mayGetWriteableType(type);
|
|
694
957
|
if (w) {
|
|
695
|
-
var writeProp = _objectSpread(_objectSpread({}, prop), {
|
|
958
|
+
var writeProp = _objectSpread(_objectSpread({}, prop), {}, {
|
|
696
959
|
type: w
|
|
697
960
|
});
|
|
698
961
|
result.push(writeProp);
|
|
@@ -756,6 +1019,74 @@ export class Type {
|
|
|
756
1019
|
return prop.hasSpecialNeeds;
|
|
757
1020
|
});
|
|
758
1021
|
}
|
|
1022
|
+
mock() {
|
|
1023
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1024
|
+
var {
|
|
1025
|
+
fields,
|
|
1026
|
+
override,
|
|
1027
|
+
empty
|
|
1028
|
+
} = mockOptions(options);
|
|
1029
|
+
var isArray = this.className === 'ArrayType';
|
|
1030
|
+
var props = isArray ? this.elementType.properties : this.properties;
|
|
1031
|
+
if (typeof override !== 'string' && typeof override !== 'function') {
|
|
1032
|
+
for (var _key in override) {
|
|
1033
|
+
if (!(_key in props)) {
|
|
1034
|
+
delete override[_key];
|
|
1035
|
+
} else {
|
|
1036
|
+
var prop = props[_key];
|
|
1037
|
+
if (prop.type.intrinsic) {
|
|
1038
|
+
override[_key] = mockData(_key, prop.type, override[_key], empty).value;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
var keys = parseFields(fields);
|
|
1044
|
+
if (keys['*']) {
|
|
1045
|
+
var merge = {};
|
|
1046
|
+
Object.keys(props).forEach(k => merge[k] = k);
|
|
1047
|
+
keys = _objectSpread(_objectSpread({}, merge), keys);
|
|
1048
|
+
delete keys['*'];
|
|
1049
|
+
} else if (isEmpty(fields)) {
|
|
1050
|
+
for (var [_key2, _prop] of Object.entries(props)) {
|
|
1051
|
+
if (_prop.required) {
|
|
1052
|
+
keys[_key2] = _key2;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
var overKeys = typeof override === 'string' || typeof override === 'function';
|
|
1057
|
+
var result = {};
|
|
1058
|
+
Object.keys(keys).forEach(k => {
|
|
1059
|
+
var v = keys[k];
|
|
1060
|
+
var over = overKeys ? undefined : override[k];
|
|
1061
|
+
var p = props[k];
|
|
1062
|
+
var scope = v === k ? k : {
|
|
1063
|
+
[k]: v
|
|
1064
|
+
};
|
|
1065
|
+
if (!p) {
|
|
1066
|
+
throw new Error("No property named '".concat(k, "' in type ").concat(this.name));
|
|
1067
|
+
}
|
|
1068
|
+
var val = typeof override === 'function' ? p.mock({
|
|
1069
|
+
fields: scope,
|
|
1070
|
+
empty
|
|
1071
|
+
}) : p.mock({
|
|
1072
|
+
fields: scope,
|
|
1073
|
+
override: over,
|
|
1074
|
+
empty
|
|
1075
|
+
});
|
|
1076
|
+
if (val !== undefined) {
|
|
1077
|
+
result[k] = val;
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
if (typeof override !== 'string') {
|
|
1081
|
+
result = _objectSpread(_objectSpread({}, result), override);
|
|
1082
|
+
}
|
|
1083
|
+
return result;
|
|
1084
|
+
}
|
|
1085
|
+
mockType() {
|
|
1086
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1087
|
+
var result = this.mock(options);
|
|
1088
|
+
return result;
|
|
1089
|
+
}
|
|
759
1090
|
load(api) {
|
|
760
1091
|
Object.entries(this.schema.properties || {}).forEach(_ref7 => {
|
|
761
1092
|
var [propName, propSchema] = _ref7;
|
|
@@ -848,6 +1179,14 @@ export class ArrayType extends Type {
|
|
|
848
1179
|
get readOnly() {
|
|
849
1180
|
return this.elementType.readOnly;
|
|
850
1181
|
}
|
|
1182
|
+
mock() {
|
|
1183
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1184
|
+
var result = super.mock(options);
|
|
1185
|
+
if (Array.isArray(result)) {
|
|
1186
|
+
return result;
|
|
1187
|
+
}
|
|
1188
|
+
return [result];
|
|
1189
|
+
}
|
|
851
1190
|
}
|
|
852
1191
|
export class EnumType extends Type {
|
|
853
1192
|
constructor(elementType, schema, api, typeName, methodName) {
|
|
@@ -887,6 +1226,10 @@ export class EnumType extends Type {
|
|
|
887
1226
|
enums[hash] = this;
|
|
888
1227
|
return name;
|
|
889
1228
|
}
|
|
1229
|
+
mock() {
|
|
1230
|
+
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1231
|
+
return this.values[0];
|
|
1232
|
+
}
|
|
890
1233
|
searchString(criteria) {
|
|
891
1234
|
var result = super.searchString(criteria);
|
|
892
1235
|
if (criteria.has(SearchCriterion.property)) {
|
|
@@ -941,6 +1284,15 @@ export class IntrinsicType extends Type {
|
|
|
941
1284
|
this.customType = '';
|
|
942
1285
|
this.isString = IntrinsicType.stringTypes.includes(name);
|
|
943
1286
|
}
|
|
1287
|
+
mock() {
|
|
1288
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1289
|
+
var {
|
|
1290
|
+
override,
|
|
1291
|
+
empty
|
|
1292
|
+
} = mockOptions(options);
|
|
1293
|
+
if (this.isString && typeof override === 'string') return override;
|
|
1294
|
+
return mockData(this.name, this, undefined, empty).value;
|
|
1295
|
+
}
|
|
944
1296
|
get className() {
|
|
945
1297
|
return 'IntrinsicType';
|
|
946
1298
|
}
|
|
@@ -951,7 +1303,7 @@ export class IntrinsicType extends Type {
|
|
|
951
1303
|
return false;
|
|
952
1304
|
}
|
|
953
1305
|
}
|
|
954
|
-
_defineProperty(IntrinsicType, "stringTypes", ['string', 'uri', 'email', 'uuid', '
|
|
1306
|
+
_defineProperty(IntrinsicType, "stringTypes", ['string', 'uri', 'url', 'email', 'uuid', 'hostname', 'password', 'ipv4', 'ipv6', 'byte', 'binary']);
|
|
955
1307
|
export class RequestType extends Type {
|
|
956
1308
|
constructor(api, name, params) {
|
|
957
1309
|
var description = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
@@ -1000,6 +1352,14 @@ _defineProperty(WriteType, "readonlyProps", properties => {
|
|
|
1000
1352
|
});
|
|
1001
1353
|
return result;
|
|
1002
1354
|
});
|
|
1355
|
+
export var specToModel = spec => {
|
|
1356
|
+
if (typeof spec === 'string') {
|
|
1357
|
+
spec = JSON.parse(spec);
|
|
1358
|
+
}
|
|
1359
|
+
var json = upgradeSpecObject(spec);
|
|
1360
|
+
var obj = new OAS.OpenApiBuilder(json).getSpec();
|
|
1361
|
+
return new ApiModel(obj);
|
|
1362
|
+
};
|
|
1003
1363
|
export class ApiModel {
|
|
1004
1364
|
constructor(spec) {
|
|
1005
1365
|
this.spec = spec;
|
|
@@ -1009,7 +1369,7 @@ export class ApiModel {
|
|
|
1009
1369
|
_defineProperty(this, "types", {});
|
|
1010
1370
|
_defineProperty(this, "tags", {});
|
|
1011
1371
|
_defineProperty(this, "typeTags", {});
|
|
1012
|
-
['string', 'integer', 'int64', 'boolean', 'object', '
|
|
1372
|
+
['string', 'integer', 'int64', 'boolean', 'object', 'float', 'double', 'void', 'date', 'datetime', 'binary', 'byte', 'email', 'uuid', 'uri', 'url', 'hostname', 'password', 'ipv4', 'ipv6', 'any'].forEach(name => this.types[name] = new IntrinsicType(name));
|
|
1013
1373
|
this.load();
|
|
1014
1374
|
}
|
|
1015
1375
|
get version() {
|
|
@@ -1021,12 +1381,10 @@ export class ApiModel {
|
|
|
1021
1381
|
return ((_this$spec2 = this.spec) === null || _this$spec2 === void 0 ? void 0 : (_this$spec2$info = _this$spec2.info) === null || _this$spec2$info === void 0 ? void 0 : (_this$spec2$info$desc = _this$spec2$info.description) === null || _this$spec2$info$desc === void 0 ? void 0 : _this$spec2$info$desc.trim()) || '';
|
|
1022
1382
|
}
|
|
1023
1383
|
static fromString(specContent) {
|
|
1024
|
-
|
|
1025
|
-
return ApiModel.fromJson(json);
|
|
1384
|
+
return specToModel(specContent);
|
|
1026
1385
|
}
|
|
1027
1386
|
static fromJson(json) {
|
|
1028
|
-
|
|
1029
|
-
return new ApiModel(spec);
|
|
1387
|
+
return specToModel(json);
|
|
1030
1388
|
}
|
|
1031
1389
|
static isMethodSearch(criteria) {
|
|
1032
1390
|
return criteria.has(SearchCriterion.method) || criteria.has(SearchCriterion.argument) || criteria.has(SearchCriterion.response) || criteria.has(SearchCriterion.status) || criteria.has(SearchCriterion.activityType);
|
|
@@ -1099,9 +1457,9 @@ export class ApiModel {
|
|
|
1099
1457
|
if (!(path instanceof Array)) {
|
|
1100
1458
|
keys = path.split(splitter);
|
|
1101
1459
|
}
|
|
1102
|
-
for (var
|
|
1103
|
-
if (
|
|
1104
|
-
item = item[
|
|
1460
|
+
for (var _key3 of keys) {
|
|
1461
|
+
if (_key3 === '#') continue;
|
|
1462
|
+
item = item[_key3];
|
|
1105
1463
|
if (item == null) return null;
|
|
1106
1464
|
}
|
|
1107
1465
|
return item;
|
|
@@ -1123,7 +1481,7 @@ export class ApiModel {
|
|
|
1123
1481
|
return result;
|
|
1124
1482
|
};
|
|
1125
1483
|
if (typeof schema === 'string') {
|
|
1126
|
-
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.
|
|
1484
|
+
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.substring(schema.lastIndexOf('/') + 1)];
|
|
1127
1485
|
var deref = this.jsonPath(schema);
|
|
1128
1486
|
if (deref) {
|
|
1129
1487
|
var ref = this.jsonPath(['content', 'application/json', 'schema', '$ref'], deref);
|
|
@@ -1135,8 +1493,9 @@ export class ApiModel {
|
|
|
1135
1493
|
if (schema.type === 'integer' && schema.format === 'int64') {
|
|
1136
1494
|
return this.types.int64;
|
|
1137
1495
|
}
|
|
1138
|
-
if (schema.type === 'number'
|
|
1139
|
-
return this.types[schema.format];
|
|
1496
|
+
if (schema.type === 'number') {
|
|
1497
|
+
if (schema.format) return this.types[schema.format];
|
|
1498
|
+
return this.types.float;
|
|
1140
1499
|
}
|
|
1141
1500
|
if (schema.type === 'array' && schema.items) {
|
|
1142
1501
|
var resolved = this.resolveType(schema.items);
|
|
@@ -1263,8 +1622,8 @@ export class ApiModel {
|
|
|
1263
1622
|
sortList(list) {
|
|
1264
1623
|
var result = {};
|
|
1265
1624
|
var sortedKeys = Object.keys(list).sort(localeSort);
|
|
1266
|
-
for (var
|
|
1267
|
-
result[
|
|
1625
|
+
for (var _key4 of sortedKeys) {
|
|
1626
|
+
result[_key4] = list[_key4];
|
|
1268
1627
|
}
|
|
1269
1628
|
return result;
|
|
1270
1629
|
}
|
|
@@ -1379,7 +1738,7 @@ export class ApiModel {
|
|
|
1379
1738
|
if (!OAS.isReferenceObject(obj)) {
|
|
1380
1739
|
var req = obj;
|
|
1381
1740
|
if ('required' in req) {
|
|
1382
|
-
required = req.required;
|
|
1741
|
+
required = Boolean(req.required);
|
|
1383
1742
|
}
|
|
1384
1743
|
}
|
|
1385
1744
|
var typeSchema = {
|
|
@@ -1409,7 +1768,7 @@ export class ApiModel {
|
|
|
1409
1768
|
description: '',
|
|
1410
1769
|
location: strBody,
|
|
1411
1770
|
name: strBody,
|
|
1412
|
-
required
|
|
1771
|
+
required
|
|
1413
1772
|
}, type);
|
|
1414
1773
|
}
|
|
1415
1774
|
}
|