@looker/sdk-codegen 21.7.3 → 21.8.0
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 +23 -0
- package/lib/codeGen.d.ts +1 -1
- package/lib/codeGen.js +28 -154
- package/lib/codeGen.js.map +1 -1
- package/lib/codeGenerators.js +0 -16
- package/lib/codeGenerators.js.map +1 -1
- package/lib/csharp.gen.js +3 -71
- package/lib/csharp.gen.js.map +1 -1
- package/lib/declarationInfo.js +0 -7
- package/lib/declarationInfo.js.map +1 -1
- package/lib/esm/codeGen.js +48 -157
- package/lib/esm/codeGen.js.map +1 -1
- package/lib/esm/codeGenerators.js +28 -20
- package/lib/esm/codeGenerators.js.map +1 -1
- package/lib/esm/csharp.gen.js +19 -75
- package/lib/esm/csharp.gen.js.map +1 -1
- package/lib/esm/declarationInfo.js +10 -7
- package/lib/esm/declarationInfo.js.map +1 -1
- package/lib/esm/exampleInfo.js +24 -23
- package/lib/esm/exampleInfo.js.map +1 -1
- package/lib/esm/go.gen.js +18 -92
- package/lib/esm/go.gen.js.map +1 -1
- package/lib/esm/index.js +148 -13
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/kotlin.gen.js +23 -118
- package/lib/esm/kotlin.gen.js.map +1 -1
- package/lib/esm/pseudo.gen.js +14 -24
- package/lib/esm/pseudo.gen.js.map +1 -1
- package/lib/esm/python.gen.js +19 -138
- package/lib/esm/python.gen.js.map +1 -1
- package/lib/esm/sdkModels.js +100 -432
- package/lib/esm/sdkModels.js.map +1 -1
- package/lib/esm/specConverter.js +58 -88
- package/lib/esm/specConverter.js.map +1 -1
- package/lib/esm/specDiff.js +36 -51
- package/lib/esm/specDiff.js.map +1 -1
- package/lib/esm/swift.gen.js +25 -137
- package/lib/esm/swift.gen.js.map +1 -1
- package/lib/esm/testUtils/index.js +17 -0
- package/lib/esm/testUtils/index.js.map +1 -0
- package/lib/esm/testUtils/testUtils.js +66 -0
- package/lib/esm/testUtils/testUtils.js.map +1 -0
- package/lib/esm/typescript.gen.js +24 -125
- package/lib/esm/typescript.gen.js.map +1 -1
- package/lib/exampleInfo.js +1 -31
- package/lib/exampleInfo.js.map +1 -1
- package/lib/go.gen.js +3 -87
- package/lib/go.gen.js.map +1 -1
- package/lib/index.js +0 -26
- package/lib/index.js.map +1 -1
- package/lib/kotlin.gen.js +7 -113
- package/lib/kotlin.gen.js.map +1 -1
- package/lib/pseudo.gen.js +3 -24
- package/lib/pseudo.gen.js.map +1 -1
- package/lib/python.gen.js +3 -133
- package/lib/python.gen.js.map +1 -1
- package/lib/sdkModels.js +8 -438
- package/lib/sdkModels.js.map +1 -1
- package/lib/specConverter.js +6 -106
- package/lib/specConverter.js.map +1 -1
- package/lib/specDiff.js +1 -56
- package/lib/specDiff.js.map +1 -1
- package/lib/swift.gen.js +3 -128
- package/lib/swift.gen.js.map +1 -1
- package/lib/testUtils/index.js +0 -2
- package/lib/testUtils/index.js.map +1 -1
- package/lib/testUtils/testUtils.js +1 -17
- package/lib/testUtils/testUtils.js.map +1 -1
- package/lib/typescript.gen.js +5 -117
- package/lib/typescript.gen.js.map +1 -1
- package/package.json +3 -3
package/lib/esm/python.gen.js
CHANGED
|
@@ -1,211 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PythonGen = void 0;
|
|
7
|
+
var _sdkModels = require("./sdkModels");
|
|
8
|
+
var _codeGen = require("./codeGen");
|
|
9
|
+
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; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
class PythonGen extends _codeGen.CodeGen {
|
|
6
13
|
constructor() {
|
|
7
14
|
super(...arguments);
|
|
8
|
-
|
|
9
15
|
_defineProperty(this, "codePath", './python/');
|
|
10
|
-
|
|
11
16
|
_defineProperty(this, "packagePath", 'looker_sdk');
|
|
12
|
-
|
|
13
17
|
_defineProperty(this, "itself", 'self');
|
|
14
|
-
|
|
15
18
|
_defineProperty(this, "fileExtension", '.py');
|
|
16
|
-
|
|
17
19
|
_defineProperty(this, "commentStr", '# ');
|
|
18
|
-
|
|
19
20
|
_defineProperty(this, "nullStr", 'None');
|
|
20
|
-
|
|
21
21
|
_defineProperty(this, "indentStr", ' ');
|
|
22
|
-
|
|
23
22
|
_defineProperty(this, "argDelimiter", ",\n".concat(this.indentStr.repeat(3)));
|
|
24
|
-
|
|
25
23
|
_defineProperty(this, "argSetSep", '=');
|
|
26
|
-
|
|
27
24
|
_defineProperty(this, "paramDelimiter", ',\n');
|
|
28
|
-
|
|
29
25
|
_defineProperty(this, "propDelimiter", '\n');
|
|
30
|
-
|
|
31
26
|
_defineProperty(this, "dataStructureDelimiter", ', ');
|
|
32
|
-
|
|
33
27
|
_defineProperty(this, "enumDelimiter", '\n');
|
|
34
|
-
|
|
35
28
|
_defineProperty(this, "codeQuote", '"');
|
|
36
|
-
|
|
37
29
|
_defineProperty(this, "typeOpen", '(');
|
|
38
|
-
|
|
39
30
|
_defineProperty(this, "typeClose", ')');
|
|
40
|
-
|
|
41
31
|
_defineProperty(this, "hashKeyQuote", '"');
|
|
42
|
-
|
|
43
32
|
_defineProperty(this, "useModelClassForTypes", true);
|
|
44
|
-
|
|
45
33
|
_defineProperty(this, "endTypeStr", '');
|
|
46
|
-
|
|
47
34
|
_defineProperty(this, "pythonKeywords", new Set(['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']));
|
|
48
|
-
|
|
49
35
|
_defineProperty(this, "hooks", []);
|
|
50
|
-
|
|
51
36
|
_defineProperty(this, "structureHookTK", 'translate_keys_structure_hook');
|
|
52
|
-
|
|
53
37
|
_defineProperty(this, "pythonReservedKeywordClasses", new Set());
|
|
54
|
-
|
|
55
38
|
_defineProperty(this, "methodsPrologue", _indent => "\n# ".concat(this.warnEditing(), "\nimport datetime\nfrom typing import Any, MutableMapping, Optional, Sequence, Union, cast\nimport warnings\n\nfrom . import models as mdls\nfrom ").concat(this.packagePath, ".rtl import api_methods\nfrom ").concat(this.packagePath, ".rtl import transport\n\nclass ").concat(this.packageName, "(api_methods.APIMethods):\n"));
|
|
56
|
-
|
|
57
39
|
_defineProperty(this, "methodsEpilogue", _indent => this.apiVersion === '3.1' ? "LookerSDK = ".concat(this.packageName) : '');
|
|
58
|
-
|
|
59
40
|
_defineProperty(this, "modelsPrologue", _indent => "\n# ".concat(this.warnEditing(), "\nimport datetime\nimport enum\nfrom typing import Any, MutableMapping, Optional, Sequence\n\ntry:\n from typing import ForwardRef # type: ignore\nexcept ImportError:\n from typing import _ForwardRef as ForwardRef # type: ignore\n\nimport attr\n\nfrom ").concat(this.packagePath, ".rtl import model\nfrom ").concat(this.packagePath, ".rtl import serialize as sr\n\nEXPLICIT_NULL = model.EXPLICIT_NULL # type: ignore\nDelimSequence = model.DelimSequence\n"));
|
|
60
|
-
|
|
61
41
|
_defineProperty(this, "modelsEpilogue", _indent => "\nimport functools # noqa:E402\n\nforward_ref_structure_hook = functools.partial(\n sr.forward_ref_structure_hook, globals(), sr.converter".concat(this.apiRef, "\n)\nsr.converter").concat(this.apiRef, ".register_structure_hook_func(\n lambda t: t.__class__ is ForwardRef, forward_ref_structure_hook\n)\n").concat(this.structureHookTK, " = functools.partial(sr.translate_keys_structure_hook, sr.converter").concat(this.apiRef, ")\n").concat(this.hooks.join('\n'), "\n"));
|
|
62
|
-
|
|
63
42
|
_defineProperty(this, "isBareForwardRef", prop => {
|
|
64
|
-
return prop.required && (prop.type.customType || prop.type instanceof EnumType) && !['ArrayType', 'HashType', 'DelimArrayType'].includes(prop.type.className);
|
|
43
|
+
return prop.required && (prop.type.customType || prop.type instanceof _sdkModels.EnumType) && !['ArrayType', 'HashType', 'DelimArrayType'].includes(prop.type.className);
|
|
65
44
|
});
|
|
66
45
|
}
|
|
67
|
-
|
|
68
46
|
sdkFileName(baseFileName) {
|
|
69
47
|
return this.fileName("sdk/api".concat(this.apiRef, "/").concat(baseFileName));
|
|
70
48
|
}
|
|
71
|
-
|
|
72
49
|
argGroup(_indent, args) {
|
|
73
50
|
if (!args || args.length === 0) return this.nullStr;
|
|
74
51
|
var hash = [];
|
|
75
|
-
|
|
76
52
|
for (var arg of args) {
|
|
77
53
|
hash.push("\"".concat(arg, "\": ").concat(arg));
|
|
78
54
|
}
|
|
79
|
-
|
|
80
55
|
return "{".concat(hash.join(this.dataStructureDelimiter), "}");
|
|
81
56
|
}
|
|
82
|
-
|
|
83
57
|
beginRegion(indent, description) {
|
|
84
58
|
return "".concat(indent, "#region ").concat(description);
|
|
85
59
|
}
|
|
86
|
-
|
|
87
60
|
endRegion(indent, _description) {
|
|
88
61
|
return "".concat(indent, "#endregion");
|
|
89
62
|
}
|
|
90
|
-
|
|
91
63
|
declareProperty(indent, property) {
|
|
92
64
|
var annotations = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
93
65
|
var mappedType = this.typeMapModels(property.type);
|
|
94
66
|
var propName = property.name;
|
|
95
|
-
|
|
96
67
|
if (this.pythonKeywords.has(propName)) {
|
|
97
68
|
propName = propName + '_';
|
|
98
69
|
}
|
|
99
|
-
|
|
100
70
|
var propType = mappedType.name;
|
|
101
|
-
|
|
102
71
|
if (!property.required) {
|
|
103
72
|
propType = "Optional[".concat(mappedType.name, "]");
|
|
104
73
|
}
|
|
105
|
-
|
|
106
74
|
var propDef;
|
|
107
|
-
|
|
108
75
|
if (annotations) {
|
|
109
76
|
var annotation = propType;
|
|
110
|
-
|
|
111
77
|
if (this.isBareForwardRef(property)) {
|
|
112
78
|
annotation = "ForwardRef(".concat(propType, ")");
|
|
113
79
|
}
|
|
114
|
-
|
|
115
80
|
propDef = "".concat(this.bumper(indent), "\"").concat(propName, "\": ").concat(annotation);
|
|
116
81
|
} else {
|
|
117
82
|
if (!property.required) {
|
|
118
83
|
propType += " = ".concat(this.nullStr);
|
|
119
84
|
}
|
|
120
|
-
|
|
121
85
|
propDef = "".concat(indent).concat(propName, ": ").concat(propType);
|
|
122
86
|
}
|
|
123
|
-
|
|
124
87
|
return propDef;
|
|
125
88
|
}
|
|
126
|
-
|
|
127
89
|
methodReturnType(method) {
|
|
128
90
|
var type = this.typeMapMethods(method.type);
|
|
129
91
|
var returnType = type.name;
|
|
130
|
-
|
|
131
92
|
if (method.responseIsBoth()) {
|
|
132
93
|
returnType = "Union[".concat(returnType, ", bytes]");
|
|
133
94
|
} else if (method.responseIsBinary()) {
|
|
134
95
|
returnType = 'bytes';
|
|
135
96
|
}
|
|
136
|
-
|
|
137
97
|
return returnType;
|
|
138
98
|
}
|
|
139
|
-
|
|
140
99
|
methodSignature(indent, method) {
|
|
141
100
|
var _method$description;
|
|
142
|
-
|
|
143
101
|
var returnType = this.methodReturnType(method);
|
|
144
102
|
var bump = this.bumper(indent);
|
|
145
103
|
var params = [];
|
|
146
104
|
var args = method.allParams;
|
|
147
|
-
|
|
148
105
|
if (args && args.length > 0) {
|
|
149
106
|
method.allParams.forEach(p => params.push(this.declareParameter(bump, method, p)));
|
|
150
107
|
}
|
|
151
|
-
|
|
152
108
|
var head = (_method$description = method.description) === null || _method$description === void 0 ? void 0 : _method$description.trim();
|
|
153
109
|
head = (head ? "".concat(head, "\n\n") : '') + "".concat(method.httpMethod, " ").concat(method.endpoint, " -> ").concat(returnType);
|
|
154
110
|
params.push("".concat(bump, "transport_options: Optional[transport.TransportOptions] = None,"));
|
|
155
111
|
return this.commentHeader(indent, head) + "".concat(indent, "def ").concat(method.name, "(\n") + "".concat(bump, "self").concat(params.length > 0 ? ',\n' : '') + "".concat(params.join(this.paramDelimiter), "\n") + "".concat(indent, ") -> ").concat(returnType, ":\n");
|
|
156
112
|
}
|
|
157
|
-
|
|
158
113
|
declareParameter(indent, method, param) {
|
|
159
114
|
var type;
|
|
160
|
-
|
|
161
|
-
if (param.location === strBody) {
|
|
115
|
+
if (param.location === _sdkModels.strBody) {
|
|
162
116
|
type = this.writeableType(param.type, method) || param.type;
|
|
163
117
|
} else {
|
|
164
118
|
type = param.type;
|
|
165
119
|
}
|
|
166
|
-
|
|
167
120
|
var mapped = this.typeMapMethods(type);
|
|
168
121
|
var paramType = param.required ? mapped.name : "Optional[".concat(mapped.name, "]");
|
|
169
|
-
return this.commentHeader(indent, describeParam(param)) + "".concat(indent).concat(param.name, ": ").concat(paramType) + (param.required ? '' : " = ".concat(mapped.default));
|
|
122
|
+
return this.commentHeader(indent, (0, _sdkModels.describeParam)(param)) + "".concat(indent).concat(param.name, ": ").concat(paramType) + (param.required ? '' : " = ".concat(mapped.default));
|
|
170
123
|
}
|
|
171
|
-
|
|
172
124
|
makeTheCall(method, inputs) {
|
|
173
125
|
var origDelim = this.argDelimiter;
|
|
174
126
|
this.argDelimiter = ",\n".concat(this.indentStr);
|
|
175
|
-
inputs = trimInputs(inputs);
|
|
176
127
|
var resp = "response = sdk.".concat(method.name, "(");
|
|
177
128
|
var args = this.assignParams(method, inputs);
|
|
178
129
|
this.argDelimiter = origDelim;
|
|
179
130
|
return "".concat(resp).concat(args, ")");
|
|
180
131
|
}
|
|
181
|
-
|
|
182
132
|
initArg(indent, property) {
|
|
183
133
|
var propName = property.name;
|
|
184
|
-
|
|
185
134
|
if (this.pythonKeywords.has(propName)) {
|
|
186
135
|
propName = propName + '_';
|
|
187
136
|
}
|
|
188
|
-
|
|
189
137
|
return "".concat(indent, "self.").concat(propName, " = ").concat(propName);
|
|
190
138
|
}
|
|
191
|
-
|
|
192
139
|
declareType(indent, type) {
|
|
193
140
|
var decl = super.declareType(indent, type);
|
|
194
|
-
|
|
195
|
-
if (type instanceof EnumType) {
|
|
141
|
+
if (type instanceof _sdkModels.EnumType) {
|
|
196
142
|
var invalid = 'invalid_api_enum_value = "invalid_api_enum_value"' + '\n\n\n# https://github.com/python/mypy/issues/2427' + "\n".concat(type.name, ".__new__ = model.safe_enum__new__ # type: ignore");
|
|
197
143
|
decl += "\n".concat(this.bumper(indent)).concat(invalid);
|
|
198
144
|
}
|
|
199
|
-
|
|
200
145
|
return decl;
|
|
201
146
|
}
|
|
202
|
-
|
|
203
147
|
typeProperties(type) {
|
|
204
148
|
return Object.values(type.requiredProperties).concat(Object.values(type.optionalProperties));
|
|
205
149
|
}
|
|
206
|
-
|
|
207
150
|
construct(indent, type) {
|
|
208
|
-
if (type instanceof EnumType) return '';
|
|
151
|
+
if (type instanceof _sdkModels.EnumType) return '';
|
|
209
152
|
indent = this.bumper(indent);
|
|
210
153
|
var bump = this.bumper(indent);
|
|
211
154
|
var annotations = [];
|
|
@@ -217,100 +160,76 @@ export class PythonGen extends CodeGen {
|
|
|
217
160
|
inits.push(this.initArg(bump, prop));
|
|
218
161
|
});
|
|
219
162
|
var result = '';
|
|
220
|
-
|
|
221
163
|
if (Object.values(type.properties).some(this.isBareForwardRef)) {
|
|
222
164
|
result = "\n".concat(indent, "__annotations__ = {\n") + "".concat(annotations.join(',\n')) + "\n".concat(indent, "}");
|
|
223
165
|
}
|
|
224
|
-
|
|
225
166
|
result += "\n\n".concat(indent, "def __init__(self, *").concat(this.argDelimiter) + "".concat(args.join(this.argDelimiter), "):\n") + inits.join('\n');
|
|
226
167
|
return result;
|
|
227
168
|
}
|
|
228
|
-
|
|
229
169
|
declareConstructorArg(indent, property) {
|
|
230
170
|
var mappedType = this.typeMapModels(property.type);
|
|
231
171
|
var propType;
|
|
232
|
-
|
|
233
172
|
if (property.required) {
|
|
234
173
|
propType = mappedType.name;
|
|
235
174
|
} else {
|
|
236
175
|
propType = "Optional[".concat(mappedType.name, "] = ").concat(this.nullStr);
|
|
237
176
|
}
|
|
238
|
-
|
|
239
177
|
var propName = property.name;
|
|
240
|
-
|
|
241
178
|
if (this.pythonKeywords.has(propName)) {
|
|
242
179
|
propName = propName + '_';
|
|
243
180
|
}
|
|
244
|
-
|
|
245
181
|
return "".concat(indent).concat(propName, ": ").concat(propType);
|
|
246
182
|
}
|
|
247
|
-
|
|
248
183
|
argFill(current, args) {
|
|
249
184
|
if (!current && args.trim() === this.nullStr) {
|
|
250
185
|
return '';
|
|
251
186
|
}
|
|
252
|
-
|
|
253
187
|
var delimiter = ',\n';
|
|
254
|
-
|
|
255
188
|
if (!current) {
|
|
256
189
|
delimiter = '';
|
|
257
190
|
} else if (args.match(/, {2}#/)) {
|
|
258
191
|
delimiter = delimiter.replace(',', '');
|
|
259
192
|
}
|
|
260
|
-
|
|
261
193
|
return "".concat(args).concat(delimiter).concat(current);
|
|
262
194
|
}
|
|
263
|
-
|
|
264
195
|
httpArgs(callerIndent, method) {
|
|
265
196
|
var currIndent = this.bumper(callerIndent);
|
|
266
197
|
var args = '';
|
|
267
198
|
args = this.argFill(args, "".concat(currIndent, "transport_options=transport_options"));
|
|
268
|
-
|
|
269
199
|
if (method.bodyArg) {
|
|
270
200
|
args = this.argFill(args, "".concat(currIndent, "body=").concat(method.bodyArg));
|
|
271
201
|
}
|
|
272
|
-
|
|
273
202
|
if (method.queryArgs.length) {
|
|
274
203
|
var queryParams = this.argGroup('', method.queryArgs);
|
|
275
204
|
args = this.argFill(args, "".concat(currIndent, "query_params=").concat(queryParams));
|
|
276
205
|
}
|
|
277
|
-
|
|
278
206
|
var returnType = this.methodReturnType(method);
|
|
279
|
-
|
|
280
207
|
if (method.responseIsBoth()) {
|
|
281
208
|
returnType += ', # type: ignore';
|
|
282
209
|
}
|
|
283
|
-
|
|
284
210
|
args = this.argFill(args, "".concat(currIndent, "structure=").concat(returnType));
|
|
285
211
|
var endpoint = "\"".concat(method.endpoint, "\"");
|
|
286
|
-
|
|
287
212
|
if (/\{\w+\}/.test(endpoint)) {
|
|
288
213
|
endpoint = "f".concat(endpoint);
|
|
289
214
|
}
|
|
290
|
-
|
|
291
215
|
args = this.argFill(args, "".concat(currIndent, "path=").concat(endpoint));
|
|
292
216
|
return args;
|
|
293
217
|
}
|
|
294
|
-
|
|
295
218
|
httpCall(callerIndent, method) {
|
|
296
219
|
var currIndent = this.bumper(callerIndent);
|
|
297
220
|
var deprecation = '';
|
|
298
|
-
|
|
299
221
|
if (method.name === 'login_user') {
|
|
300
222
|
deprecation = "".concat(callerIndent, "warnings.warn(\"login_user behavior changed significantly ") + "in 21.4.0. See https://git.io/JOtH1\")\n";
|
|
301
223
|
}
|
|
302
|
-
|
|
303
224
|
var callOpener = "".concat(callerIndent, "response = cast(\n") + "".concat(currIndent).concat(this.methodReturnType(method), ",\n") + "".concat(currIndent).concat(this.it(method.httpMethod.toLowerCase()), "(\n");
|
|
304
225
|
var callArgs = "".concat(this.httpArgs(currIndent, method), "\n");
|
|
305
226
|
var callCloser = "".concat(currIndent, ")\n").concat(callerIndent, ")\n");
|
|
306
227
|
var returnStmt = "".concat(callerIndent, "return response");
|
|
307
228
|
return deprecation + callOpener + callArgs + callCloser + returnStmt;
|
|
308
229
|
}
|
|
309
|
-
|
|
310
230
|
encodePathParams(indent, method) {
|
|
311
231
|
var encodings = '';
|
|
312
232
|
var pathParams = method.pathParams;
|
|
313
|
-
|
|
314
233
|
if (pathParams.length > 0) {
|
|
315
234
|
for (var param of pathParams) {
|
|
316
235
|
if (param.doEncode()) {
|
|
@@ -318,76 +237,57 @@ export class PythonGen extends CodeGen {
|
|
|
318
237
|
}
|
|
319
238
|
}
|
|
320
239
|
}
|
|
321
|
-
|
|
322
240
|
return encodings;
|
|
323
241
|
}
|
|
324
|
-
|
|
325
242
|
declareMethod(indent, method) {
|
|
326
243
|
var bump = this.bumper(indent);
|
|
327
244
|
return this.methodSignature(indent, method) + this.summary(bump, method.summary) + this.encodePathParams(bump, method) + this.httpCall(bump, method);
|
|
328
245
|
}
|
|
329
|
-
|
|
330
246
|
typeSignature(indent, type) {
|
|
331
247
|
var bump = this.bumper(indent);
|
|
332
248
|
var b2 = this.bumper(bump);
|
|
333
249
|
var attrs = [];
|
|
334
|
-
var isEnum = type instanceof EnumType;
|
|
250
|
+
var isEnum = type instanceof _sdkModels.EnumType;
|
|
335
251
|
var baseClass = isEnum ? 'enum.Enum' : 'model.Model';
|
|
336
252
|
var usesReservedPythonKeyword = false;
|
|
337
|
-
|
|
338
253
|
if (!isEnum) {
|
|
339
254
|
for (var prop of this.typeProperties(type)) {
|
|
340
255
|
var propName = prop.name;
|
|
341
|
-
|
|
342
256
|
if (this.pythonKeywords.has(propName)) {
|
|
343
257
|
propName = propName + '_';
|
|
344
258
|
usesReservedPythonKeyword = true;
|
|
345
259
|
}
|
|
346
|
-
|
|
347
260
|
var attr = "".concat(b2).concat(propName, ":");
|
|
348
|
-
|
|
349
261
|
if (prop.description) {
|
|
350
262
|
attr += " ".concat(prop.description);
|
|
351
263
|
}
|
|
352
|
-
|
|
353
264
|
attrs.push(attr);
|
|
354
265
|
}
|
|
355
266
|
}
|
|
356
|
-
|
|
357
267
|
if (usesReservedPythonKeyword) {
|
|
358
268
|
this.hooks.push("sr.converter".concat(this.apiRef, ".register_structure_hook(\n").concat(bump).concat(type.name, ", # type: ignore\n").concat(bump).concat(this.structureHookTK, " # type:ignore\n)"));
|
|
359
269
|
}
|
|
360
|
-
|
|
361
270
|
var result = "\n" + (isEnum ? '' : "".concat(indent, "@attr.s(auto_attribs=True, init=False)\n")) + "".concat(indent, "class ").concat(type.name, "(").concat(baseClass, "):\n") + "".concat(bump, "\"\"\"\n") + (type.description ? "".concat(bump).concat(type.description, "\n\n") : '');
|
|
362
|
-
|
|
363
271
|
if (attrs.length > 0) {
|
|
364
272
|
result += "".concat(bump, "Attributes:\n") + "".concat(attrs.join('\n'), "\n");
|
|
365
273
|
}
|
|
366
|
-
|
|
367
274
|
return result + "".concat(bump, "\"\"\"\n");
|
|
368
275
|
}
|
|
369
|
-
|
|
370
276
|
summary(indent, text) {
|
|
371
277
|
return text ? "".concat(indent, "\"\"\"").concat(text, "\"\"\"\n") : '';
|
|
372
278
|
}
|
|
373
|
-
|
|
374
279
|
prefixModelsNamespace(name, format) {
|
|
375
280
|
var forwardRef = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
376
|
-
|
|
377
281
|
if (format === 'models') {
|
|
378
282
|
name = forwardRef ? "\"".concat(name, "\"") : name;
|
|
379
283
|
} else if (format === 'methods') {
|
|
380
284
|
name = "mdls.".concat(name);
|
|
381
285
|
}
|
|
382
|
-
|
|
383
286
|
return name;
|
|
384
287
|
}
|
|
385
|
-
|
|
386
288
|
typeMap(type) {
|
|
387
289
|
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'methods';
|
|
388
|
-
|
|
389
290
|
var asString = (_, v) => "\"".concat(v, "\"");
|
|
390
|
-
|
|
391
291
|
var pythonTypes = {
|
|
392
292
|
any: {
|
|
393
293
|
default: this.nullStr,
|
|
@@ -455,62 +355,45 @@ export class PythonGen extends CodeGen {
|
|
|
455
355
|
}
|
|
456
356
|
};
|
|
457
357
|
super.typeMap(type);
|
|
458
|
-
|
|
459
358
|
if (type.elementType) {
|
|
460
359
|
var map = this.typeMap(type.elementType, format);
|
|
461
360
|
var typeName;
|
|
462
|
-
|
|
463
361
|
var _name;
|
|
464
|
-
|
|
465
362
|
var defaultValue = this.nullStr;
|
|
466
363
|
var asVal;
|
|
467
|
-
|
|
468
364
|
switch (type.className) {
|
|
469
365
|
case 'ArrayType':
|
|
470
366
|
typeName = 'Sequence';
|
|
471
367
|
_name = "".concat(typeName, "[").concat(map.name, "]");
|
|
472
368
|
break;
|
|
473
|
-
|
|
474
369
|
case 'HashType':
|
|
475
370
|
typeName = 'MutableMapping';
|
|
476
371
|
_name = typeName + '[str, ' + (type.elementType.name === 'string' ? 'Any' : map.name) + ']';
|
|
477
372
|
break;
|
|
478
|
-
|
|
479
373
|
case 'DelimArrayType':
|
|
480
374
|
typeName = this.prefixModelsNamespace('DelimSequence', format);
|
|
481
375
|
_name = "".concat(typeName, "[").concat(map.name, "]");
|
|
482
|
-
|
|
483
376
|
asVal = (_, v) => "".concat(typeName, "([").concat(v, "])");
|
|
484
|
-
|
|
485
377
|
break;
|
|
486
|
-
|
|
487
378
|
case 'EnumType':
|
|
488
379
|
_name = typeName = this.prefixModelsNamespace(type.name, format, true);
|
|
489
|
-
|
|
490
380
|
asVal = (_, v) => "".concat(typeName, ".").concat(v);
|
|
491
|
-
|
|
492
381
|
break;
|
|
493
|
-
|
|
494
382
|
default:
|
|
495
383
|
throw new Error("Don't know how to handle: ".concat(JSON.stringify(type)));
|
|
496
384
|
}
|
|
497
|
-
|
|
498
385
|
var mt = {
|
|
499
386
|
default: defaultValue,
|
|
500
387
|
name: _name
|
|
501
388
|
};
|
|
502
|
-
|
|
503
389
|
if (asVal) {
|
|
504
390
|
mt.asVal = asVal;
|
|
505
391
|
}
|
|
506
|
-
|
|
507
392
|
return mt;
|
|
508
393
|
}
|
|
509
|
-
|
|
510
394
|
if (!type.name) {
|
|
511
395
|
throw new Error('Cannot output a nameless type.');
|
|
512
396
|
}
|
|
513
|
-
|
|
514
397
|
var name = this.prefixModelsNamespace(type.name, format, !!type.customType);
|
|
515
398
|
var result = pythonTypes[type.name];
|
|
516
399
|
return result || {
|
|
@@ -518,14 +401,12 @@ export class PythonGen extends CodeGen {
|
|
|
518
401
|
name: name
|
|
519
402
|
};
|
|
520
403
|
}
|
|
521
|
-
|
|
522
404
|
typeMapMethods(type) {
|
|
523
405
|
return this.typeMap(type, 'methods');
|
|
524
406
|
}
|
|
525
|
-
|
|
526
407
|
typeMapModels(type) {
|
|
527
408
|
return this.typeMap(type, 'models');
|
|
528
409
|
}
|
|
529
|
-
|
|
530
410
|
}
|
|
411
|
+
exports.PythonGen = PythonGen;
|
|
531
412
|
//# sourceMappingURL=python.gen.js.map
|