quicktype 16.0.26 → 16.0.28
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/README.md +0 -20
- package/dist/cli/index.js +4 -1
- package/dist/quicktype-core/Transformers.js +3 -1
- package/dist/quicktype-core/input/JSONSchemaInput.js +8 -2
- package/dist/quicktype-core/language/All.js +1 -1
- package/dist/quicktype-core/language/CPlusPlus.js +53 -134
- package/dist/quicktype-core/language/CSharp.js +30 -37
- package/dist/quicktype-core/language/Elm.js +1 -4
- package/dist/quicktype-core/language/Golang.js +7 -7
- package/dist/quicktype-core/language/Haskell.js +15 -15
- package/dist/quicktype-core/language/Java.js +54 -51
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +11 -11
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +1196 -65
- package/dist/quicktype-core/language/Kotlin.js +5 -20
- package/dist/quicktype-core/language/Pike.js +2 -9
- package/dist/quicktype-core/language/Rust.js +11 -11
- package/dist/quicktype-core/language/TypeScriptFlow.js +1 -1
- package/package.json +93 -94
|
@@ -78,33 +78,30 @@ function csTypeForTransformedStringType(t) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
exports.cSharpOptions = {
|
|
81
|
-
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
|
|
82
|
-
["NewtonSoft", Framework.Newtonsoft],
|
|
83
|
-
["SystemTextJson", Framework.SystemTextJson]
|
|
84
|
-
], "NewtonSoft"),
|
|
81
|
+
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [["NewtonSoft", Framework.Newtonsoft], ["SystemTextJson", Framework.SystemTextJson]], "NewtonSoft"),
|
|
85
82
|
useList: new RendererOptions_1.EnumOption("array-type", "Use T[] or List<T>", [
|
|
86
83
|
["array", false],
|
|
87
|
-
["list", true]
|
|
84
|
+
["list", true],
|
|
88
85
|
]),
|
|
89
86
|
dense: new RendererOptions_1.EnumOption("density", "Property density", [
|
|
90
87
|
["normal", false],
|
|
91
|
-
["dense", true]
|
|
88
|
+
["dense", true],
|
|
92
89
|
], "normal", "secondary"),
|
|
93
90
|
// FIXME: Do this via a configurable named eventually.
|
|
94
91
|
namespace: new RendererOptions_1.StringOption("namespace", "Generated namespace", "NAME", "QuickType"),
|
|
95
92
|
version: new RendererOptions_1.EnumOption("csharp-version", "C# version", [
|
|
96
93
|
["5", 5],
|
|
97
|
-
["6", 6]
|
|
94
|
+
["6", 6],
|
|
98
95
|
], "6", "secondary"),
|
|
99
96
|
virtual: new RendererOptions_1.BooleanOption("virtual", "Generate virtual properties", false),
|
|
100
97
|
typeForAny: new RendererOptions_1.EnumOption("any-type", 'Type to use for "any"', [
|
|
101
98
|
["object", "object"],
|
|
102
|
-
["dynamic", "dynamic"]
|
|
99
|
+
["dynamic", "dynamic"],
|
|
103
100
|
], "object", "secondary"),
|
|
104
101
|
useDecimal: new RendererOptions_1.EnumOption("number-type", "Type to use for numbers", [
|
|
105
102
|
["double", false],
|
|
106
|
-
["decimal", true]
|
|
107
|
-
], "double", "secondary")
|
|
103
|
+
["decimal", true],
|
|
104
|
+
], "double", "secondary"),
|
|
108
105
|
};
|
|
109
106
|
class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
110
107
|
constructor() {
|
|
@@ -119,7 +116,7 @@ class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
119
116
|
exports.cSharpOptions.useList,
|
|
120
117
|
exports.cSharpOptions.useDecimal,
|
|
121
118
|
exports.cSharpOptions.typeForAny,
|
|
122
|
-
exports.cSharpOptions.virtual
|
|
119
|
+
exports.cSharpOptions.virtual,
|
|
123
120
|
];
|
|
124
121
|
}
|
|
125
122
|
get stringTypeMapping() {
|
|
@@ -203,9 +200,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
203
200
|
"Equals",
|
|
204
201
|
"GetType",
|
|
205
202
|
"MemberwiseClone",
|
|
206
|
-
"ReferenceEquals"
|
|
203
|
+
"ReferenceEquals",
|
|
207
204
|
],
|
|
208
|
-
includeGlobalForbidden: false
|
|
205
|
+
includeGlobalForbidden: false,
|
|
209
206
|
};
|
|
210
207
|
}
|
|
211
208
|
forbiddenForUnionMembers(_, unionNamed) {
|
|
@@ -242,7 +239,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
242
239
|
}
|
|
243
240
|
csType(t, follow = Transformers_1.followTargetType, withIssues = false) {
|
|
244
241
|
const actualType = follow(t);
|
|
245
|
-
return TypeUtils_1.matchType(actualType, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this._csOptions.typeForAny), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this._csOptions.typeForAny), _boolType => "bool", _integerType => "long", _doubleType => this.doubleType, _stringType => "string", arrayType => {
|
|
242
|
+
return TypeUtils_1.matchType(actualType, (_anyType) => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this._csOptions.typeForAny), (_nullType) => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this._csOptions.typeForAny), (_boolType) => "bool", (_integerType) => "long", (_doubleType) => this.doubleType, (_stringType) => "string", (arrayType) => {
|
|
246
243
|
const itemsType = this.csType(arrayType.items, follow, withIssues);
|
|
247
244
|
if (this._csOptions.useList) {
|
|
248
245
|
return ["System.Collections.Generic.List<", itemsType, ">"];
|
|
@@ -250,16 +247,12 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
250
247
|
else {
|
|
251
248
|
return [itemsType, "[]"];
|
|
252
249
|
}
|
|
253
|
-
}, classType => this.nameForNamedType(classType), mapType => [
|
|
254
|
-
"System.Collections.Generic.Dictionary<string, ",
|
|
255
|
-
this.csType(mapType.values, follow, withIssues),
|
|
256
|
-
">"
|
|
257
|
-
], enumType => this.nameForNamedType(enumType), unionType => {
|
|
250
|
+
}, (classType) => this.nameForNamedType(classType), (mapType) => ["System.Collections.Generic.Dictionary<string, ", this.csType(mapType.values, follow, withIssues), ">"], (enumType) => this.nameForNamedType(enumType), (unionType) => {
|
|
258
251
|
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
259
252
|
if (nullable !== null)
|
|
260
253
|
return this.nullableCSType(nullable, noFollow);
|
|
261
254
|
return this.nameForNamedType(unionType);
|
|
262
|
-
}, transformedStringType => csTypeForTransformedStringType(transformedStringType));
|
|
255
|
+
}, (transformedStringType) => csTypeForTransformedStringType(transformedStringType));
|
|
263
256
|
}
|
|
264
257
|
nullableCSType(t, follow = Transformers_1.followTargetType, withIssues = false) {
|
|
265
258
|
t = Transformers_1.followTargetType(t);
|
|
@@ -369,9 +362,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
369
362
|
this.emitLine("public ", csType, " ", fieldName, ";");
|
|
370
363
|
});
|
|
371
364
|
this.ensureBlankLine();
|
|
372
|
-
const nullTests = Array.from(nonNulls).map(t => [
|
|
365
|
+
const nullTests = Array.from(nonNulls).map((t) => [
|
|
373
366
|
this.nameForUnionMember(u, t),
|
|
374
|
-
" == null"
|
|
367
|
+
" == null",
|
|
375
368
|
]);
|
|
376
369
|
this.ensureBlankLine();
|
|
377
370
|
this.forEachUnionMember(u, nonNulls, "none", null, (fieldName, t) => {
|
|
@@ -385,7 +378,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
385
378
|
}
|
|
386
379
|
emitEnumDefinition(e, enumName) {
|
|
387
380
|
const caseNames = [];
|
|
388
|
-
this.forEachEnumCase(e, "none", name => {
|
|
381
|
+
this.forEachEnumCase(e, "none", (name) => {
|
|
389
382
|
if (caseNames.length > 0)
|
|
390
383
|
caseNames.push(", ");
|
|
391
384
|
caseNames.push(name);
|
|
@@ -482,13 +475,13 @@ exports.newtonsoftCSharpOptions = Object.assign({}, exports.cSharpOptions, {
|
|
|
482
475
|
["complete", { namespaces: true, helpers: true, attributes: true }],
|
|
483
476
|
["attributes-only", { namespaces: true, helpers: false, attributes: true }],
|
|
484
477
|
["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
|
|
485
|
-
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
478
|
+
["just-types", { namespaces: true, helpers: false, attributes: false }],
|
|
486
479
|
]),
|
|
487
480
|
baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
|
|
488
481
|
["EntityData", "EntityData"],
|
|
489
|
-
["Object", undefined]
|
|
482
|
+
["Object", undefined],
|
|
490
483
|
], "Object", "secondary"),
|
|
491
|
-
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
484
|
+
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false),
|
|
492
485
|
});
|
|
493
486
|
class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
494
487
|
constructor(targetLanguage, renderContext, _options) {
|
|
@@ -511,7 +504,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
511
504
|
"MetadataPropertyHandling",
|
|
512
505
|
"DateParseHandling",
|
|
513
506
|
"FromJson",
|
|
514
|
-
"Required"
|
|
507
|
+
"Required",
|
|
515
508
|
];
|
|
516
509
|
if (this._options.dense) {
|
|
517
510
|
forbidden.push("J", "R", "N");
|
|
@@ -534,12 +527,12 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
534
527
|
}
|
|
535
528
|
return new Naming_1.SimpleName([`${xfer.kind}_converter`], namingFunction, ConvenienceRenderer_1.inferredNameOrder + 30);
|
|
536
529
|
}
|
|
537
|
-
return new Naming_1.DependencyName(namingFunction, typeName.order + 30, lookup => `${lookup(typeName)}_converter`);
|
|
530
|
+
return new Naming_1.DependencyName(namingFunction, typeName.order + 30, (lookup) => `${lookup(typeName)}_converter`);
|
|
538
531
|
}
|
|
539
532
|
makeNamedTypeDependencyNames(t, name) {
|
|
540
533
|
if (!(t instanceof Type_1.EnumType))
|
|
541
534
|
return [];
|
|
542
|
-
const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30, lookup => `${lookup(name)}_extensions`);
|
|
535
|
+
const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30, (lookup) => `${lookup(name)}_extensions`);
|
|
543
536
|
this._enumExtensionsNames.set(name, extensionsName);
|
|
544
537
|
return [extensionsName];
|
|
545
538
|
}
|
|
@@ -679,7 +672,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
679
672
|
// Sometimes multiple top-levels will resolve to the same type, so we have to take care
|
|
680
673
|
// not to emit more than one extension method for the same type.
|
|
681
674
|
const seenTypes = new Set();
|
|
682
|
-
this.forEachTopLevel("none", t => {
|
|
675
|
+
this.forEachTopLevel("none", (t) => {
|
|
683
676
|
// FIXME: Make ToJson a Named
|
|
684
677
|
if (!seenTypes.has(t)) {
|
|
685
678
|
seenTypes.add(t);
|
|
@@ -772,7 +765,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
772
765
|
this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
|
|
773
766
|
this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
|
|
774
767
|
this.emitBlock(() => {
|
|
775
|
-
this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, v => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem");
|
|
768
|
+
this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, (v) => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem");
|
|
776
769
|
// FIXME: handle EOF
|
|
777
770
|
this.emitLine("reader.Read();");
|
|
778
771
|
});
|
|
@@ -826,7 +819,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
826
819
|
}
|
|
827
820
|
if (xfer instanceof Transformers_1.ChoiceTransformer) {
|
|
828
821
|
const caseXfers = xfer.transformers;
|
|
829
|
-
if (caseXfers.length > 1 && caseXfers.every(caseXfer => caseXfer instanceof Transformers_1.StringMatchTransformer)) {
|
|
822
|
+
if (caseXfers.length > 1 && caseXfers.every((caseXfer) => caseXfer instanceof Transformers_1.StringMatchTransformer)) {
|
|
830
823
|
this.emitLine("switch (", variable, ")");
|
|
831
824
|
this.emitBlock(() => {
|
|
832
825
|
for (const caseXfer of caseXfers) {
|
|
@@ -1044,7 +1037,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
1044
1037
|
if (haveNullable && !(targetType instanceof Type_1.UnionType)) {
|
|
1045
1038
|
this.emitLine("if (reader.TokenType == JsonToken.Null) return null;");
|
|
1046
1039
|
}
|
|
1047
|
-
const allHandled = this.emitDecodeTransformer(xfer, targetType, v => this.emitLine("return ", v, ";"));
|
|
1040
|
+
const allHandled = this.emitDecodeTransformer(xfer, targetType, (v) => this.emitLine("return ", v, ";"));
|
|
1048
1041
|
if (!allHandled) {
|
|
1049
1042
|
this.emitThrow(['"Cannot unmarshal type ', csType, '"']);
|
|
1050
1043
|
}
|
|
@@ -1091,13 +1084,13 @@ exports.systemTextJsonCSharpOptions = Object.assign({}, exports.cSharpOptions, {
|
|
|
1091
1084
|
["complete", { namespaces: true, helpers: true, attributes: true }],
|
|
1092
1085
|
["attributes-only", { namespaces: true, helpers: false, attributes: true }],
|
|
1093
1086
|
["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
|
|
1094
|
-
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
1087
|
+
["just-types", { namespaces: true, helpers: false, attributes: false }],
|
|
1095
1088
|
]),
|
|
1096
1089
|
baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
|
|
1097
1090
|
["EntityData", "EntityData"],
|
|
1098
|
-
["Object", undefined]
|
|
1091
|
+
["Object", undefined],
|
|
1099
1092
|
], "Object", "secondary"),
|
|
1100
|
-
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
1093
|
+
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false),
|
|
1101
1094
|
});
|
|
1102
1095
|
class SystemTextJsonCSharpRenderer extends CSharpRenderer {
|
|
1103
1096
|
constructor(targetLanguage, renderContext, _options) {
|
|
@@ -1574,7 +1567,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer {
|
|
|
1574
1567
|
this.emitBlock(() => {
|
|
1575
1568
|
// this.emitLine("var uri = new Uri(", variable, ");");
|
|
1576
1569
|
// The default value about:blank should never happen, but this way we avoid a null reference warning.
|
|
1577
|
-
this.emitLine(
|
|
1570
|
+
this.emitLine("var uri = new Uri(\"about:blank\");");
|
|
1578
1571
|
this.emitLine("if (!string.IsNullOrEmpty(stringValue))");
|
|
1579
1572
|
this.emitBlock(() => {
|
|
1580
1573
|
this.emitLine("uri = new Uri(", variable, ");");
|
|
@@ -13,10 +13,7 @@ const Source_1 = require("../Source");
|
|
|
13
13
|
const Annotation_1 = require("../Annotation");
|
|
14
14
|
exports.elmOptions = {
|
|
15
15
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
16
|
-
useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [
|
|
17
|
-
["array", false],
|
|
18
|
-
["list", true]
|
|
19
|
-
]),
|
|
16
|
+
useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [["array", false], ["list", true]]),
|
|
20
17
|
// FIXME: Do this via a configurable named eventually.
|
|
21
18
|
moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType")
|
|
22
19
|
};
|
|
@@ -14,7 +14,7 @@ exports.goOptions = {
|
|
|
14
14
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
15
15
|
justTypesAndPackage: new RendererOptions_1.BooleanOption("just-types-and-package", "Plain types with package only", false),
|
|
16
16
|
packageName: new RendererOptions_1.StringOption("package", "Generated package name", "NAME", "main"),
|
|
17
|
-
multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Go file", false)
|
|
17
|
+
multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Go file", false),
|
|
18
18
|
};
|
|
19
19
|
class GoTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
20
20
|
constructor() {
|
|
@@ -82,7 +82,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
82
82
|
return true;
|
|
83
83
|
}
|
|
84
84
|
makeTopLevelDependencyNames(_, topLevelName) {
|
|
85
|
-
const unmarshalName = new Naming_1.DependencyName(namingFunction, topLevelName.order, lookup => `unmarshal_${lookup(topLevelName)}`);
|
|
85
|
+
const unmarshalName = new Naming_1.DependencyName(namingFunction, topLevelName.order, (lookup) => `unmarshal_${lookup(topLevelName)}`);
|
|
86
86
|
this._topLevelUnmarshalNames.set(topLevelName, unmarshalName);
|
|
87
87
|
return [unmarshalName];
|
|
88
88
|
}
|
|
@@ -135,7 +135,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
135
135
|
return this.goType(t, true);
|
|
136
136
|
}
|
|
137
137
|
goType(t, withIssues = false) {
|
|
138
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "interface{}"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "interface{}"), _boolType => "bool", _integerType => "int64", _doubleType => "float64", _stringType => "string", arrayType => ["[]", this.goType(arrayType.items, withIssues)], classType => this.nameForNamedType(classType), mapType => {
|
|
138
|
+
return TypeUtils_1.matchType(t, (_anyType) => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "interface{}"), (_nullType) => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "interface{}"), (_boolType) => "bool", (_integerType) => "int64", (_doubleType) => "float64", (_stringType) => "string", (arrayType) => ["[]", this.goType(arrayType.items, withIssues)], (classType) => this.nameForNamedType(classType), (mapType) => {
|
|
139
139
|
let valueSource;
|
|
140
140
|
const v = mapType.values;
|
|
141
141
|
if (v instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(v) === null) {
|
|
@@ -145,7 +145,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
145
145
|
valueSource = this.goType(v, withIssues);
|
|
146
146
|
}
|
|
147
147
|
return ["map[string]", valueSource];
|
|
148
|
-
}, enumType => this.nameForNamedType(enumType), unionType => {
|
|
148
|
+
}, (enumType) => this.nameForNamedType(enumType), (unionType) => {
|
|
149
149
|
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
150
150
|
if (nullable !== null)
|
|
151
151
|
return this.nullableGoType(nullable, withIssues);
|
|
@@ -254,7 +254,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
254
254
|
ifMember("class", undefined, (_1, _2, goType) => {
|
|
255
255
|
this.emitLine("var c ", goType);
|
|
256
256
|
});
|
|
257
|
-
const args = makeArgs(fn => ["&x.", fn], (isClass, fn) => {
|
|
257
|
+
const args = makeArgs((fn) => ["&x.", fn], (isClass, fn) => {
|
|
258
258
|
if (isClass) {
|
|
259
259
|
return "true, &c";
|
|
260
260
|
}
|
|
@@ -275,7 +275,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
275
275
|
});
|
|
276
276
|
this.ensureBlankLine();
|
|
277
277
|
this.emitFunc(["(x *", unionName, ") MarshalJSON() ([]byte, error)"], () => {
|
|
278
|
-
const args = makeArgs(fn => ["x.", fn], (_, fn) => ["x.", fn, " != nil, x.", fn]);
|
|
278
|
+
const args = makeArgs((fn) => ["x.", fn], (_, fn) => ["x.", fn, " != nil, x.", fn]);
|
|
279
279
|
this.emitLine("return marshalUnion(", args, ")");
|
|
280
280
|
});
|
|
281
281
|
this.endFile();
|
|
@@ -442,7 +442,7 @@ func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool,
|
|
|
442
442
|
this.leadingComments === undefined) {
|
|
443
443
|
this.emitSingleFileHeaderComments();
|
|
444
444
|
}
|
|
445
|
-
this.forEachTopLevel("leading-and-interposing", (t, name) => this.emitTopLevel(t, name), t => !(this._options.justTypes || this._options.justTypesAndPackage) ||
|
|
445
|
+
this.forEachTopLevel("leading-and-interposing", (t, name) => this.emitTopLevel(t, name), (t) => !(this._options.justTypes || this._options.justTypesAndPackage) ||
|
|
446
446
|
this.namedTypeToNameForTopLevel(t) === undefined);
|
|
447
447
|
this.forEachObject("leading-and-interposing", (c, className) => this.emitClass(c, className));
|
|
448
448
|
this.forEachEnum("leading-and-interposing", (u, enumName) => this.emitEnum(u, enumName));
|
|
@@ -12,9 +12,9 @@ exports.haskellOptions = {
|
|
|
12
12
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
13
13
|
useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [
|
|
14
14
|
["array", false],
|
|
15
|
-
["list", true]
|
|
15
|
+
["list", true],
|
|
16
16
|
]),
|
|
17
|
-
moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType")
|
|
17
|
+
moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType"),
|
|
18
18
|
};
|
|
19
19
|
class HaskellTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
20
20
|
constructor() {
|
|
@@ -86,15 +86,15 @@ const forbiddenNames = [
|
|
|
86
86
|
"Object",
|
|
87
87
|
"Result",
|
|
88
88
|
"Series",
|
|
89
|
-
"Error"
|
|
89
|
+
"Error",
|
|
90
90
|
];
|
|
91
|
-
const legalizeName = Strings_1.legalizeCharacters(cp => Strings_1.isAscii(cp) && Strings_1.isLetterOrUnderscoreOrDigit(cp));
|
|
91
|
+
const legalizeName = Strings_1.legalizeCharacters((cp) => Strings_1.isAscii(cp) && Strings_1.isLetterOrUnderscoreOrDigit(cp));
|
|
92
92
|
function haskellNameStyle(original, upper) {
|
|
93
93
|
const words = Strings_1.splitIntoWords(original);
|
|
94
94
|
return Strings_1.combineWords(words, legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
95
95
|
}
|
|
96
|
-
const upperNamingFunction = Naming_1.funPrefixNamer("upper", n => haskellNameStyle(n, true));
|
|
97
|
-
const lowerNamingFunction = Naming_1.funPrefixNamer("lower", n => haskellNameStyle(n, false));
|
|
96
|
+
const upperNamingFunction = Naming_1.funPrefixNamer("upper", (n) => haskellNameStyle(n, true));
|
|
97
|
+
const lowerNamingFunction = Naming_1.funPrefixNamer("lower", (n) => haskellNameStyle(n, false));
|
|
98
98
|
class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
99
99
|
constructor(targetLanguage, renderContext, _options) {
|
|
100
100
|
super(targetLanguage, renderContext);
|
|
@@ -140,12 +140,12 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
haskellType(t, noOptional = false) {
|
|
143
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.multiWord(" ", "Maybe", "Text"), _nullType => Source_1.multiWord(" ", "Maybe", "Text"), _boolType => Source_1.singleWord("Bool"), _integerType => Source_1.singleWord("Int"), _doubleType => Source_1.singleWord("Float"), _stringType => Source_1.singleWord("Text"), arrayType => {
|
|
143
|
+
return TypeUtils_1.matchType(t, (_anyType) => Source_1.multiWord(" ", "Maybe", "Text"), (_nullType) => Source_1.multiWord(" ", "Maybe", "Text"), (_boolType) => Source_1.singleWord("Bool"), (_integerType) => Source_1.singleWord("Int"), (_doubleType) => Source_1.singleWord("Float"), (_stringType) => Source_1.singleWord("Text"), (arrayType) => {
|
|
144
144
|
if (this._options.useList) {
|
|
145
145
|
return Source_1.multiWord("", "[", Source_1.parenIfNeeded(this.haskellType(arrayType.items)), "]");
|
|
146
146
|
}
|
|
147
147
|
return Source_1.multiWord(" ", "Vector", Source_1.parenIfNeeded(this.haskellType(arrayType.items)));
|
|
148
|
-
}, classType => Source_1.singleWord(this.nameForNamedType(classType)), mapType => Source_1.multiWord(" ", "HashMap Text", Source_1.parenIfNeeded(this.haskellType(mapType.values))), enumType => Source_1.singleWord(this.nameForNamedType(enumType)), unionType => {
|
|
148
|
+
}, (classType) => Source_1.singleWord(this.nameForNamedType(classType)), (mapType) => Source_1.multiWord(" ", "HashMap Text", Source_1.parenIfNeeded(this.haskellType(mapType.values))), (enumType) => Source_1.singleWord(this.nameForNamedType(enumType)), (unionType) => {
|
|
149
149
|
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
150
150
|
if (nullable !== null) {
|
|
151
151
|
const nullableType = this.haskellType(nullable);
|
|
@@ -204,7 +204,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
204
204
|
this.emitLine("data ", enumName);
|
|
205
205
|
this.indent(() => {
|
|
206
206
|
let onFirst = true;
|
|
207
|
-
this.forEachEnumCase(e, "none", name => {
|
|
207
|
+
this.forEachEnumCase(e, "none", (name) => {
|
|
208
208
|
const equalsOrPipe = onFirst ? "=" : "|";
|
|
209
209
|
this.emitLine(equalsOrPipe, " ", name, enumName);
|
|
210
210
|
onFirst = false;
|
|
@@ -243,7 +243,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
243
243
|
}
|
|
244
244
|
emitClassEncoderInstance(c, className) {
|
|
245
245
|
let classProperties = [];
|
|
246
|
-
this.forEachClassProperty(c, "none", name => {
|
|
246
|
+
this.forEachClassProperty(c, "none", (name) => {
|
|
247
247
|
classProperties.push(" ");
|
|
248
248
|
classProperties.push(name);
|
|
249
249
|
classProperties.push(className);
|
|
@@ -259,7 +259,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
259
259
|
this.emitLine("object");
|
|
260
260
|
let onFirst = true;
|
|
261
261
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
262
|
-
this.emitLine(onFirst ? "[ " : ", ",
|
|
262
|
+
this.emitLine(onFirst ? "[ " : ", ", "\"", Strings_1.stringEscape(jsonName), "\" .= ", name, className);
|
|
263
263
|
onFirst = false;
|
|
264
264
|
});
|
|
265
265
|
if (onFirst) {
|
|
@@ -282,7 +282,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
282
282
|
let onFirst = true;
|
|
283
283
|
this.forEachClassProperty(c, "none", (_, jsonName, p) => {
|
|
284
284
|
const operator = p.isOptional ? ".:?" : ".:";
|
|
285
|
-
this.emitLine(onFirst ? "<$> " : "<*> ", "v ", operator,
|
|
285
|
+
this.emitLine(onFirst ? "<$> " : "<*> ", "v ", operator, " \"", Strings_1.stringEscape(jsonName), "\"");
|
|
286
286
|
onFirst = false;
|
|
287
287
|
});
|
|
288
288
|
});
|
|
@@ -298,19 +298,19 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
298
298
|
this.emitLine("instance ToJSON ", enumName, " where");
|
|
299
299
|
this.indent(() => {
|
|
300
300
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
301
|
-
this.emitLine("toJSON ", name, enumName,
|
|
301
|
+
this.emitLine("toJSON ", name, enumName, " = \"", Strings_1.stringEscape(jsonName), "\"");
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
emitEnumDecoderInstance(e, enumName) {
|
|
306
306
|
this.emitLine("instance FromJSON ", enumName, " where");
|
|
307
307
|
this.indent(() => {
|
|
308
|
-
this.emitLine(
|
|
308
|
+
this.emitLine("parseJSON = withText \"", enumName, "\" parseText");
|
|
309
309
|
this.indent(() => {
|
|
310
310
|
this.emitLine("where");
|
|
311
311
|
this.indent(() => {
|
|
312
312
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
313
|
-
this.emitLine(
|
|
313
|
+
this.emitLine("parseText \"", Strings_1.stringEscape(jsonName), "\" = return ", name, enumName);
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
316
|
});
|