@looker/sdk-codegen 21.8.2 → 21.9.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/CHANGELOG.md +153 -167
- package/README.md +0 -1
- package/lib/codeGen.d.ts +15 -1
- package/lib/codeGen.js +23 -6
- package/lib/codeGen.js.map +1 -1
- package/lib/codeGenerators.d.ts +3 -3
- package/lib/codeGenerators.js +2 -4
- package/lib/codeGenerators.js.map +1 -1
- package/lib/csharp.gen.d.ts +1 -1
- package/lib/csharp.gen.js +2 -2
- package/lib/csharp.gen.js.map +1 -1
- package/lib/declarationInfo.d.ts +3 -3
- package/lib/declarationInfo.js +1 -2
- package/lib/declarationInfo.js.map +1 -1
- package/lib/esm/codeGen.js +33 -23
- package/lib/esm/codeGen.js.map +1 -1
- package/lib/esm/codeGenerators.js +17 -28
- package/lib/esm/codeGenerators.js.map +1 -1
- package/lib/esm/csharp.gen.js +11 -18
- package/lib/esm/csharp.gen.js.map +1 -1
- package/lib/esm/declarationInfo.js +3 -10
- package/lib/esm/declarationInfo.js.map +1 -1
- package/lib/esm/exampleInfo.js +9 -24
- package/lib/esm/exampleInfo.js.map +1 -1
- package/lib/esm/go.gen.js +11 -18
- package/lib/esm/go.gen.js.map +1 -1
- package/lib/esm/index.js +13 -148
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/kotlin.gen.js +11 -18
- package/lib/esm/kotlin.gen.js.map +1 -1
- package/lib/esm/pseudo.gen.js +6 -13
- package/lib/esm/pseudo.gen.js.map +1 -1
- package/lib/esm/python.gen.js +13 -20
- package/lib/esm/python.gen.js.map +1 -1
- package/lib/esm/sdkModels.js +431 -116
- package/lib/esm/sdkModels.js.map +1 -1
- package/lib/esm/specConverter.js +31 -59
- package/lib/esm/specConverter.js.map +1 -1
- package/lib/esm/specDiff.js +19 -36
- package/lib/esm/specDiff.js.map +1 -1
- package/lib/esm/swift.gen.js +17 -24
- package/lib/esm/swift.gen.js.map +1 -1
- package/lib/esm/typescript.gen.js +168 -31
- package/lib/esm/typescript.gen.js.map +1 -1
- package/lib/exampleInfo.d.ts +8 -20
- package/lib/exampleInfo.js +1 -2
- package/lib/exampleInfo.js.map +1 -1
- package/lib/go.gen.js +3 -3
- package/lib/go.gen.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/kotlin.gen.d.ts +1 -1
- package/lib/kotlin.gen.js +2 -2
- package/lib/kotlin.gen.js.map +1 -1
- package/lib/pseudo.gen.js +2 -2
- package/lib/pseudo.gen.js.map +1 -1
- package/lib/python.gen.js +4 -4
- package/lib/python.gen.js.map +1 -1
- package/lib/sdkModels.d.ts +33 -13
- package/lib/sdkModels.js +397 -46
- package/lib/sdkModels.js.map +1 -1
- package/lib/specConverter.d.ts +9 -12
- package/lib/specConverter.js +14 -22
- package/lib/specConverter.js.map +1 -1
- package/lib/specDiff.d.ts +4 -4
- package/lib/specDiff.js +6 -8
- package/lib/specDiff.js.map +1 -1
- package/lib/swift.gen.js +2 -2
- package/lib/swift.gen.js.map +1 -1
- package/lib/typescript.gen.d.ts +13 -0
- package/lib/typescript.gen.js +157 -13
- package/lib/typescript.gen.js.map +1 -1
- package/package.json +8 -7
- package/lib/esm/testUtils/index.js +0 -17
- package/lib/esm/testUtils/index.js.map +0 -1
- package/lib/esm/testUtils/testUtils.js +0 -66
- 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 -66
- package/lib/testUtils/testUtils.js.map +0 -1
package/lib/esm/sdkModels.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
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;
|
|
7
|
-
var OAS = _interopRequireWildcard(require("openapi3-ts"));
|
|
8
|
-
var _blueimpMd = _interopRequireDefault(require("blueimp-md5"));
|
|
9
|
-
var _sdkRtl = require("@looker/sdk-rtl");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
-
function _toPropertyKey(
|
|
17
|
-
function _toPrimitive(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
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
|
+
import * as OAS from 'openapi3-ts';
|
|
7
|
+
import md5 from 'blueimp-md5';
|
|
8
|
+
import isEmpty from 'lodash/isEmpty';
|
|
9
|
+
import { DelimArray, ResponseMode, StatusCode, responseMode } from '@looker/sdk-rtl';
|
|
10
|
+
import { upgradeSpecObject } from './specConverter';
|
|
11
|
+
export var strBody = 'body';
|
|
12
|
+
export var strRequest = 'Request';
|
|
13
|
+
export var strWrite = 'Write';
|
|
24
14
|
var lookerValuesTag = 'x-looker-values';
|
|
25
15
|
var enumTag = 'enum';
|
|
26
16
|
var simpleName = /^[a-z_][a-z_\d]*(\[])?$/im;
|
|
27
|
-
var TypeOfType = function (TypeOfType) {
|
|
17
|
+
export var TypeOfType = function (TypeOfType) {
|
|
28
18
|
TypeOfType[TypeOfType["Intrinsic"] = 0] = "Intrinsic";
|
|
29
19
|
TypeOfType[TypeOfType["Array"] = 1] = "Array";
|
|
30
20
|
TypeOfType[TypeOfType["Hash"] = 2] = "Hash";
|
|
@@ -33,8 +23,74 @@ var TypeOfType = function (TypeOfType) {
|
|
|
33
23
|
TypeOfType[TypeOfType["Complex"] = 5] = "Complex";
|
|
34
24
|
return TypeOfType;
|
|
35
25
|
}({});
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
};
|
|
93
|
+
export var typeOfType = type => {
|
|
38
94
|
if (type.intrinsic) return TypeOfType.Intrinsic;
|
|
39
95
|
switch (type.className) {
|
|
40
96
|
case 'ArrayType':
|
|
@@ -51,40 +107,34 @@ var typeOfType = type => {
|
|
|
51
107
|
}
|
|
52
108
|
}
|
|
53
109
|
};
|
|
54
|
-
|
|
55
|
-
var isSpecialName = name => {
|
|
110
|
+
export var isSpecialName = name => {
|
|
56
111
|
if (!name) return false;
|
|
57
112
|
var result = simpleName.test(name);
|
|
58
113
|
return !result;
|
|
59
114
|
};
|
|
60
|
-
|
|
61
|
-
var safeName = value => {
|
|
115
|
+
export var safeName = value => {
|
|
62
116
|
if (!value) return '';
|
|
63
117
|
return value.replace(/([-_ ]+)/g, '_');
|
|
64
118
|
};
|
|
65
|
-
|
|
66
|
-
var camelCase = value => {
|
|
119
|
+
export var camelCase = value => {
|
|
67
120
|
if (!value) return '';
|
|
68
121
|
return value.replace(/(([-_ ]+)[a-z])|([-_ ]+)/gi, $1 => {
|
|
69
122
|
return $1.toLocaleUpperCase().replace(/([-_ ]+)/gi, '');
|
|
70
123
|
});
|
|
71
124
|
};
|
|
72
|
-
|
|
73
|
-
var titleCase = value => {
|
|
125
|
+
export var titleCase = value => {
|
|
74
126
|
if (!value) return '';
|
|
75
127
|
value = camelCase(value);
|
|
76
|
-
return value[0].toLocaleUpperCase() + value.
|
|
128
|
+
return value[0].toLocaleUpperCase() + value.substring(1);
|
|
77
129
|
};
|
|
78
|
-
|
|
79
|
-
var firstCase = value => {
|
|
130
|
+
export var firstCase = value => {
|
|
80
131
|
if (!value) return '';
|
|
81
132
|
value = camelCase(value);
|
|
82
|
-
return value[0].toLocaleUpperCase() + value.
|
|
133
|
+
return value[0].toLocaleUpperCase() + value.substring(1).toLocaleLowerCase();
|
|
83
134
|
};
|
|
84
|
-
exports.firstCase = firstCase;
|
|
85
135
|
var searchIt = value => value ? value + '\t' : '';
|
|
86
136
|
var localeSort = (a, b) => a.localeCompare(b);
|
|
87
|
-
var describeParam = param => {
|
|
137
|
+
export var describeParam = param => {
|
|
88
138
|
var _param$type;
|
|
89
139
|
var desc = param.description || ((_param$type = param.type) === null || _param$type === void 0 ? void 0 : _param$type.description);
|
|
90
140
|
if (param.deprecated) {
|
|
@@ -94,20 +144,17 @@ var describeParam = param => {
|
|
|
94
144
|
}
|
|
95
145
|
return desc;
|
|
96
146
|
};
|
|
97
|
-
|
|
98
|
-
var keyValues = list => {
|
|
147
|
+
export var keyValues = list => {
|
|
99
148
|
if (!list) return [];
|
|
100
149
|
return Array.from(list.values()).sort();
|
|
101
150
|
};
|
|
102
|
-
|
|
103
|
-
var mayQuote = function mayQuote(value) {
|
|
151
|
+
export var mayQuote = function mayQuote(value) {
|
|
104
152
|
var quoteChar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "'";
|
|
105
153
|
var str = value.toString();
|
|
106
154
|
if (!isSpecialName(str)) return str;
|
|
107
155
|
return "".concat(quoteChar).concat(str).concat(quoteChar);
|
|
108
156
|
};
|
|
109
|
-
|
|
110
|
-
var methodRefs = (api, refs) => {
|
|
157
|
+
export var methodRefs = (api, refs) => {
|
|
111
158
|
var keys = keyValues(refs);
|
|
112
159
|
var result = [];
|
|
113
160
|
keys.forEach(k => {
|
|
@@ -117,8 +164,7 @@ var methodRefs = (api, refs) => {
|
|
|
117
164
|
});
|
|
118
165
|
return result;
|
|
119
166
|
};
|
|
120
|
-
|
|
121
|
-
var typeRefs = (api, refs) => {
|
|
167
|
+
export var typeRefs = (api, refs) => {
|
|
122
168
|
var keys = keyValues(refs);
|
|
123
169
|
var result = [];
|
|
124
170
|
keys.forEach(k => {
|
|
@@ -129,8 +175,7 @@ var typeRefs = (api, refs) => {
|
|
|
129
175
|
});
|
|
130
176
|
return result;
|
|
131
177
|
};
|
|
132
|
-
|
|
133
|
-
var firstMethodRef = function firstMethodRef(api, type) {
|
|
178
|
+
export var firstMethodRef = function firstMethodRef(api, type) {
|
|
134
179
|
var stack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
|
|
135
180
|
stack.add(type.name);
|
|
136
181
|
var method = methodRefs(api, type.methodRefs)[0];
|
|
@@ -145,7 +190,6 @@ var firstMethodRef = function firstMethodRef(api, type) {
|
|
|
145
190
|
}
|
|
146
191
|
return method;
|
|
147
192
|
};
|
|
148
|
-
exports.firstMethodRef = firstMethodRef;
|
|
149
193
|
var anyWriter = function anyWriter(api, type) {
|
|
150
194
|
var stack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
|
|
151
195
|
var result;
|
|
@@ -171,7 +215,7 @@ var anyWriter = function anyWriter(api, type) {
|
|
|
171
215
|
}
|
|
172
216
|
return result;
|
|
173
217
|
};
|
|
174
|
-
var SearchCriterion = function (SearchCriterion) {
|
|
218
|
+
export var SearchCriterion = function (SearchCriterion) {
|
|
175
219
|
SearchCriterion[SearchCriterion["method"] = 0] = "method";
|
|
176
220
|
SearchCriterion[SearchCriterion["type"] = 1] = "type";
|
|
177
221
|
SearchCriterion[SearchCriterion["name"] = 2] = "name";
|
|
@@ -184,10 +228,8 @@ var SearchCriterion = function (SearchCriterion) {
|
|
|
184
228
|
SearchCriterion[SearchCriterion["response"] = 9] = "response";
|
|
185
229
|
return SearchCriterion;
|
|
186
230
|
}({});
|
|
187
|
-
|
|
188
|
-
var
|
|
189
|
-
exports.SearchAll = SearchAll;
|
|
190
|
-
var criteriaToSet = criteria => {
|
|
231
|
+
export var SearchAll = new Set([SearchCriterion.method, SearchCriterion.type, SearchCriterion.name, SearchCriterion.description, SearchCriterion.argument, SearchCriterion.property, SearchCriterion.title, SearchCriterion.activityType, SearchCriterion.status, SearchCriterion.response]);
|
|
232
|
+
export var criteriaToSet = criteria => {
|
|
191
233
|
var result = new Set();
|
|
192
234
|
criteria.forEach(name => {
|
|
193
235
|
var val = SearchCriterion[name];
|
|
@@ -195,14 +237,12 @@ var criteriaToSet = criteria => {
|
|
|
195
237
|
});
|
|
196
238
|
return result;
|
|
197
239
|
};
|
|
198
|
-
|
|
199
|
-
var setToCriteria = criteria => {
|
|
240
|
+
export var setToCriteria = criteria => {
|
|
200
241
|
var result = [];
|
|
201
242
|
criteria.forEach(value => result.push(SearchCriterion[value]));
|
|
202
243
|
return result;
|
|
203
244
|
};
|
|
204
|
-
|
|
205
|
-
var MetaType = function (MetaType) {
|
|
245
|
+
export var MetaType = function (MetaType) {
|
|
206
246
|
MetaType["Intrinsic"] = "Intrinsic";
|
|
207
247
|
MetaType["Specification"] = "Specification";
|
|
208
248
|
MetaType["Write"] = "Write";
|
|
@@ -210,8 +250,7 @@ var MetaType = function (MetaType) {
|
|
|
210
250
|
MetaType["Enumerated"] = "Enumerated";
|
|
211
251
|
return MetaType;
|
|
212
252
|
}({});
|
|
213
|
-
|
|
214
|
-
var tagTypes = (api, types) => {
|
|
253
|
+
export var tagTypes = (api, types) => {
|
|
215
254
|
var typeTags = {};
|
|
216
255
|
Object.entries(types).filter(_ref => {
|
|
217
256
|
var [_, type] = _ref;
|
|
@@ -236,7 +275,6 @@ var tagTypes = (api, types) => {
|
|
|
236
275
|
});
|
|
237
276
|
return typeTags;
|
|
238
277
|
};
|
|
239
|
-
exports.tagTypes = tagTypes;
|
|
240
278
|
class MethodResponse {
|
|
241
279
|
constructor(statusCode, mediaType, type, description) {
|
|
242
280
|
this.statusCode = statusCode;
|
|
@@ -245,14 +283,14 @@ class MethodResponse {
|
|
|
245
283
|
this.description = description;
|
|
246
284
|
}
|
|
247
285
|
get mode() {
|
|
248
|
-
return
|
|
286
|
+
return responseMode(this.mediaType);
|
|
249
287
|
}
|
|
250
288
|
search(rx, criteria) {
|
|
251
289
|
if (!criteria.has(SearchCriterion.response)) return false;
|
|
252
290
|
return rx.test(this.searchString(criteria)) || this.type.search(rx, criteria);
|
|
253
291
|
}
|
|
254
292
|
searchString(criteria) {
|
|
255
|
-
var result = searchIt("".concat(this.statusCode)) + searchIt("".concat(
|
|
293
|
+
var result = searchIt("".concat(this.statusCode)) + searchIt("".concat(ResponseMode[this.mode]));
|
|
256
294
|
if (criteria.has(SearchCriterion.name)) result += searchIt(this.mediaType);
|
|
257
295
|
return result;
|
|
258
296
|
}
|
|
@@ -305,7 +343,151 @@ class SchemadSymbol extends _Symbol {
|
|
|
305
343
|
return this.deprecated ? 'deprecated' : '';
|
|
306
344
|
}
|
|
307
345
|
}
|
|
308
|
-
|
|
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
|
+
};
|
|
490
|
+
export class Property extends SchemadSymbol {
|
|
309
491
|
constructor(name, type, schema) {
|
|
310
492
|
var _schema$required;
|
|
311
493
|
var owner = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
@@ -315,7 +497,7 @@ class Property extends SchemadSymbol {
|
|
|
315
497
|
_defineProperty(this, "nullable", false);
|
|
316
498
|
_defineProperty(this, "readOnly", false);
|
|
317
499
|
_defineProperty(this, "writeOnly", false);
|
|
318
|
-
this.required =
|
|
500
|
+
this.required = Boolean(required.includes(name) || ((_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(name)));
|
|
319
501
|
this.nullable = this.schema.nullable || this.schema['x-looker-nullable'] || false;
|
|
320
502
|
this.readOnly = this.schema.readOnly || false;
|
|
321
503
|
this.writeOnly = this.schema.writeOnly || false;
|
|
@@ -338,9 +520,58 @@ class Property extends SchemadSymbol {
|
|
|
338
520
|
search(rx, criteria) {
|
|
339
521
|
return rx.test(this.searchString(criteria)) || this.type.search(rx, criteria);
|
|
340
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
|
+
}
|
|
341
573
|
}
|
|
342
|
-
|
|
343
|
-
class Parameter extends SchemadSymbol {
|
|
574
|
+
export class Parameter extends SchemadSymbol {
|
|
344
575
|
constructor(param, type) {
|
|
345
576
|
var owner = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
346
577
|
super(param.name || '', type, type.schema, owner);
|
|
@@ -395,24 +626,23 @@ class Parameter extends SchemadSymbol {
|
|
|
395
626
|
return rx.test(this.searchString(criteria)) || this.type.search(rx, criteria);
|
|
396
627
|
}
|
|
397
628
|
}
|
|
398
|
-
|
|
399
|
-
class Method extends SchemadSymbol {
|
|
629
|
+
export class Method extends SchemadSymbol {
|
|
400
630
|
constructor(api, httpMethod, endpoint, schema, params, responses, body) {
|
|
401
631
|
if (!schema.operationId) {
|
|
402
632
|
throw new Error('Missing operationId');
|
|
403
633
|
}
|
|
404
634
|
var okays = responses.filter(response => {
|
|
405
|
-
return response.statusCode ===
|
|
635
|
+
return response.statusCode === StatusCode.OK || response.statusCode === StatusCode.NoContent;
|
|
406
636
|
});
|
|
407
637
|
if (!okays) {
|
|
408
638
|
throw new Error("Missing 2xx + application/json response in ".concat(endpoint));
|
|
409
639
|
}
|
|
410
640
|
var primaryResponse = okays.find(response => {
|
|
411
|
-
return response.statusCode ===
|
|
641
|
+
return response.statusCode === StatusCode.OK && response.mediaType === 'application/json';
|
|
412
642
|
}) || okays.find(response => {
|
|
413
|
-
return response.statusCode ===
|
|
643
|
+
return response.statusCode === StatusCode.OK;
|
|
414
644
|
}) || okays.find(response => {
|
|
415
|
-
return response.statusCode ===
|
|
645
|
+
return response.statusCode === StatusCode.NoContent;
|
|
416
646
|
});
|
|
417
647
|
if (!primaryResponse) {
|
|
418
648
|
throw new Error("Missing 2xx + application/json response in ".concat(endpoint));
|
|
@@ -500,7 +730,7 @@ class Method extends SchemadSymbol {
|
|
|
500
730
|
var modes = new Set();
|
|
501
731
|
for (var resp of this.responses) {
|
|
502
732
|
var mode = resp.mode;
|
|
503
|
-
if (mode !==
|
|
733
|
+
if (mode !== ResponseMode.unknown) modes.add(mode);
|
|
504
734
|
}
|
|
505
735
|
if (modes.size === 0) {
|
|
506
736
|
throw new Error("Is ".concat(this.operationId, " ").concat(JSON.stringify(this.responses), " binary or string?"));
|
|
@@ -584,10 +814,10 @@ class Method extends SchemadSymbol {
|
|
|
584
814
|
return this.params;
|
|
585
815
|
}
|
|
586
816
|
responseIsBinary() {
|
|
587
|
-
return this.responseModes.has(
|
|
817
|
+
return this.responseModes.has(ResponseMode.binary);
|
|
588
818
|
}
|
|
589
819
|
responseIsString() {
|
|
590
|
-
return this.responseModes.has(
|
|
820
|
+
return this.responseModes.has(ResponseMode.string);
|
|
591
821
|
}
|
|
592
822
|
responseIsBoth() {
|
|
593
823
|
return this.responseIsBinary() && this.responseIsString();
|
|
@@ -681,8 +911,7 @@ class Method extends SchemadSymbol {
|
|
|
681
911
|
return result;
|
|
682
912
|
}
|
|
683
913
|
}
|
|
684
|
-
|
|
685
|
-
class Type {
|
|
914
|
+
export class Type {
|
|
686
915
|
constructor(schema, name) {
|
|
687
916
|
this.schema = schema;
|
|
688
917
|
this.name = name;
|
|
@@ -726,7 +955,7 @@ class Type {
|
|
|
726
955
|
var type = prop.type;
|
|
727
956
|
var w = type.intrinsic ? undefined : api.mayGetWriteableType(type);
|
|
728
957
|
if (w) {
|
|
729
|
-
var writeProp = _objectSpread(_objectSpread({}, prop), {
|
|
958
|
+
var writeProp = _objectSpread(_objectSpread({}, prop), {}, {
|
|
730
959
|
type: w
|
|
731
960
|
});
|
|
732
961
|
result.push(writeProp);
|
|
@@ -790,6 +1019,74 @@ class Type {
|
|
|
790
1019
|
return prop.hasSpecialNeeds;
|
|
791
1020
|
});
|
|
792
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
|
+
}
|
|
793
1090
|
load(api) {
|
|
794
1091
|
Object.entries(this.schema.properties || {}).forEach(_ref7 => {
|
|
795
1092
|
var [propName, propSchema] = _ref7;
|
|
@@ -870,8 +1167,7 @@ class Type {
|
|
|
870
1167
|
return result;
|
|
871
1168
|
}
|
|
872
1169
|
}
|
|
873
|
-
|
|
874
|
-
class ArrayType extends Type {
|
|
1170
|
+
export class ArrayType extends Type {
|
|
875
1171
|
constructor(elementType, schema) {
|
|
876
1172
|
super(schema, "".concat(elementType.name, "[]"));
|
|
877
1173
|
this.elementType = elementType;
|
|
@@ -883,9 +1179,16 @@ class ArrayType extends Type {
|
|
|
883
1179
|
get readOnly() {
|
|
884
1180
|
return this.elementType.readOnly;
|
|
885
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
|
+
}
|
|
886
1190
|
}
|
|
887
|
-
|
|
888
|
-
class EnumType extends Type {
|
|
1191
|
+
export class EnumType extends Type {
|
|
889
1192
|
constructor(elementType, schema, api, typeName, methodName) {
|
|
890
1193
|
super(schema, schema.name);
|
|
891
1194
|
this.elementType = elementType;
|
|
@@ -904,7 +1207,7 @@ class EnumType extends Type {
|
|
|
904
1207
|
this.name = this.findName(api, typeName, methodName);
|
|
905
1208
|
}
|
|
906
1209
|
findName(api, typeName, methodName) {
|
|
907
|
-
var hash = (
|
|
1210
|
+
var hash = md5(this.asHashString());
|
|
908
1211
|
var enums = api.getEnumList();
|
|
909
1212
|
var name = titleCase(this.name || typeName || 'Enum');
|
|
910
1213
|
if (name in api.types) {
|
|
@@ -923,6 +1226,10 @@ class EnumType extends Type {
|
|
|
923
1226
|
enums[hash] = this;
|
|
924
1227
|
return name;
|
|
925
1228
|
}
|
|
1229
|
+
mock() {
|
|
1230
|
+
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1231
|
+
return this.values[0];
|
|
1232
|
+
}
|
|
926
1233
|
searchString(criteria) {
|
|
927
1234
|
var result = super.searchString(criteria);
|
|
928
1235
|
if (criteria.has(SearchCriterion.property)) {
|
|
@@ -942,8 +1249,7 @@ class EnumType extends Type {
|
|
|
942
1249
|
return this.values.join();
|
|
943
1250
|
}
|
|
944
1251
|
}
|
|
945
|
-
|
|
946
|
-
class DelimArrayType extends Type {
|
|
1252
|
+
export class DelimArrayType extends Type {
|
|
947
1253
|
constructor(elementType, schema) {
|
|
948
1254
|
super(schema, "DelimArray<".concat(elementType.name, ">"));
|
|
949
1255
|
this.elementType = elementType;
|
|
@@ -957,8 +1263,7 @@ class DelimArrayType extends Type {
|
|
|
957
1263
|
return this.elementType.readOnly;
|
|
958
1264
|
}
|
|
959
1265
|
}
|
|
960
|
-
|
|
961
|
-
class HashType extends Type {
|
|
1266
|
+
export class HashType extends Type {
|
|
962
1267
|
constructor(elementType, schema) {
|
|
963
1268
|
super(schema, "Hash[".concat(elementType.name, "]"));
|
|
964
1269
|
_defineProperty(this, "elementType", void 0);
|
|
@@ -972,14 +1277,22 @@ class HashType extends Type {
|
|
|
972
1277
|
return this.elementType.readOnly;
|
|
973
1278
|
}
|
|
974
1279
|
}
|
|
975
|
-
|
|
976
|
-
class IntrinsicType extends Type {
|
|
1280
|
+
export class IntrinsicType extends Type {
|
|
977
1281
|
constructor(name) {
|
|
978
1282
|
super({}, name);
|
|
979
1283
|
_defineProperty(this, "isString", false);
|
|
980
1284
|
this.customType = '';
|
|
981
1285
|
this.isString = IntrinsicType.stringTypes.includes(name);
|
|
982
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
|
+
}
|
|
983
1296
|
get className() {
|
|
984
1297
|
return 'IntrinsicType';
|
|
985
1298
|
}
|
|
@@ -990,9 +1303,8 @@ class IntrinsicType extends Type {
|
|
|
990
1303
|
return false;
|
|
991
1304
|
}
|
|
992
1305
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
class RequestType extends Type {
|
|
1306
|
+
_defineProperty(IntrinsicType, "stringTypes", ['string', 'uri', 'url', 'email', 'uuid', 'hostname', 'password', 'ipv4', 'ipv6', 'byte', 'binary']);
|
|
1307
|
+
export class RequestType extends Type {
|
|
996
1308
|
constructor(api, name, params) {
|
|
997
1309
|
var description = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
998
1310
|
super({
|
|
@@ -1006,8 +1318,7 @@ class RequestType extends Type {
|
|
|
1006
1318
|
});
|
|
1007
1319
|
}
|
|
1008
1320
|
}
|
|
1009
|
-
|
|
1010
|
-
class WriteType extends Type {
|
|
1321
|
+
export class WriteType extends Type {
|
|
1011
1322
|
constructor(api, type) {
|
|
1012
1323
|
var name = "".concat(strWrite).concat(type.name);
|
|
1013
1324
|
var roProps = WriteType.readonlyProps(type.properties);
|
|
@@ -1030,7 +1341,6 @@ class WriteType extends Type {
|
|
|
1030
1341
|
});
|
|
1031
1342
|
}
|
|
1032
1343
|
}
|
|
1033
|
-
exports.WriteType = WriteType;
|
|
1034
1344
|
_defineProperty(WriteType, "readonlyProps", properties => {
|
|
1035
1345
|
var result = [];
|
|
1036
1346
|
Object.entries(properties).filter(_ref21 => {
|
|
@@ -1042,7 +1352,15 @@ _defineProperty(WriteType, "readonlyProps", properties => {
|
|
|
1042
1352
|
});
|
|
1043
1353
|
return result;
|
|
1044
1354
|
});
|
|
1045
|
-
|
|
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
|
+
};
|
|
1363
|
+
export class ApiModel {
|
|
1046
1364
|
constructor(spec) {
|
|
1047
1365
|
this.spec = spec;
|
|
1048
1366
|
_defineProperty(this, "enumTypes", {});
|
|
@@ -1051,8 +1369,7 @@ class ApiModel {
|
|
|
1051
1369
|
_defineProperty(this, "types", {});
|
|
1052
1370
|
_defineProperty(this, "tags", {});
|
|
1053
1371
|
_defineProperty(this, "typeTags", {});
|
|
1054
|
-
;
|
|
1055
|
-
['string', 'integer', 'int64', 'boolean', 'object', 'uri', 'float', 'double', 'void', 'datetime', 'email', 'uuid', 'uri', 'hostname', 'ipv4', 'ipv6', 'any'].forEach(name => this.types[name] = new IntrinsicType(name));
|
|
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));
|
|
1056
1373
|
this.load();
|
|
1057
1374
|
}
|
|
1058
1375
|
get version() {
|
|
@@ -1064,12 +1381,10 @@ class ApiModel {
|
|
|
1064
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()) || '';
|
|
1065
1382
|
}
|
|
1066
1383
|
static fromString(specContent) {
|
|
1067
|
-
|
|
1068
|
-
return ApiModel.fromJson(json);
|
|
1384
|
+
return specToModel(specContent);
|
|
1069
1385
|
}
|
|
1070
1386
|
static fromJson(json) {
|
|
1071
|
-
|
|
1072
|
-
return new ApiModel(spec);
|
|
1387
|
+
return specToModel(json);
|
|
1073
1388
|
}
|
|
1074
1389
|
static isMethodSearch(criteria) {
|
|
1075
1390
|
return criteria.has(SearchCriterion.method) || criteria.has(SearchCriterion.argument) || criteria.has(SearchCriterion.response) || criteria.has(SearchCriterion.status) || criteria.has(SearchCriterion.activityType);
|
|
@@ -1142,9 +1457,9 @@ class ApiModel {
|
|
|
1142
1457
|
if (!(path instanceof Array)) {
|
|
1143
1458
|
keys = path.split(splitter);
|
|
1144
1459
|
}
|
|
1145
|
-
for (var
|
|
1146
|
-
if (
|
|
1147
|
-
item = item[
|
|
1460
|
+
for (var _key3 of keys) {
|
|
1461
|
+
if (_key3 === '#') continue;
|
|
1462
|
+
item = item[_key3];
|
|
1148
1463
|
if (item == null) return null;
|
|
1149
1464
|
}
|
|
1150
1465
|
return item;
|
|
@@ -1166,7 +1481,7 @@ class ApiModel {
|
|
|
1166
1481
|
return result;
|
|
1167
1482
|
};
|
|
1168
1483
|
if (typeof schema === 'string') {
|
|
1169
|
-
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.
|
|
1484
|
+
if (schema.indexOf('/requestBodies/') < 0) return this.types[schema.substring(schema.lastIndexOf('/') + 1)];
|
|
1170
1485
|
var deref = this.jsonPath(schema);
|
|
1171
1486
|
if (deref) {
|
|
1172
1487
|
var ref = this.jsonPath(['content', 'application/json', 'schema', '$ref'], deref);
|
|
@@ -1178,8 +1493,9 @@ class ApiModel {
|
|
|
1178
1493
|
if (schema.type === 'integer' && schema.format === 'int64') {
|
|
1179
1494
|
return this.types.int64;
|
|
1180
1495
|
}
|
|
1181
|
-
if (schema.type === 'number'
|
|
1182
|
-
return this.types[schema.format];
|
|
1496
|
+
if (schema.type === 'number') {
|
|
1497
|
+
if (schema.format) return this.types[schema.format];
|
|
1498
|
+
return this.types.float;
|
|
1183
1499
|
}
|
|
1184
1500
|
if (schema.type === 'array' && schema.items) {
|
|
1185
1501
|
var resolved = this.resolveType(schema.items);
|
|
@@ -1235,7 +1551,7 @@ class ApiModel {
|
|
|
1235
1551
|
registerEnum(type, methodName) {
|
|
1236
1552
|
if (!(type instanceof EnumType)) return type;
|
|
1237
1553
|
if (type.name in this.types) {
|
|
1238
|
-
var hash = (
|
|
1554
|
+
var hash = md5(type.asHashString());
|
|
1239
1555
|
var matched = this.enumTypes[hash];
|
|
1240
1556
|
if ((matched === null || matched === void 0 ? void 0 : matched.name) === type.name) {
|
|
1241
1557
|
return this.enumTypes[hash];
|
|
@@ -1306,8 +1622,8 @@ class ApiModel {
|
|
|
1306
1622
|
sortList(list) {
|
|
1307
1623
|
var result = {};
|
|
1308
1624
|
var sortedKeys = Object.keys(list).sort(localeSort);
|
|
1309
|
-
for (var
|
|
1310
|
-
result[
|
|
1625
|
+
for (var _key4 of sortedKeys) {
|
|
1626
|
+
result[_key4] = list[_key4];
|
|
1311
1627
|
}
|
|
1312
1628
|
return result;
|
|
1313
1629
|
}
|
|
@@ -1422,7 +1738,7 @@ class ApiModel {
|
|
|
1422
1738
|
if (!OAS.isReferenceObject(obj)) {
|
|
1423
1739
|
var req = obj;
|
|
1424
1740
|
if ('required' in req) {
|
|
1425
|
-
required = req.required;
|
|
1741
|
+
required = Boolean(req.required);
|
|
1426
1742
|
}
|
|
1427
1743
|
}
|
|
1428
1744
|
var typeSchema = {
|
|
@@ -1452,9 +1768,8 @@ class ApiModel {
|
|
|
1452
1768
|
description: '',
|
|
1453
1769
|
location: strBody,
|
|
1454
1770
|
name: strBody,
|
|
1455
|
-
required
|
|
1771
|
+
required
|
|
1456
1772
|
}, type);
|
|
1457
1773
|
}
|
|
1458
1774
|
}
|
|
1459
|
-
exports.ApiModel = ApiModel;
|
|
1460
1775
|
//# sourceMappingURL=sdkModels.js.map
|