@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/sdkModels.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.typeRefs = exports.typeOfType = exports.titleCase = exports.tagTypes = exports.strWrite = exports.strRequest = exports.strBody = exports.setToCriteria = exports.safeName = exports.methodRefs = exports.mayQuote = exports.keyValues = exports.isSpecialName = exports.firstMethodRef = exports.firstCase = exports.describeParam = exports.criteriaToSet = exports.camelCase = exports.WriteType = exports.TypeOfType = exports.Type = exports.SearchCriterion = exports.SearchAll = exports.RequestType = exports.Property = exports.Parameter = exports.Method = exports.MetaType = exports.IntrinsicType = exports.HashType = exports.EnumType = exports.DelimArrayType = exports.ArrayType = exports.ApiModel = void 0;
|
|
6
|
+
exports.typeRefs = exports.typeOfType = exports.titleCase = exports.tagTypes = exports.strWrite = exports.strRequest = exports.strBody = exports.specToModel = exports.setToCriteria = exports.safeName = exports.parseFields = exports.methodRefs = exports.mayQuote = exports.keyValues = exports.isSpecialName = exports.firstMethodRef = exports.firstCase = exports.describeParam = exports.criteriaToSet = exports.camelCase = exports.WriteType = exports.TypeOfType = exports.Type = exports.SearchCriterion = exports.SearchAll = exports.RequestType = exports.Property = exports.Parameter = exports.Method = exports.MetaType = exports.IntrinsicType = exports.HashType = exports.EnumType = exports.DelimArrayType = exports.ArrayType = exports.ApiModel = void 0;
|
|
7
7
|
var OAS = _interopRequireWildcard(require("openapi3-ts"));
|
|
8
8
|
var _blueimpMd = _interopRequireDefault(require("blueimp-md5"));
|
|
9
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
9
10
|
var _sdkRtl = require("@looker/sdk-rtl");
|
|
11
|
+
var _specConverter = require("./specConverter");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -30,6 +32,74 @@ var TypeOfType = exports.TypeOfType = function (TypeOfType) {
|
|
|
30
32
|
TypeOfType[TypeOfType["Complex"] = 5] = "Complex";
|
|
31
33
|
return TypeOfType;
|
|
32
34
|
}({});
|
|
35
|
+
var parseFields = fields => {
|
|
36
|
+
function splitConsideringParentheses(segment) {
|
|
37
|
+
var parts = [];
|
|
38
|
+
var currentPart = '';
|
|
39
|
+
var openParentheses = 0;
|
|
40
|
+
var lastChar = '';
|
|
41
|
+
function charCheck(char) {
|
|
42
|
+
if (lastChar === char) {
|
|
43
|
+
if (char === '(' || char === ')' && openParentheses < 0) {
|
|
44
|
+
throw new Error("Unexpected '".concat(char, "' after '").concat(currentPart, "' parens:").concat(openParentheses));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (var char of segment) {
|
|
49
|
+
if (char === '(') {
|
|
50
|
+
openParentheses++;
|
|
51
|
+
charCheck(char);
|
|
52
|
+
} else if (char === ')') {
|
|
53
|
+
openParentheses--;
|
|
54
|
+
charCheck(char);
|
|
55
|
+
}
|
|
56
|
+
if (char === ',' && openParentheses === 0) {
|
|
57
|
+
parts.push(currentPart);
|
|
58
|
+
currentPart = '';
|
|
59
|
+
} else {
|
|
60
|
+
currentPart += char;
|
|
61
|
+
}
|
|
62
|
+
lastChar = char;
|
|
63
|
+
}
|
|
64
|
+
if (currentPart) {
|
|
65
|
+
parts.push(currentPart);
|
|
66
|
+
}
|
|
67
|
+
return parts;
|
|
68
|
+
}
|
|
69
|
+
function parseSegment(segment) {
|
|
70
|
+
var parts = splitConsideringParentheses(segment);
|
|
71
|
+
var result = {};
|
|
72
|
+
parts.forEach(part => {
|
|
73
|
+
var [key, nestedStr] = part.split(/\((.+)/);
|
|
74
|
+
key = key.trim();
|
|
75
|
+
if (nestedStr) {
|
|
76
|
+
nestedStr = nestedStr.slice(0, -1);
|
|
77
|
+
if (key in result) {
|
|
78
|
+
throw new Error("Duplicate '".concat(key, "' found"));
|
|
79
|
+
}
|
|
80
|
+
result[key] = parseSegment(nestedStr);
|
|
81
|
+
} else {
|
|
82
|
+
var p = part.trim();
|
|
83
|
+
if (p in result) {
|
|
84
|
+
throw new Error("Duplicate '".concat(key, "' found"));
|
|
85
|
+
}
|
|
86
|
+
if (p) result[p] = p;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
if (typeof fields === 'string') {
|
|
92
|
+
fields = fields.trim();
|
|
93
|
+
if (!fields) return {};
|
|
94
|
+
return parseSegment(fields);
|
|
95
|
+
} else if (Array.isArray(fields)) {
|
|
96
|
+
var result = {};
|
|
97
|
+
fields.forEach(f => result[f] = f);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
return fields;
|
|
101
|
+
};
|
|
102
|
+
exports.parseFields = parseFields;
|
|
33
103
|
var typeOfType = type => {
|
|
34
104
|
if (type.intrinsic) return TypeOfType.Intrinsic;
|
|
35
105
|
switch (type.className) {
|
|
@@ -69,13 +139,13 @@ exports.camelCase = camelCase;
|
|
|
69
139
|
var titleCase = value => {
|
|
70
140
|
if (!value) return '';
|
|
71
141
|
value = camelCase(value);
|
|
72
|
-
return value[0].toLocaleUpperCase() + value.
|
|
142
|
+
return value[0].toLocaleUpperCase() + value.substring(1);
|
|
73
143
|
};
|
|
74
144
|
exports.titleCase = titleCase;
|
|
75
145
|
var firstCase = value => {
|
|
76
146
|
if (!value) return '';
|
|
77
147
|
value = camelCase(value);
|
|
78
|
-
return value[0].toLocaleUpperCase() + value.
|
|
148
|
+
return value[0].toLocaleUpperCase() + value.substring(1).toLocaleLowerCase();
|
|
79
149
|
};
|
|
80
150
|
exports.firstCase = firstCase;
|
|
81
151
|
var searchIt = value => value ? value + '\t' : '';
|
|
@@ -296,6 +366,150 @@ class SchemadSymbol extends _Symbol {
|
|
|
296
366
|
return this.deprecated ? 'deprecated' : '';
|
|
297
367
|
}
|
|
298
368
|
}
|
|
369
|
+
var mockData = function mockData(propertyName, type, override) {
|
|
370
|
+
var _dataMocks$type$name;
|
|
371
|
+
var empty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
372
|
+
var over = override !== undefined;
|
|
373
|
+
var stringer = mocked => {
|
|
374
|
+
if (over) {
|
|
375
|
+
return String(override);
|
|
376
|
+
}
|
|
377
|
+
if (empty) {
|
|
378
|
+
return '';
|
|
379
|
+
}
|
|
380
|
+
return mocked;
|
|
381
|
+
};
|
|
382
|
+
var inter = mocked => {
|
|
383
|
+
if (over) {
|
|
384
|
+
return parseInt(override, 10);
|
|
385
|
+
}
|
|
386
|
+
if (empty) {
|
|
387
|
+
return 0;
|
|
388
|
+
}
|
|
389
|
+
return mocked;
|
|
390
|
+
};
|
|
391
|
+
var floater = mocked => {
|
|
392
|
+
if (over) {
|
|
393
|
+
return parseFloat(override);
|
|
394
|
+
}
|
|
395
|
+
if (empty) {
|
|
396
|
+
return 0.0;
|
|
397
|
+
}
|
|
398
|
+
return mocked;
|
|
399
|
+
};
|
|
400
|
+
var dater = mocked => {
|
|
401
|
+
if (over) {
|
|
402
|
+
return new Date(override);
|
|
403
|
+
}
|
|
404
|
+
if (empty) {
|
|
405
|
+
return new Date(1970, 0, 1);
|
|
406
|
+
}
|
|
407
|
+
return mocked;
|
|
408
|
+
};
|
|
409
|
+
var booler = mocked => {
|
|
410
|
+
if (over) {
|
|
411
|
+
return Boolean(override);
|
|
412
|
+
}
|
|
413
|
+
if (empty) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
return mocked;
|
|
417
|
+
};
|
|
418
|
+
var anyer = mocked => {
|
|
419
|
+
if (over) {
|
|
420
|
+
return override;
|
|
421
|
+
}
|
|
422
|
+
if (empty) {
|
|
423
|
+
return {};
|
|
424
|
+
}
|
|
425
|
+
return mocked;
|
|
426
|
+
};
|
|
427
|
+
var dataMocks = {
|
|
428
|
+
any: {
|
|
429
|
+
value: anyer({
|
|
430
|
+
a: 1,
|
|
431
|
+
b: 'two'
|
|
432
|
+
})
|
|
433
|
+
},
|
|
434
|
+
boolean: {
|
|
435
|
+
value: booler(true)
|
|
436
|
+
},
|
|
437
|
+
byte: {
|
|
438
|
+
value: stringer('A')
|
|
439
|
+
},
|
|
440
|
+
binary: {
|
|
441
|
+
value: stringer('01')
|
|
442
|
+
},
|
|
443
|
+
date: {
|
|
444
|
+
value: dater(new Date(2024, 0, 5))
|
|
445
|
+
},
|
|
446
|
+
datetime: {
|
|
447
|
+
value: dater(new Date(2024, 0, 5, 1))
|
|
448
|
+
},
|
|
449
|
+
double: {
|
|
450
|
+
value: floater(2.2)
|
|
451
|
+
},
|
|
452
|
+
float: {
|
|
453
|
+
value: floater(1.1)
|
|
454
|
+
},
|
|
455
|
+
int32: {
|
|
456
|
+
value: inter(32)
|
|
457
|
+
},
|
|
458
|
+
int64: {
|
|
459
|
+
value: inter(64)
|
|
460
|
+
},
|
|
461
|
+
integer: {
|
|
462
|
+
value: inter(1)
|
|
463
|
+
},
|
|
464
|
+
number: {
|
|
465
|
+
value: inter(2)
|
|
466
|
+
},
|
|
467
|
+
object: {
|
|
468
|
+
value: anyer({
|
|
469
|
+
[propertyName]: 1
|
|
470
|
+
})
|
|
471
|
+
},
|
|
472
|
+
password: {
|
|
473
|
+
value: stringer('*')
|
|
474
|
+
},
|
|
475
|
+
string: {
|
|
476
|
+
value: stringer(propertyName)
|
|
477
|
+
},
|
|
478
|
+
uri: {
|
|
479
|
+
value: stringer("urn:".concat(propertyName))
|
|
480
|
+
},
|
|
481
|
+
url: {
|
|
482
|
+
value: stringer("https://".concat(propertyName, ".mock"))
|
|
483
|
+
},
|
|
484
|
+
email: {
|
|
485
|
+
value: stringer("".concat(propertyName, "@example.com"))
|
|
486
|
+
},
|
|
487
|
+
uuid: {
|
|
488
|
+
value: stringer("uuid-".concat(propertyName))
|
|
489
|
+
},
|
|
490
|
+
hostname: {
|
|
491
|
+
value: stringer("https://".concat(propertyName))
|
|
492
|
+
},
|
|
493
|
+
ipv4: {
|
|
494
|
+
value: stringer('127.0.0.1')
|
|
495
|
+
},
|
|
496
|
+
ipv6: {
|
|
497
|
+
value: stringer('::1')
|
|
498
|
+
},
|
|
499
|
+
void: {
|
|
500
|
+
value: over ? override : null
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
return (_dataMocks$type$name = dataMocks[type.name]) !== null && _dataMocks$type$name !== void 0 ? _dataMocks$type$name : override;
|
|
504
|
+
};
|
|
505
|
+
var mockOptions = options => {
|
|
506
|
+
var _options$override, _options$empty;
|
|
507
|
+
return {
|
|
508
|
+
fields: options !== null && options !== void 0 && options.fields ? options === null || options === void 0 ? void 0 : options.fields : '',
|
|
509
|
+
override: (_options$override = options === null || options === void 0 ? void 0 : options.override) !== null && _options$override !== void 0 ? _options$override : {},
|
|
510
|
+
empty: (_options$empty = options === null || options === void 0 ? void 0 : options.empty) !== null && _options$empty !== void 0 ? _options$empty : false
|
|
511
|
+
};
|
|
512
|
+
};
|
|
299
513
|
class Property extends SchemadSymbol {
|
|
300
514
|
constructor(name, type, schema) {
|
|
301
515
|
var _schema$required;
|
|
@@ -306,7 +520,7 @@ class Property extends SchemadSymbol {
|
|
|
306
520
|
_defineProperty(this, "nullable", false);
|
|
307
521
|
_defineProperty(this, "readOnly", false);
|
|
308
522
|
_defineProperty(this, "writeOnly", false);
|
|
309
|
-
this.required =
|
|
523
|
+
this.required = Boolean(required.includes(name) || ((_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(name)));
|
|
310
524
|
this.nullable = this.schema.nullable || this.schema['x-looker-nullable'] || false;
|
|
311
525
|
this.readOnly = this.schema.readOnly || false;
|
|
312
526
|
this.writeOnly = this.schema.writeOnly || false;
|
|
@@ -329,6 +543,56 @@ class Property extends SchemadSymbol {
|
|
|
329
543
|
search(rx, criteria) {
|
|
330
544
|
return rx.test(this.searchString(criteria)) || this.type.search(rx, criteria);
|
|
331
545
|
}
|
|
546
|
+
mock() {
|
|
547
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
548
|
+
var {
|
|
549
|
+
fields,
|
|
550
|
+
override,
|
|
551
|
+
empty
|
|
552
|
+
} = mockOptions(options);
|
|
553
|
+
if ((0, _isEmpty.default)(fields) && !this.required) return undefined;
|
|
554
|
+
var keys = parseFields(fields);
|
|
555
|
+
if (!(0, _isEmpty.default)(fields) && !(this.name in keys)) return undefined;
|
|
556
|
+
var type = this.type;
|
|
557
|
+
if (type.elementType) {
|
|
558
|
+
var el = type.elementType;
|
|
559
|
+
var over = el.intrinsic && el.isString ? this.name : override;
|
|
560
|
+
var scope = typeof keys[this.name] === 'string' ? undefined : keys[this.name];
|
|
561
|
+
var opts = el.intrinsic ? {
|
|
562
|
+
fields: el.name,
|
|
563
|
+
override: over
|
|
564
|
+
} : {
|
|
565
|
+
fields: scope,
|
|
566
|
+
override
|
|
567
|
+
};
|
|
568
|
+
var val = el.mock(opts);
|
|
569
|
+
switch (type.className) {
|
|
570
|
+
case 'ArrayType':
|
|
571
|
+
return empty ? [] : [val];
|
|
572
|
+
case 'HashType':
|
|
573
|
+
return empty ? {} : {
|
|
574
|
+
a: val
|
|
575
|
+
};
|
|
576
|
+
case 'DelimArrayType':
|
|
577
|
+
return empty ? new _sdkRtl.DelimArray([]) : new _sdkRtl.DelimArray([val]);
|
|
578
|
+
case 'EnumType':
|
|
579
|
+
return type.values[0];
|
|
580
|
+
}
|
|
581
|
+
throw new Error("Don't know how to handle: ".concat(JSON.stringify(type)));
|
|
582
|
+
}
|
|
583
|
+
if (type.name) {
|
|
584
|
+
if (type.intrinsic) {
|
|
585
|
+
var data = mockData(this.name, type, undefined, empty);
|
|
586
|
+
return data.value;
|
|
587
|
+
}
|
|
588
|
+
return type.mock({
|
|
589
|
+
override,
|
|
590
|
+
empty
|
|
591
|
+
});
|
|
592
|
+
} else {
|
|
593
|
+
throw new Error('Cannot output a nameless type.');
|
|
594
|
+
}
|
|
595
|
+
}
|
|
332
596
|
}
|
|
333
597
|
exports.Property = Property;
|
|
334
598
|
class Parameter extends SchemadSymbol {
|
|
@@ -717,7 +981,7 @@ class Type {
|
|
|
717
981
|
var type = prop.type;
|
|
718
982
|
var w = type.intrinsic ? undefined : api.mayGetWriteableType(type);
|
|
719
983
|
if (w) {
|
|
720
|
-
var writeProp = _objectSpread(_objectSpread({}, prop), {
|
|
984
|
+
var writeProp = _objectSpread(_objectSpread({}, prop), {}, {
|
|
721
985
|
type: w
|
|
722
986
|
});
|
|
723
987
|
result.push(writeProp);
|
|
@@ -781,6 +1045,74 @@ class Type {
|
|
|
781
1045
|
return prop.hasSpecialNeeds;
|
|
782
1046
|
});
|
|
783
1047
|
}
|
|
1048
|
+
mock() {
|
|
1049
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1050
|
+
var {
|
|
1051
|
+
fields,
|
|
1052
|
+
override,
|
|
1053
|
+
empty
|
|
1054
|
+
} = mockOptions(options);
|
|
1055
|
+
var isArray = this.className === 'ArrayType';
|
|
1056
|
+
var props = isArray ? this.elementType.properties : this.properties;
|
|
1057
|
+
if (typeof override !== 'string' && typeof override !== 'function') {
|
|
1058
|
+
for (var _key in override) {
|
|
1059
|
+
if (!(_key in props)) {
|
|
1060
|
+
delete override[_key];
|
|
1061
|
+
} else {
|
|
1062
|
+
var prop = props[_key];
|
|
1063
|
+
if (prop.type.intrinsic) {
|
|
1064
|
+
override[_key] = mockData(_key, prop.type, override[_key], empty).value;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
var keys = parseFields(fields);
|
|
1070
|
+
if (keys['*']) {
|
|
1071
|
+
var merge = {};
|
|
1072
|
+
Object.keys(props).forEach(k => merge[k] = k);
|
|
1073
|
+
keys = _objectSpread(_objectSpread({}, merge), keys);
|
|
1074
|
+
delete keys['*'];
|
|
1075
|
+
} else if ((0, _isEmpty.default)(fields)) {
|
|
1076
|
+
for (var [_key2, _prop] of Object.entries(props)) {
|
|
1077
|
+
if (_prop.required) {
|
|
1078
|
+
keys[_key2] = _key2;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
var overKeys = typeof override === 'string' || typeof override === 'function';
|
|
1083
|
+
var result = {};
|
|
1084
|
+
Object.keys(keys).forEach(k => {
|
|
1085
|
+
var v = keys[k];
|
|
1086
|
+
var over = overKeys ? undefined : override[k];
|
|
1087
|
+
var p = props[k];
|
|
1088
|
+
var scope = v === k ? k : {
|
|
1089
|
+
[k]: v
|
|
1090
|
+
};
|
|
1091
|
+
if (!p) {
|
|
1092
|
+
throw new Error("No property named '".concat(k, "' in type ").concat(this.name));
|
|
1093
|
+
}
|
|
1094
|
+
var val = typeof override === 'function' ? p.mock({
|
|
1095
|
+
fields: scope,
|
|
1096
|
+
empty
|
|
1097
|
+
}) : p.mock({
|
|
1098
|
+
fields: scope,
|
|
1099
|
+
override: over,
|
|
1100
|
+
empty
|
|
1101
|
+
});
|
|
1102
|
+
if (val !== undefined) {
|
|
1103
|
+
result[k] = val;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
if (typeof override !== 'string') {
|
|
1107
|
+
result = _objectSpread(_objectSpread({}, result), override);
|
|
1108
|
+
}
|
|
1109
|
+
return result;
|
|
1110
|
+
}
|
|
1111
|
+
mockType() {
|
|
1112
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1113
|
+
var result = this.mock(options);
|
|
1114
|
+
return result;
|
|
1115
|
+
}
|
|
784
1116
|
load(api) {
|
|
785
1117
|
Object.entries(this.schema.properties || {}).forEach(_ref7 => {
|
|
786
1118
|
var [propName, propSchema] = _ref7;
|
|
@@ -874,6 +1206,14 @@ class ArrayType extends Type {
|
|
|
874
1206
|
get readOnly() {
|
|
875
1207
|
return this.elementType.readOnly;
|
|
876
1208
|
}
|
|
1209
|
+
mock() {
|
|
1210
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1211
|
+
var result = super.mock(options);
|
|
1212
|
+
if (Array.isArray(result)) {
|
|
1213
|
+
return result;
|
|
1214
|
+
}
|
|
1215
|
+
return [result];
|
|
1216
|
+
}
|
|
877
1217
|
}
|
|
878
1218
|
exports.ArrayType = ArrayType;
|
|
879
1219
|
class EnumType extends Type {
|
|
@@ -914,6 +1254,10 @@ class EnumType extends Type {
|
|
|
914
1254
|
enums[hash] = this;
|
|
915
1255
|
return name;
|
|
916
1256
|
}
|
|
1257
|
+
mock() {
|
|
1258
|
+
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1259
|
+
return this.values[0];
|
|
1260
|
+
}
|
|
917
1261
|
searchString(criteria) {
|
|
918
1262
|
var result = super.searchString(criteria);
|
|
919
1263
|
if (criteria.has(SearchCriterion.property)) {
|
|
@@ -971,6 +1315,15 @@ class IntrinsicType extends Type {
|
|
|
971
1315
|
this.customType = '';
|
|
972
1316
|
this.isString = IntrinsicType.stringTypes.includes(name);
|
|
973
1317
|
}
|
|
1318
|
+
mock() {
|
|
1319
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1320
|
+
var {
|
|
1321
|
+
override,
|
|
1322
|
+
empty
|
|
1323
|
+
} = mockOptions(options);
|
|
1324
|
+
if (this.isString && typeof override === 'string') return override;
|
|
1325
|
+
return mockData(this.name, this, undefined, empty).value;
|
|
1326
|
+
}
|
|
974
1327
|
get className() {
|
|
975
1328
|
return 'IntrinsicType';
|
|
976
1329
|
}
|
|
@@ -982,7 +1335,7 @@ class IntrinsicType extends Type {
|
|
|
982
1335
|
}
|
|
983
1336
|
}
|
|
984
1337
|
exports.IntrinsicType = IntrinsicType;
|
|
985
|
-
_defineProperty(IntrinsicType, "stringTypes", ['string', 'uri', 'email', 'uuid', '
|
|
1338
|
+
_defineProperty(IntrinsicType, "stringTypes", ['string', 'uri', 'url', 'email', 'uuid', 'hostname', 'password', 'ipv4', 'ipv6', 'byte', 'binary']);
|
|
986
1339
|
class RequestType extends Type {
|
|
987
1340
|
constructor(api, name, params) {
|
|
988
1341
|
var description = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
@@ -1033,6 +1386,15 @@ _defineProperty(WriteType, "readonlyProps", properties => {
|
|
|
1033
1386
|
});
|
|
1034
1387
|
return result;
|
|
1035
1388
|
});
|
|
1389
|
+
var specToModel = spec => {
|
|
1390
|
+
if (typeof spec === 'string') {
|
|
1391
|
+
spec = JSON.parse(spec);
|
|
1392
|
+
}
|
|
1393
|
+
var json = (0, _specConverter.upgradeSpecObject)(spec);
|
|
1394
|
+
var obj = new OAS.OpenApiBuilder(json).getSpec();
|
|
1395
|
+
return new ApiModel(obj);
|
|
1396
|
+
};
|
|
1397
|
+
exports.specToModel = specToModel;
|
|
1036
1398
|
class ApiModel {
|
|
1037
1399
|
constructor(spec) {
|
|
1038
1400
|
this.spec = spec;
|
|
@@ -1042,7 +1404,7 @@ class ApiModel {
|
|
|
1042
1404
|
_defineProperty(this, "types", {});
|
|
1043
1405
|
_defineProperty(this, "tags", {});
|
|
1044
1406
|
_defineProperty(this, "typeTags", {});
|
|
1045
|
-
['string', 'integer', 'int64', 'boolean', 'object', '
|
|
1407
|
+
['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));
|
|
1046
1408
|
this.load();
|
|
1047
1409
|
}
|
|
1048
1410
|
get version() {
|
|
@@ -1054,12 +1416,10 @@ class ApiModel {
|
|
|
1054
1416
|
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()) || '';
|
|
1055
1417
|
}
|
|
1056
1418
|
static fromString(specContent) {
|
|
1057
|
-
|
|
1058
|
-
return ApiModel.fromJson(json);
|
|
1419
|
+
return specToModel(specContent);
|
|
1059
1420
|
}
|
|
1060
1421
|
static fromJson(json) {
|
|
1061
|
-
|
|
1062
|
-
return new ApiModel(spec);
|
|
1422
|
+
return specToModel(json);
|
|
1063
1423
|
}
|
|
1064
1424
|
static isMethodSearch(criteria) {
|
|
1065
1425
|
return criteria.has(SearchCriterion.method) || criteria.has(SearchCriterion.argument) || criteria.has(SearchCriterion.response) || criteria.has(SearchCriterion.status) || criteria.has(SearchCriterion.activityType);
|
|
@@ -1132,9 +1492,9 @@ class ApiModel {
|
|
|
1132
1492
|
if (!(path instanceof Array)) {
|
|
1133
1493
|
keys = path.split(splitter);
|
|
1134
1494
|
}
|
|
1135
|
-
for (var
|
|
1136
|
-
if (
|
|
1137
|
-
item = item[
|
|
1495
|
+
for (var _key3 of keys) {
|
|
1496
|
+
if (_key3 === '#') continue;
|
|
1497
|
+
item = item[_key3];
|
|
1138
1498
|
if (item == null) return null;
|
|
1139
1499
|
}
|
|
1140
1500
|
return item;
|
|
@@ -1156,7 +1516,7 @@ class ApiModel {
|
|
|
1156
1516
|
return result;
|
|
1157
1517
|
};
|
|
1158
1518
|
if (typeof schema === 'string') {
|
|
1159
|
-
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.
|
|
1519
|
+
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.substring(schema.lastIndexOf('/') + 1)];
|
|
1160
1520
|
var deref = this.jsonPath(schema);
|
|
1161
1521
|
if (deref) {
|
|
1162
1522
|
var ref = this.jsonPath(['content', 'application/json', 'schema', '$ref'], deref);
|
|
@@ -1168,8 +1528,9 @@ class ApiModel {
|
|
|
1168
1528
|
if (schema.type === 'integer' && schema.format === 'int64') {
|
|
1169
1529
|
return this.types.int64;
|
|
1170
1530
|
}
|
|
1171
|
-
if (schema.type === 'number'
|
|
1172
|
-
return this.types[schema.format];
|
|
1531
|
+
if (schema.type === 'number') {
|
|
1532
|
+
if (schema.format) return this.types[schema.format];
|
|
1533
|
+
return this.types.float;
|
|
1173
1534
|
}
|
|
1174
1535
|
if (schema.type === 'array' && schema.items) {
|
|
1175
1536
|
var resolved = this.resolveType(schema.items);
|
|
@@ -1296,8 +1657,8 @@ class ApiModel {
|
|
|
1296
1657
|
sortList(list) {
|
|
1297
1658
|
var result = {};
|
|
1298
1659
|
var sortedKeys = Object.keys(list).sort(localeSort);
|
|
1299
|
-
for (var
|
|
1300
|
-
result[
|
|
1660
|
+
for (var _key4 of sortedKeys) {
|
|
1661
|
+
result[_key4] = list[_key4];
|
|
1301
1662
|
}
|
|
1302
1663
|
return result;
|
|
1303
1664
|
}
|
|
@@ -1412,7 +1773,7 @@ class ApiModel {
|
|
|
1412
1773
|
if (!OAS.isReferenceObject(obj)) {
|
|
1413
1774
|
var req = obj;
|
|
1414
1775
|
if ('required' in req) {
|
|
1415
|
-
required = req.required;
|
|
1776
|
+
required = Boolean(req.required);
|
|
1416
1777
|
}
|
|
1417
1778
|
}
|
|
1418
1779
|
var typeSchema = {
|
|
@@ -1442,7 +1803,7 @@ class ApiModel {
|
|
|
1442
1803
|
description: '',
|
|
1443
1804
|
location: strBody,
|
|
1444
1805
|
name: strBody,
|
|
1445
|
-
required
|
|
1806
|
+
required
|
|
1446
1807
|
}, type);
|
|
1447
1808
|
}
|
|
1448
1809
|
}
|