quicktype-core 7.0.10 → 7.0.11
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/Transformers.js +1 -3
- package/dist/input/JSONSchemaInput.js +2 -8
- package/dist/language/All.js +1 -1
- package/dist/language/CPlusPlus.js +134 -53
- package/dist/language/CSharp.js +37 -30
- package/dist/language/Elm.js +4 -1
- package/dist/language/Golang.js +7 -7
- package/dist/language/Haskell.js +15 -15
- package/dist/language/Java.js +51 -54
- package/dist/language/JavaScriptPropTypes.js +11 -11
- package/dist/language/JavaScriptUnicodeMaps.js +65 -1196
- package/dist/language/Kotlin.js +20 -5
- package/dist/language/Pike.js +9 -2
- package/dist/language/Rust.js +11 -11
- package/dist/language/TypeScriptFlow.js +1 -1
- package/package.json +2 -2
package/dist/Transformers.js
CHANGED
|
@@ -731,9 +731,7 @@ class MinMaxValueTransformer extends ProducerTransformer {
|
|
|
731
731
|
equals(other) {
|
|
732
732
|
if (!super.equals(other))
|
|
733
733
|
return false;
|
|
734
|
-
return (other instanceof MinMaxValueTransformer &&
|
|
735
|
-
this.minimum === other.minimum &&
|
|
736
|
-
this.maximum === other.maximum);
|
|
734
|
+
return (other instanceof MinMaxValueTransformer && this.minimum === other.minimum && this.maximum === other.maximum);
|
|
737
735
|
}
|
|
738
736
|
}
|
|
739
737
|
exports.MinMaxValueTransformer = MinMaxValueTransformer;
|
|
@@ -80,10 +80,7 @@ function normalizeURI(uri) {
|
|
|
80
80
|
if (typeof uri === "string") {
|
|
81
81
|
uri = new URI(uri);
|
|
82
82
|
}
|
|
83
|
-
return new URI(URI.decode(uri
|
|
84
|
-
.clone()
|
|
85
|
-
.normalize()
|
|
86
|
-
.toString()));
|
|
83
|
+
return new URI(URI.decode(uri.clone().normalize().toString()));
|
|
87
84
|
}
|
|
88
85
|
class Ref {
|
|
89
86
|
constructor(addressURI, path) {
|
|
@@ -1020,10 +1017,7 @@ class JSONSchemaInput {
|
|
|
1020
1017
|
else {
|
|
1021
1018
|
normalizedURIs = uris.map(uri => {
|
|
1022
1019
|
const normalizedURI = normalizeURI(uri);
|
|
1023
|
-
if (normalizedURI
|
|
1024
|
-
.clone()
|
|
1025
|
-
.hash("")
|
|
1026
|
-
.toString() === "") {
|
|
1020
|
+
if (normalizedURI.clone().hash("").toString() === "") {
|
|
1027
1021
|
normalizedURI.path(name);
|
|
1028
1022
|
}
|
|
1029
1023
|
return normalizedURI;
|
package/dist/language/All.js
CHANGED
|
@@ -40,7 +40,7 @@ exports.all = [
|
|
|
40
40
|
new Dart_1.DartTargetLanguage(),
|
|
41
41
|
new Python_1.PythonTargetLanguage("Python", ["python", "py"], "py"),
|
|
42
42
|
new Pike_1.PikeTargetLanguage(),
|
|
43
|
-
new Haskell_1.HaskellTargetLanguage()
|
|
43
|
+
new Haskell_1.HaskellTargetLanguage()
|
|
44
44
|
];
|
|
45
45
|
function languageNamed(name, targetLanguages) {
|
|
46
46
|
if (targetLanguages === undefined) {
|
|
@@ -22,12 +22,30 @@ const upperUnderscoreValue = ["upper-underscore-case", "upper-underscore"];
|
|
|
22
22
|
const pascalUpperAcronymsValue = ["pascal-case-upper-acronyms", "pascal-upper-acronyms"];
|
|
23
23
|
const camelUpperAcronymsValue = ["camel-case-upper-acronyms", "camel-upper-acronyms"];
|
|
24
24
|
exports.cPlusPlusOptions = {
|
|
25
|
-
typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [
|
|
26
|
+
["single-source", true],
|
|
27
|
+
["multi-source", false]
|
|
28
|
+
], "single-source", "secondary"),
|
|
29
|
+
includeLocation: new RendererOptions_1.EnumOption("include-location", "Whether json.hpp is to be located globally or locally", [
|
|
30
|
+
["local-include", true],
|
|
31
|
+
["global-include", false]
|
|
32
|
+
], "local-include", "secondary"),
|
|
33
|
+
codeFormat: new RendererOptions_1.EnumOption("code-format", "Generate classes with getters/setters, instead of structs", [
|
|
34
|
+
["with-struct", false],
|
|
35
|
+
["with-getter-setter", true]
|
|
36
|
+
], "with-getter-setter"),
|
|
37
|
+
wstring: new RendererOptions_1.EnumOption("wstring", "Store strings using Utf-16 std::wstring, rather than Utf-8 std::string", [
|
|
38
|
+
["use-string", false],
|
|
39
|
+
["use-wstring", true]
|
|
40
|
+
], "use-string"),
|
|
41
|
+
msbuildPermissive: new RendererOptions_1.EnumOption("msbuildPermissive", "Moves to_json and from_json types into the nlohmann::details namespace, so that msbuild can build it with conformance mode disabled", [
|
|
42
|
+
["not-permissive", false],
|
|
43
|
+
["use-permissive", true]
|
|
44
|
+
], "not-permissive", "secondary"),
|
|
45
|
+
westConst: new RendererOptions_1.EnumOption("const-style", "Put const to the left/west (const T) or right/east (T const)", [
|
|
46
|
+
["west-const", true],
|
|
47
|
+
["east-const", false]
|
|
48
|
+
], "west-const"),
|
|
31
49
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
32
50
|
namespace: new RendererOptions_1.StringOption("namespace", "Name of the generated namespace(s)", "NAME", "quicktype"),
|
|
33
51
|
enumType: new RendererOptions_1.StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"),
|
|
@@ -56,7 +74,7 @@ exports.cPlusPlusOptions = {
|
|
|
56
74
|
camelUpperAcronymsValue
|
|
57
75
|
]),
|
|
58
76
|
boost: new RendererOptions_1.BooleanOption("boost", "Require a dependency on boost. Without boost, C++17 is required", true),
|
|
59
|
-
hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false)
|
|
77
|
+
hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false)
|
|
60
78
|
};
|
|
61
79
|
class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
62
80
|
constructor(displayName = "C++", names = ["c++", "cpp", "cplusplus"], extension = "cpp") {
|
|
@@ -77,7 +95,7 @@ class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
77
95
|
exports.cPlusPlusOptions.enumeratorNamingStyle,
|
|
78
96
|
exports.cPlusPlusOptions.enumType,
|
|
79
97
|
exports.cPlusPlusOptions.boost,
|
|
80
|
-
exports.cPlusPlusOptions.hideNullOptional
|
|
98
|
+
exports.cPlusPlusOptions.hideNullOptional
|
|
81
99
|
];
|
|
82
100
|
}
|
|
83
101
|
get supportsUnionsWithBothNumberTypes() {
|
|
@@ -304,7 +322,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
304
322
|
super(targetLanguage, renderContext);
|
|
305
323
|
this._options = _options;
|
|
306
324
|
this._gettersAndSettersForPropertyName = new Map();
|
|
307
|
-
this.NarrowString = new class extends BaseString {
|
|
325
|
+
this.NarrowString = new (class extends BaseString {
|
|
308
326
|
constructor() {
|
|
309
327
|
super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
|
|
310
328
|
}
|
|
@@ -314,8 +332,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
314
332
|
emitHelperFunctions() {
|
|
315
333
|
return;
|
|
316
334
|
}
|
|
317
|
-
}();
|
|
318
|
-
this.WideString = new class extends BaseString {
|
|
335
|
+
})();
|
|
336
|
+
this.WideString = new (class extends BaseString {
|
|
319
337
|
constructor(superThis) {
|
|
320
338
|
super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
|
|
321
339
|
this.superThis = superThis;
|
|
@@ -398,7 +416,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
398
416
|
});
|
|
399
417
|
this.superThis.ensureBlankLine();
|
|
400
418
|
}
|
|
401
|
-
}(this);
|
|
419
|
+
})(this);
|
|
402
420
|
this._enumType = _options.enumType;
|
|
403
421
|
this._namespaceNames = _options.namespace.split("::");
|
|
404
422
|
this.typeNamingStyle = _options.typeNamingStyle;
|
|
@@ -541,10 +559,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
541
559
|
this.emitCommentLines(this.leadingComments);
|
|
542
560
|
}
|
|
543
561
|
else if (!this._options.justTypes) {
|
|
544
|
-
this.emitCommentLines([
|
|
545
|
-
" To parse this JSON data, first install",
|
|
546
|
-
"",
|
|
547
|
-
]);
|
|
562
|
+
this.emitCommentLines([" To parse this JSON data, first install", ""]);
|
|
548
563
|
if (this._options.boost) {
|
|
549
564
|
this.emitCommentLines([" Boost http://www.boost.org"]);
|
|
550
565
|
}
|
|
@@ -664,10 +679,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
664
679
|
return [optionalType, "<", variant, ">"];
|
|
665
680
|
}
|
|
666
681
|
ourQualifier(inJsonNamespace) {
|
|
667
|
-
return
|
|
682
|
+
return inJsonNamespace || this._options.msbuildPermissive
|
|
683
|
+
? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"]
|
|
684
|
+
: [];
|
|
668
685
|
}
|
|
669
686
|
jsonQualifier(inJsonNamespace) {
|
|
670
|
-
return
|
|
687
|
+
return inJsonNamespace || this._options.msbuildPermissive ? [] : "nlohmann::";
|
|
671
688
|
}
|
|
672
689
|
variantIndirection(needIndirection, typeSrc) {
|
|
673
690
|
if (!needIndirection)
|
|
@@ -676,7 +693,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
676
693
|
}
|
|
677
694
|
cppType(t, ctx, withIssues, forceNarrowString, isOptional) {
|
|
678
695
|
const inJsonNamespace = ctx.inJsonNamespace;
|
|
679
|
-
if (isOptional && t instanceof Type_1.UnionType) {
|
|
696
|
+
if (isOptional && t instanceof Type_1.UnionType) {
|
|
697
|
+
// avoid have optionalType<optionalType<Type>>
|
|
680
698
|
for (const tChild of t.getChildren()) {
|
|
681
699
|
if (tChild.isNullable) {
|
|
682
700
|
isOptional = false;
|
|
@@ -686,10 +704,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
686
704
|
}
|
|
687
705
|
let typeSource = TypeUtils_1.matchType(t, _anyType => {
|
|
688
706
|
isOptional = false;
|
|
689
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [
|
|
707
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [
|
|
708
|
+
this.jsonQualifier(inJsonNamespace),
|
|
709
|
+
"json"
|
|
710
|
+
]);
|
|
690
711
|
}, _nullType => {
|
|
691
712
|
isOptional = false;
|
|
692
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [
|
|
713
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [
|
|
714
|
+
this.jsonQualifier(inJsonNamespace),
|
|
715
|
+
"json"
|
|
716
|
+
]);
|
|
693
717
|
}, _boolType => "bool", _integerType => "int64_t", _doubleType => "double", _stringType => {
|
|
694
718
|
if (forceNarrowString) {
|
|
695
719
|
return "std::string";
|
|
@@ -701,10 +725,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
701
725
|
"std::vector<",
|
|
702
726
|
this.cppType(arrayType.items, { needsForwardIndirection: false, needsOptionalIndirection: true, inJsonNamespace }, withIssues, forceNarrowString, false),
|
|
703
727
|
">"
|
|
704
|
-
], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [
|
|
705
|
-
this.ourQualifier(inJsonNamespace),
|
|
706
|
-
this.nameForNamedType(classType)
|
|
707
|
-
]), mapType => {
|
|
728
|
+
], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [this.ourQualifier(inJsonNamespace), this.nameForNamedType(classType)]), mapType => {
|
|
708
729
|
let keyType = this._stringType.getType();
|
|
709
730
|
if (forceNarrowString) {
|
|
710
731
|
keyType = "std::string";
|
|
@@ -725,12 +746,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
725
746
|
});
|
|
726
747
|
if (!isOptional)
|
|
727
748
|
return typeSource;
|
|
728
|
-
return [
|
|
729
|
-
optionalType,
|
|
730
|
-
"<",
|
|
731
|
-
typeSource,
|
|
732
|
-
">"
|
|
733
|
-
];
|
|
749
|
+
return [optionalType, "<", typeSource, ">"];
|
|
734
750
|
}
|
|
735
751
|
/**
|
|
736
752
|
* similar to cppType, it practically gathers all the generated types within
|
|
@@ -834,7 +850,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
834
850
|
* a member called 'value' value = value will screw up the compiler
|
|
835
851
|
*/
|
|
836
852
|
const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
|
|
837
|
-
if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) ||
|
|
853
|
+
if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) ||
|
|
854
|
+
(property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
|
|
838
855
|
this.emitLine(rendered, " ", getterName, "() const { return ", name, "; }");
|
|
839
856
|
if (constraints !== undefined && constraints.has(jsonName)) {
|
|
840
857
|
this.emitLine("void ", setterName, "(", rendered, " value) { if (value) ", checkConst, "(", this._stringType.createStringLiteral([name]), ", ", this.constraintMember(jsonName), ", *value); this->", name, " = value; }");
|
|
@@ -867,15 +884,26 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
867
884
|
res.set(jsonName, [
|
|
868
885
|
this.constraintMember(jsonName),
|
|
869
886
|
"(",
|
|
870
|
-
|
|
887
|
+
minMax !== undefined && minMax[0] !== undefined ? String(minMax[0]) : this._nulloptType,
|
|
871
888
|
", ",
|
|
872
|
-
|
|
889
|
+
minMax !== undefined && minMax[1] !== undefined ? String(minMax[1]) : this._nulloptType,
|
|
873
890
|
", ",
|
|
874
|
-
|
|
891
|
+
minMaxLength !== undefined && minMaxLength[0] !== undefined
|
|
892
|
+
? String(minMaxLength[0])
|
|
893
|
+
: this._nulloptType,
|
|
875
894
|
", ",
|
|
876
|
-
|
|
895
|
+
minMaxLength !== undefined && minMaxLength[1] !== undefined
|
|
896
|
+
? String(minMaxLength[1])
|
|
897
|
+
: this._nulloptType,
|
|
877
898
|
", ",
|
|
878
|
-
|
|
899
|
+
pattern === undefined
|
|
900
|
+
? this._nulloptType
|
|
901
|
+
: [
|
|
902
|
+
this._stringType.getType(),
|
|
903
|
+
"(",
|
|
904
|
+
this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]),
|
|
905
|
+
")"
|
|
906
|
+
],
|
|
879
907
|
")"
|
|
880
908
|
]);
|
|
881
909
|
});
|
|
@@ -936,7 +964,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
936
964
|
toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
|
|
937
965
|
this.emitLine([
|
|
938
966
|
"x = ",
|
|
939
|
-
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
967
|
+
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
968
|
+
"j.get<",
|
|
969
|
+
cppType,
|
|
970
|
+
">()"
|
|
971
|
+
]),
|
|
940
972
|
";"
|
|
941
973
|
]);
|
|
942
974
|
});
|
|
@@ -976,7 +1008,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
976
1008
|
return;
|
|
977
1009
|
}
|
|
978
1010
|
if (p.isOptional || t instanceof Type_1.UnionType) {
|
|
979
|
-
const [nullOrOptional, typeSet] = function () {
|
|
1011
|
+
const [nullOrOptional, typeSet] = (function () {
|
|
980
1012
|
if (t instanceof Type_1.UnionType) {
|
|
981
1013
|
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(t, true);
|
|
982
1014
|
return [maybeNull !== null || p.isOptional, nonNulls];
|
|
@@ -986,7 +1018,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
986
1018
|
set.add(t);
|
|
987
1019
|
return [true, set];
|
|
988
1020
|
}
|
|
989
|
-
}();
|
|
1021
|
+
})();
|
|
990
1022
|
if (nullOrOptional) {
|
|
991
1023
|
cppType = this.cppTypeInOptional(typeSet, {
|
|
992
1024
|
needsForwardIndirection: false,
|
|
@@ -1045,7 +1077,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1045
1077
|
";"
|
|
1046
1078
|
];
|
|
1047
1079
|
if (p.isOptional && this._options.hideNullOptional) {
|
|
1048
|
-
this.emitBlock([
|
|
1080
|
+
this.emitBlock([
|
|
1081
|
+
"if (",
|
|
1082
|
+
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
|
|
1083
|
+
")"
|
|
1084
|
+
], false, () => {
|
|
1049
1085
|
this.emitLine(assignment);
|
|
1050
1086
|
});
|
|
1051
1087
|
}
|
|
@@ -1159,7 +1195,14 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1159
1195
|
const ourQualifier = this.ourQualifier(true);
|
|
1160
1196
|
this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, enumName, " & x)"], false, () => {
|
|
1161
1197
|
if (this.isLargeEnum(e)) {
|
|
1162
|
-
this.emitBlock([
|
|
1198
|
+
this.emitBlock([
|
|
1199
|
+
"static std::unordered_map<",
|
|
1200
|
+
this._stringType.getType(),
|
|
1201
|
+
", ",
|
|
1202
|
+
ourQualifier,
|
|
1203
|
+
enumName,
|
|
1204
|
+
"> enumValues"
|
|
1205
|
+
], true, () => {
|
|
1163
1206
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1164
1207
|
this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), ", ", ourQualifier, enumName, "::", name, "},");
|
|
1165
1208
|
});
|
|
@@ -1306,7 +1349,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1306
1349
|
this.ensureBlankLine();
|
|
1307
1350
|
}
|
|
1308
1351
|
const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
|
|
1309
|
-
this.emitBlock([
|
|
1352
|
+
this.emitBlock([
|
|
1353
|
+
"inline void ",
|
|
1354
|
+
checkConst,
|
|
1355
|
+
"(",
|
|
1356
|
+
this._stringType.getConstType(),
|
|
1357
|
+
" name, ",
|
|
1358
|
+
this.withConst(classConstraint),
|
|
1359
|
+
" & c, int64_t value)"
|
|
1360
|
+
], false, () => {
|
|
1310
1361
|
this.emitBlock(["if (c.", getterMinValue, "() != ", this._nulloptType, " && value < *c.", getterMinValue, "())"], false, () => {
|
|
1311
1362
|
this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLowException), " (", this._stringType.createStringLiteral(["Value too low for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinValue, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
|
|
1312
1363
|
});
|
|
@@ -1317,12 +1368,38 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1317
1368
|
this.ensureBlankLine();
|
|
1318
1369
|
});
|
|
1319
1370
|
this.ensureBlankLine();
|
|
1320
|
-
this.emitBlock([
|
|
1321
|
-
|
|
1371
|
+
this.emitBlock([
|
|
1372
|
+
"inline void ",
|
|
1373
|
+
checkConst,
|
|
1374
|
+
"(",
|
|
1375
|
+
this._stringType.getConstType(),
|
|
1376
|
+
" name, ",
|
|
1377
|
+
this.withConst(classConstraint),
|
|
1378
|
+
" & c, ",
|
|
1379
|
+
this._stringType.getConstType(),
|
|
1380
|
+
" value)"
|
|
1381
|
+
], false, () => {
|
|
1382
|
+
this.emitBlock([
|
|
1383
|
+
"if (c.",
|
|
1384
|
+
getterMinLength,
|
|
1385
|
+
"() != ",
|
|
1386
|
+
this._nulloptType,
|
|
1387
|
+
" && value.length() < *c.",
|
|
1388
|
+
getterMinLength,
|
|
1389
|
+
"())"
|
|
1390
|
+
], false, () => {
|
|
1322
1391
|
this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooShortException), " (", this._stringType.createStringLiteral(["Value too short for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
|
|
1323
1392
|
});
|
|
1324
1393
|
this.ensureBlankLine();
|
|
1325
|
-
this.emitBlock([
|
|
1394
|
+
this.emitBlock([
|
|
1395
|
+
"if (c.",
|
|
1396
|
+
getterMaxLength,
|
|
1397
|
+
"() != ",
|
|
1398
|
+
this._nulloptType,
|
|
1399
|
+
" && value.length() > *c.",
|
|
1400
|
+
getterMaxLength,
|
|
1401
|
+
"())"
|
|
1402
|
+
], false, () => {
|
|
1326
1403
|
this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLongException), " (", this._stringType.createStringLiteral(["Value too long for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral([">"]), " + ", this._stringType.wrapToString(["*c.", getterMaxLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
|
|
1327
1404
|
});
|
|
1328
1405
|
this.ensureBlankLine();
|
|
@@ -1343,24 +1420,28 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1343
1420
|
this.emitConstraintClasses();
|
|
1344
1421
|
this.ensureBlankLine();
|
|
1345
1422
|
}
|
|
1346
|
-
this.emitBlock([
|
|
1347
|
-
"inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"
|
|
1348
|
-
], false, () => {
|
|
1423
|
+
this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
|
|
1349
1424
|
this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
|
|
1350
1425
|
this.emitLine("return j.at(property).get<json>();");
|
|
1351
1426
|
});
|
|
1352
1427
|
this.emitLine("return json();");
|
|
1353
1428
|
});
|
|
1354
1429
|
this.ensureBlankLine();
|
|
1355
|
-
this.emitBlock([
|
|
1356
|
-
"inline json get_untyped(", this.withConst("json"), " & j, std::string property)"
|
|
1357
|
-
], false, () => {
|
|
1430
|
+
this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, std::string property)"], false, () => {
|
|
1358
1431
|
this.emitLine("return get_untyped(j, property.data());");
|
|
1359
1432
|
});
|
|
1360
1433
|
this.ensureBlankLine();
|
|
1361
1434
|
if (this.haveUnions || this.haveOptionalProperties) {
|
|
1362
1435
|
this.emitLine("template <typename T>");
|
|
1363
|
-
this.emitBlock([
|
|
1436
|
+
this.emitBlock([
|
|
1437
|
+
"inline ",
|
|
1438
|
+
optionalType,
|
|
1439
|
+
"<T> get_optional(",
|
|
1440
|
+
this.withConst("json"),
|
|
1441
|
+
" & j, ",
|
|
1442
|
+
this.withConst("char"),
|
|
1443
|
+
" * property)"
|
|
1444
|
+
], false, () => {
|
|
1364
1445
|
this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
|
|
1365
1446
|
this.emitLine("return j.at(property).get<", optionalType, "<T>>();");
|
|
1366
1447
|
});
|
package/dist/language/CSharp.js
CHANGED
|
@@ -78,30 +78,33 @@ function csTypeForTransformedStringType(t) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
exports.cSharpOptions = {
|
|
81
|
-
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
|
|
81
|
+
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
|
|
82
|
+
["NewtonSoft", Framework.Newtonsoft],
|
|
83
|
+
["SystemTextJson", Framework.SystemTextJson]
|
|
84
|
+
], "NewtonSoft"),
|
|
82
85
|
useList: new RendererOptions_1.EnumOption("array-type", "Use T[] or List<T>", [
|
|
83
86
|
["array", false],
|
|
84
|
-
["list", true]
|
|
87
|
+
["list", true]
|
|
85
88
|
]),
|
|
86
89
|
dense: new RendererOptions_1.EnumOption("density", "Property density", [
|
|
87
90
|
["normal", false],
|
|
88
|
-
["dense", true]
|
|
91
|
+
["dense", true]
|
|
89
92
|
], "normal", "secondary"),
|
|
90
93
|
// FIXME: Do this via a configurable named eventually.
|
|
91
94
|
namespace: new RendererOptions_1.StringOption("namespace", "Generated namespace", "NAME", "QuickType"),
|
|
92
95
|
version: new RendererOptions_1.EnumOption("csharp-version", "C# version", [
|
|
93
96
|
["5", 5],
|
|
94
|
-
["6", 6]
|
|
97
|
+
["6", 6]
|
|
95
98
|
], "6", "secondary"),
|
|
96
99
|
virtual: new RendererOptions_1.BooleanOption("virtual", "Generate virtual properties", false),
|
|
97
100
|
typeForAny: new RendererOptions_1.EnumOption("any-type", 'Type to use for "any"', [
|
|
98
101
|
["object", "object"],
|
|
99
|
-
["dynamic", "dynamic"]
|
|
102
|
+
["dynamic", "dynamic"]
|
|
100
103
|
], "object", "secondary"),
|
|
101
104
|
useDecimal: new RendererOptions_1.EnumOption("number-type", "Type to use for numbers", [
|
|
102
105
|
["double", false],
|
|
103
|
-
["decimal", true]
|
|
104
|
-
], "double", "secondary")
|
|
106
|
+
["decimal", true]
|
|
107
|
+
], "double", "secondary")
|
|
105
108
|
};
|
|
106
109
|
class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
107
110
|
constructor() {
|
|
@@ -116,7 +119,7 @@ class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
116
119
|
exports.cSharpOptions.useList,
|
|
117
120
|
exports.cSharpOptions.useDecimal,
|
|
118
121
|
exports.cSharpOptions.typeForAny,
|
|
119
|
-
exports.cSharpOptions.virtual
|
|
122
|
+
exports.cSharpOptions.virtual
|
|
120
123
|
];
|
|
121
124
|
}
|
|
122
125
|
get stringTypeMapping() {
|
|
@@ -200,9 +203,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
200
203
|
"Equals",
|
|
201
204
|
"GetType",
|
|
202
205
|
"MemberwiseClone",
|
|
203
|
-
"ReferenceEquals"
|
|
206
|
+
"ReferenceEquals"
|
|
204
207
|
],
|
|
205
|
-
includeGlobalForbidden: false
|
|
208
|
+
includeGlobalForbidden: false
|
|
206
209
|
};
|
|
207
210
|
}
|
|
208
211
|
forbiddenForUnionMembers(_, unionNamed) {
|
|
@@ -239,7 +242,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
239
242
|
}
|
|
240
243
|
csType(t, follow = Transformers_1.followTargetType, withIssues = false) {
|
|
241
244
|
const actualType = follow(t);
|
|
242
|
-
return TypeUtils_1.matchType(actualType,
|
|
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 => {
|
|
243
246
|
const itemsType = this.csType(arrayType.items, follow, withIssues);
|
|
244
247
|
if (this._csOptions.useList) {
|
|
245
248
|
return ["System.Collections.Generic.List<", itemsType, ">"];
|
|
@@ -247,12 +250,16 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
247
250
|
else {
|
|
248
251
|
return [itemsType, "[]"];
|
|
249
252
|
}
|
|
250
|
-
},
|
|
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 => {
|
|
251
258
|
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
252
259
|
if (nullable !== null)
|
|
253
260
|
return this.nullableCSType(nullable, noFollow);
|
|
254
261
|
return this.nameForNamedType(unionType);
|
|
255
|
-
},
|
|
262
|
+
}, transformedStringType => csTypeForTransformedStringType(transformedStringType));
|
|
256
263
|
}
|
|
257
264
|
nullableCSType(t, follow = Transformers_1.followTargetType, withIssues = false) {
|
|
258
265
|
t = Transformers_1.followTargetType(t);
|
|
@@ -362,9 +369,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
362
369
|
this.emitLine("public ", csType, " ", fieldName, ";");
|
|
363
370
|
});
|
|
364
371
|
this.ensureBlankLine();
|
|
365
|
-
const nullTests = Array.from(nonNulls).map(
|
|
372
|
+
const nullTests = Array.from(nonNulls).map(t => [
|
|
366
373
|
this.nameForUnionMember(u, t),
|
|
367
|
-
" == null"
|
|
374
|
+
" == null"
|
|
368
375
|
]);
|
|
369
376
|
this.ensureBlankLine();
|
|
370
377
|
this.forEachUnionMember(u, nonNulls, "none", null, (fieldName, t) => {
|
|
@@ -378,7 +385,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
378
385
|
}
|
|
379
386
|
emitEnumDefinition(e, enumName) {
|
|
380
387
|
const caseNames = [];
|
|
381
|
-
this.forEachEnumCase(e, "none",
|
|
388
|
+
this.forEachEnumCase(e, "none", name => {
|
|
382
389
|
if (caseNames.length > 0)
|
|
383
390
|
caseNames.push(", ");
|
|
384
391
|
caseNames.push(name);
|
|
@@ -475,13 +482,13 @@ exports.newtonsoftCSharpOptions = Object.assign({}, exports.cSharpOptions, {
|
|
|
475
482
|
["complete", { namespaces: true, helpers: true, attributes: true }],
|
|
476
483
|
["attributes-only", { namespaces: true, helpers: false, attributes: true }],
|
|
477
484
|
["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
|
|
478
|
-
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
485
|
+
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
479
486
|
]),
|
|
480
487
|
baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
|
|
481
488
|
["EntityData", "EntityData"],
|
|
482
|
-
["Object", undefined]
|
|
489
|
+
["Object", undefined]
|
|
483
490
|
], "Object", "secondary"),
|
|
484
|
-
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
491
|
+
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
485
492
|
});
|
|
486
493
|
class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
487
494
|
constructor(targetLanguage, renderContext, _options) {
|
|
@@ -504,7 +511,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
504
511
|
"MetadataPropertyHandling",
|
|
505
512
|
"DateParseHandling",
|
|
506
513
|
"FromJson",
|
|
507
|
-
"Required"
|
|
514
|
+
"Required"
|
|
508
515
|
];
|
|
509
516
|
if (this._options.dense) {
|
|
510
517
|
forbidden.push("J", "R", "N");
|
|
@@ -527,12 +534,12 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
527
534
|
}
|
|
528
535
|
return new Naming_1.SimpleName([`${xfer.kind}_converter`], namingFunction, ConvenienceRenderer_1.inferredNameOrder + 30);
|
|
529
536
|
}
|
|
530
|
-
return new Naming_1.DependencyName(namingFunction, typeName.order + 30,
|
|
537
|
+
return new Naming_1.DependencyName(namingFunction, typeName.order + 30, lookup => `${lookup(typeName)}_converter`);
|
|
531
538
|
}
|
|
532
539
|
makeNamedTypeDependencyNames(t, name) {
|
|
533
540
|
if (!(t instanceof Type_1.EnumType))
|
|
534
541
|
return [];
|
|
535
|
-
const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30,
|
|
542
|
+
const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30, lookup => `${lookup(name)}_extensions`);
|
|
536
543
|
this._enumExtensionsNames.set(name, extensionsName);
|
|
537
544
|
return [extensionsName];
|
|
538
545
|
}
|
|
@@ -672,7 +679,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
672
679
|
// Sometimes multiple top-levels will resolve to the same type, so we have to take care
|
|
673
680
|
// not to emit more than one extension method for the same type.
|
|
674
681
|
const seenTypes = new Set();
|
|
675
|
-
this.forEachTopLevel("none",
|
|
682
|
+
this.forEachTopLevel("none", t => {
|
|
676
683
|
// FIXME: Make ToJson a Named
|
|
677
684
|
if (!seenTypes.has(t)) {
|
|
678
685
|
seenTypes.add(t);
|
|
@@ -765,7 +772,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
765
772
|
this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
|
|
766
773
|
this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
|
|
767
774
|
this.emitBlock(() => {
|
|
768
|
-
this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType,
|
|
775
|
+
this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, v => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem");
|
|
769
776
|
// FIXME: handle EOF
|
|
770
777
|
this.emitLine("reader.Read();");
|
|
771
778
|
});
|
|
@@ -819,7 +826,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
819
826
|
}
|
|
820
827
|
if (xfer instanceof Transformers_1.ChoiceTransformer) {
|
|
821
828
|
const caseXfers = xfer.transformers;
|
|
822
|
-
if (caseXfers.length > 1 && caseXfers.every(
|
|
829
|
+
if (caseXfers.length > 1 && caseXfers.every(caseXfer => caseXfer instanceof Transformers_1.StringMatchTransformer)) {
|
|
823
830
|
this.emitLine("switch (", variable, ")");
|
|
824
831
|
this.emitBlock(() => {
|
|
825
832
|
for (const caseXfer of caseXfers) {
|
|
@@ -1037,7 +1044,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
|
|
|
1037
1044
|
if (haveNullable && !(targetType instanceof Type_1.UnionType)) {
|
|
1038
1045
|
this.emitLine("if (reader.TokenType == JsonToken.Null) return null;");
|
|
1039
1046
|
}
|
|
1040
|
-
const allHandled = this.emitDecodeTransformer(xfer, targetType,
|
|
1047
|
+
const allHandled = this.emitDecodeTransformer(xfer, targetType, v => this.emitLine("return ", v, ";"));
|
|
1041
1048
|
if (!allHandled) {
|
|
1042
1049
|
this.emitThrow(['"Cannot unmarshal type ', csType, '"']);
|
|
1043
1050
|
}
|
|
@@ -1084,13 +1091,13 @@ exports.systemTextJsonCSharpOptions = Object.assign({}, exports.cSharpOptions, {
|
|
|
1084
1091
|
["complete", { namespaces: true, helpers: true, attributes: true }],
|
|
1085
1092
|
["attributes-only", { namespaces: true, helpers: false, attributes: true }],
|
|
1086
1093
|
["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
|
|
1087
|
-
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
1094
|
+
["just-types", { namespaces: true, helpers: false, attributes: false }]
|
|
1088
1095
|
]),
|
|
1089
1096
|
baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
|
|
1090
1097
|
["EntityData", "EntityData"],
|
|
1091
|
-
["Object", undefined]
|
|
1098
|
+
["Object", undefined]
|
|
1092
1099
|
], "Object", "secondary"),
|
|
1093
|
-
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
1100
|
+
checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
|
|
1094
1101
|
});
|
|
1095
1102
|
class SystemTextJsonCSharpRenderer extends CSharpRenderer {
|
|
1096
1103
|
constructor(targetLanguage, renderContext, _options) {
|
|
@@ -1567,7 +1574,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer {
|
|
|
1567
1574
|
this.emitBlock(() => {
|
|
1568
1575
|
// this.emitLine("var uri = new Uri(", variable, ");");
|
|
1569
1576
|
// The default value about:blank should never happen, but this way we avoid a null reference warning.
|
|
1570
|
-
this.emitLine(
|
|
1577
|
+
this.emitLine('var uri = new Uri("about:blank");');
|
|
1571
1578
|
this.emitLine("if (!string.IsNullOrEmpty(stringValue))");
|
|
1572
1579
|
this.emitBlock(() => {
|
|
1573
1580
|
this.emitLine("uri = new Uri(", variable, ");");
|
package/dist/language/Elm.js
CHANGED
|
@@ -13,7 +13,10 @@ 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", [
|
|
16
|
+
useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [
|
|
17
|
+
["array", false],
|
|
18
|
+
["list", true]
|
|
19
|
+
]),
|
|
17
20
|
// FIXME: Do this via a configurable named eventually.
|
|
18
21
|
moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType")
|
|
19
22
|
};
|