quicktype-core 7.0.8 → 7.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/language/Python.d.ts +0 -3
- package/dist/language/Python.js +49 -45
- package/package.json +2 -2
|
@@ -7,9 +7,7 @@ import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer"
|
|
|
7
7
|
import { Namer, Name, DependencyName } from "../Naming";
|
|
8
8
|
import { Sourcelike, MultiWord } from "../Source";
|
|
9
9
|
import { Transformer } from "../Transformers";
|
|
10
|
-
export declare type PythonVersion = 2 | 3;
|
|
11
10
|
export declare type PythonFeatures = {
|
|
12
|
-
version: 2 | 3;
|
|
13
11
|
typeHints: boolean;
|
|
14
12
|
dataClasses: boolean;
|
|
15
13
|
};
|
|
@@ -59,7 +57,6 @@ export declare class PythonRenderer extends ConvenienceRenderer {
|
|
|
59
57
|
protected emitClass(t: ClassType): void;
|
|
60
58
|
protected emitEnum(t: EnumType): void;
|
|
61
59
|
protected emitImports(): void;
|
|
62
|
-
protected emitDefaultLeadingComments(): void;
|
|
63
60
|
protected emitSupportCode(): void;
|
|
64
61
|
protected emitClosingCode(): void;
|
|
65
62
|
protected emitSourceStructure(_givenOutputFilename: string): void;
|
package/dist/language/Python.js
CHANGED
|
@@ -72,13 +72,12 @@ const forbiddenPropertyNames = [
|
|
|
72
72
|
];
|
|
73
73
|
exports.pythonOptions = {
|
|
74
74
|
features: new RendererOptions_1.EnumOption("python-version", "Python version", [
|
|
75
|
-
["
|
|
76
|
-
["3.
|
|
77
|
-
["3.
|
|
78
|
-
["3.7", { version: 3, typeHints: true, dataClasses: true }]
|
|
75
|
+
["3.5", { typeHints: false, dataClasses: false }],
|
|
76
|
+
["3.6", { typeHints: true, dataClasses: false }],
|
|
77
|
+
["3.7", { typeHints: true, dataClasses: true }]
|
|
79
78
|
], "3.6"),
|
|
80
79
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Classes only", false),
|
|
81
|
-
nicePropertyNames: new RendererOptions_1.BooleanOption("nice-property-names", "Transform property names to be Pythonic", true)
|
|
80
|
+
nicePropertyNames: new RendererOptions_1.BooleanOption("nice-property-names", "Transform property names to be Pythonic", true)
|
|
82
81
|
};
|
|
83
82
|
class PythonTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
84
83
|
getOptions() {
|
|
@@ -118,12 +117,6 @@ class PythonTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
119
|
exports.PythonTargetLanguage = PythonTargetLanguage;
|
|
121
|
-
function isStartCharacter2(utf16Unit) {
|
|
122
|
-
return Strings_1.isAscii(utf16Unit) && Strings_1.isLetter(utf16Unit);
|
|
123
|
-
}
|
|
124
|
-
function isPartCharacter2(utf16Unit) {
|
|
125
|
-
return Strings_1.isAscii(utf16Unit) && Strings_1.isLetterOrUnderscoreOrDigit(utf16Unit);
|
|
126
|
-
}
|
|
127
120
|
function isNormalizedStartCharacter3(utf16Unit) {
|
|
128
121
|
// FIXME: add Other_ID_Start - https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
|
129
122
|
const category = unicode.getCategory(utf16Unit);
|
|
@@ -156,11 +149,10 @@ function isPartCharacter3(utf16Unit) {
|
|
|
156
149
|
}
|
|
157
150
|
return true;
|
|
158
151
|
}
|
|
159
|
-
const legalizeName2 = Strings_1.utf16LegalizeCharacters(isPartCharacter2);
|
|
160
152
|
const legalizeName3 = Strings_1.utf16LegalizeCharacters(isPartCharacter3);
|
|
161
|
-
function classNameStyle(
|
|
153
|
+
function classNameStyle(original) {
|
|
162
154
|
const words = Strings_1.splitIntoWords(original);
|
|
163
|
-
return Strings_1.combineWords(words,
|
|
155
|
+
return Strings_1.combineWords(words, legalizeName3, Strings_1.firstUpperWordStyle, Strings_1.firstUpperWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", isStartCharacter3);
|
|
164
156
|
}
|
|
165
157
|
function getWordStyle(uppercase, forceSnakeNameStyle) {
|
|
166
158
|
if (!forceSnakeNameStyle) {
|
|
@@ -168,11 +160,11 @@ function getWordStyle(uppercase, forceSnakeNameStyle) {
|
|
|
168
160
|
}
|
|
169
161
|
return uppercase ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle;
|
|
170
162
|
}
|
|
171
|
-
function snakeNameStyle(
|
|
163
|
+
function snakeNameStyle(original, uppercase, forceSnakeNameStyle) {
|
|
172
164
|
const wordStyle = getWordStyle(uppercase, forceSnakeNameStyle);
|
|
173
165
|
const separator = forceSnakeNameStyle ? "_" : "";
|
|
174
166
|
const words = Strings_1.splitIntoWords(original);
|
|
175
|
-
return Strings_1.combineWords(words,
|
|
167
|
+
return Strings_1.combineWords(words, legalizeName3, wordStyle, wordStyle, wordStyle, wordStyle, separator, isStartCharacter3);
|
|
176
168
|
}
|
|
177
169
|
class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
178
170
|
constructor(targetLanguage, renderContext, pyOptions) {
|
|
@@ -188,16 +180,16 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
188
180
|
return { names: forbiddenPropertyNames, includeGlobalForbidden: false };
|
|
189
181
|
}
|
|
190
182
|
makeNamedTypeNamer() {
|
|
191
|
-
return Naming_1.funPrefixNamer("type",
|
|
183
|
+
return Naming_1.funPrefixNamer("type", classNameStyle);
|
|
192
184
|
}
|
|
193
185
|
namerForObjectProperty() {
|
|
194
|
-
return Naming_1.funPrefixNamer("property", s => snakeNameStyle(
|
|
186
|
+
return Naming_1.funPrefixNamer("property", s => snakeNameStyle(s, false, this.pyOptions.nicePropertyNames));
|
|
195
187
|
}
|
|
196
188
|
makeUnionMemberNamer() {
|
|
197
189
|
return null;
|
|
198
190
|
}
|
|
199
191
|
makeEnumCaseNamer() {
|
|
200
|
-
return Naming_1.funPrefixNamer("enum-case", s => snakeNameStyle(
|
|
192
|
+
return Naming_1.funPrefixNamer("enum-case", s => snakeNameStyle(s, true, this.pyOptions.nicePropertyNames));
|
|
201
193
|
}
|
|
202
194
|
get commentLineStart() {
|
|
203
195
|
return "# ";
|
|
@@ -222,7 +214,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
222
214
|
this.indent(f);
|
|
223
215
|
}
|
|
224
216
|
string(s) {
|
|
225
|
-
const openQuote =
|
|
217
|
+
const openQuote = '"';
|
|
226
218
|
return [openQuote, Strings_1.stringEscape(s), '"'];
|
|
227
219
|
}
|
|
228
220
|
withImport(module, name) {
|
|
@@ -255,7 +247,13 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
255
247
|
rest.push(" = None");
|
|
256
248
|
if (nonNulls.size > 1) {
|
|
257
249
|
this.withImport("typing", "Union");
|
|
258
|
-
return [
|
|
250
|
+
return [
|
|
251
|
+
this.withTyping("Optional"),
|
|
252
|
+
"[Union[",
|
|
253
|
+
collection_utils_1.arrayIntercalate(", ", memberTypes),
|
|
254
|
+
"]]",
|
|
255
|
+
...rest
|
|
256
|
+
];
|
|
259
257
|
}
|
|
260
258
|
else {
|
|
261
259
|
return [this.withTyping("Optional"), "[", Support_1.defined(collection_utils_1.iterableFirst(memberTypes)), "]", ...rest];
|
|
@@ -362,20 +360,6 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
362
360
|
this.emitLine("from ", module, " import ", Array.from(names).join(", "));
|
|
363
361
|
});
|
|
364
362
|
}
|
|
365
|
-
emitDefaultLeadingComments() {
|
|
366
|
-
if (this.pyOptions.features.version === 2) {
|
|
367
|
-
this.emitCommentLines(["coding: utf-8"]);
|
|
368
|
-
this.ensureBlankLine();
|
|
369
|
-
if (this.haveEnums) {
|
|
370
|
-
this.emitCommentLines([
|
|
371
|
-
"",
|
|
372
|
-
"To use this code in Python 2.7 you'll have to",
|
|
373
|
-
"",
|
|
374
|
-
" pip install enum34"
|
|
375
|
-
]);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
363
|
emitSupportCode() {
|
|
380
364
|
return;
|
|
381
365
|
}
|
|
@@ -393,9 +377,6 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
393
377
|
if (this.leadingComments !== undefined) {
|
|
394
378
|
this.emitCommentLines(this.leadingComments);
|
|
395
379
|
}
|
|
396
|
-
else {
|
|
397
|
-
this.emitDefaultLeadingComments();
|
|
398
|
-
}
|
|
399
380
|
this.ensureBlankLine();
|
|
400
381
|
this.emitImports();
|
|
401
382
|
this.ensureBlankLine(2);
|
|
@@ -472,7 +453,7 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
472
453
|
constructor() {
|
|
473
454
|
super(...arguments);
|
|
474
455
|
this._deserializerFunctions = new Set();
|
|
475
|
-
this._converterNamer = Naming_1.funPrefixNamer("converter", s => snakeNameStyle(
|
|
456
|
+
this._converterNamer = Naming_1.funPrefixNamer("converter", s => snakeNameStyle(s, false, this.pyOptions.nicePropertyNames));
|
|
476
457
|
this._topLevelConverterNames = new Map();
|
|
477
458
|
this._haveTypeVar = false;
|
|
478
459
|
this._haveEnumTypeVar = false;
|
|
@@ -542,7 +523,7 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
542
523
|
}
|
|
543
524
|
emitStrConverter() {
|
|
544
525
|
this.emitBlock(["def from_str(", this.typingDecl("x", "Any"), ")", this.typeHint(" -> str"), ":"], () => {
|
|
545
|
-
const strType =
|
|
526
|
+
const strType = "str";
|
|
546
527
|
this.emitLine("assert isinstance(x, ", strType, ")");
|
|
547
528
|
this.emitLine("return x");
|
|
548
529
|
});
|
|
@@ -725,7 +706,14 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
725
706
|
};
|
|
726
707
|
if (xfer instanceof Transformers_1.DecodingChoiceTransformer || xfer instanceof Transformers_1.ChoiceTransformer) {
|
|
727
708
|
const lambdas = xfer.transformers.map(x => makeLambda(this.transformer(identity, x, targetType)).source);
|
|
728
|
-
return compose(inputTransformer, v => [
|
|
709
|
+
return compose(inputTransformer, v => [
|
|
710
|
+
this.conv("union"),
|
|
711
|
+
"([",
|
|
712
|
+
collection_utils_1.arrayIntercalate(", ", lambdas),
|
|
713
|
+
"], ",
|
|
714
|
+
v,
|
|
715
|
+
")"
|
|
716
|
+
]);
|
|
729
717
|
}
|
|
730
718
|
else if (xfer instanceof Transformers_1.DecodingTransformer) {
|
|
731
719
|
const consumer = xfer.consumer;
|
|
@@ -811,7 +799,10 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
811
799
|
", ",
|
|
812
800
|
v,
|
|
813
801
|
")"
|
|
814
|
-
]), classType => compose(value, {
|
|
802
|
+
]), classType => compose(value, {
|
|
803
|
+
lambda: Source_1.singleWord(this.nameForNamedType(classType), ".from_dict"),
|
|
804
|
+
value: undefined
|
|
805
|
+
}), mapType => compose(value, v => [
|
|
815
806
|
this.conv("dict"),
|
|
816
807
|
"(",
|
|
817
808
|
makeLambda(this.deserializer(identity, mapType.values)).source,
|
|
@@ -821,7 +812,14 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
821
812
|
]), enumType => compose(value, { lambda: Source_1.singleWord(this.nameForNamedType(enumType)), value: undefined }), unionType => {
|
|
822
813
|
// FIXME: handle via transformers
|
|
823
814
|
const deserializers = Array.from(unionType.members).map(m => makeLambda(this.deserializer(identity, m)).source);
|
|
824
|
-
return compose(value, v => [
|
|
815
|
+
return compose(value, v => [
|
|
816
|
+
this.conv("union"),
|
|
817
|
+
"([",
|
|
818
|
+
collection_utils_1.arrayIntercalate(", ", deserializers),
|
|
819
|
+
"], ",
|
|
820
|
+
v,
|
|
821
|
+
")"
|
|
822
|
+
]);
|
|
825
823
|
}, transformedStringType => {
|
|
826
824
|
// FIXME: handle via transformers
|
|
827
825
|
if (transformedStringType.kind === "date-time") {
|
|
@@ -855,7 +853,14 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
855
853
|
")"
|
|
856
854
|
]), enumType => compose(value, v => [this.conv("to-enum"), "(", this.nameForNamedType(enumType), ", ", v, ")"]), unionType => {
|
|
857
855
|
const serializers = Array.from(unionType.members).map(m => makeLambda(this.serializer(identity, m)).source);
|
|
858
|
-
return compose(value, v => [
|
|
856
|
+
return compose(value, v => [
|
|
857
|
+
this.conv("union"),
|
|
858
|
+
"([",
|
|
859
|
+
collection_utils_1.arrayIntercalate(", ", serializers),
|
|
860
|
+
"], ",
|
|
861
|
+
v,
|
|
862
|
+
")"
|
|
863
|
+
]);
|
|
859
864
|
}, transformedStringType => {
|
|
860
865
|
if (transformedStringType.kind === "date-time") {
|
|
861
866
|
return compose(value, v => [v, ".isoformat()"]);
|
|
@@ -926,7 +931,6 @@ class JSONPythonRenderer extends PythonRenderer {
|
|
|
926
931
|
return [fromDict, toDict];
|
|
927
932
|
}
|
|
928
933
|
emitDefaultLeadingComments() {
|
|
929
|
-
super.emitDefaultLeadingComments();
|
|
930
934
|
this.ensureBlankLine();
|
|
931
935
|
if (this._haveDateutil) {
|
|
932
936
|
this.emitCommentLines([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quicktype-core",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.9",
|
|
4
4
|
"description": "The quicktype engine as a library",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"fs": false
|
|
46
46
|
},
|
|
47
47
|
"config": {
|
|
48
|
-
"commit": "
|
|
48
|
+
"commit": "316b5df7236a38c80f6d19bf5fbc19be3f3a07db"
|
|
49
49
|
}
|
|
50
50
|
}
|