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
package/README.md
CHANGED
|
@@ -250,27 +250,7 @@ files, URLs, or add other options.
|
|
|
250
250
|
|
|
251
251
|
### Test
|
|
252
252
|
|
|
253
|
-
`quicktype` has many complex test dependencies:
|
|
254
|
-
|
|
255
|
-
- `crystal` compiler
|
|
256
|
-
- `dotnetcore` SDK
|
|
257
|
-
- Java, Maven
|
|
258
|
-
- `elm` tools
|
|
259
|
-
- `g++` C++ compiler
|
|
260
|
-
- `golang` stack
|
|
261
|
-
- `swift` compiler
|
|
262
|
-
- `clang` and Objective-C Foundation (must be tested separately on macOS)
|
|
263
|
-
- `rust` tools
|
|
264
|
-
- `pike` interpreter
|
|
265
|
-
- [Bundler](https://bundler.io) for Ruby
|
|
266
|
-
- `haskell` [stack](https://docs.haskellstack.org/)
|
|
267
|
-
|
|
268
|
-
We've assembled all of these tools in a Docker container that you build and test within:
|
|
269
|
-
|
|
270
253
|
```bash
|
|
271
|
-
# Build and attach to Docker container
|
|
272
|
-
script/dev
|
|
273
|
-
|
|
274
254
|
# Run full test suite
|
|
275
255
|
npm run test
|
|
276
256
|
|
package/dist/cli/index.js
CHANGED
|
@@ -493,7 +493,10 @@ function parseOptions(definitions, argv, partial) {
|
|
|
493
493
|
if (o.renderer !== undefined)
|
|
494
494
|
options.rendererOptions[o.name] = v;
|
|
495
495
|
else {
|
|
496
|
-
const k = _.lowerFirst(o.name
|
|
496
|
+
const k = _.lowerFirst(o.name
|
|
497
|
+
.split("-")
|
|
498
|
+
.map(_.upperFirst)
|
|
499
|
+
.join(""));
|
|
497
500
|
options[k] = v;
|
|
498
501
|
}
|
|
499
502
|
}
|
|
@@ -731,7 +731,9 @@ class MinMaxValueTransformer extends ProducerTransformer {
|
|
|
731
731
|
equals(other) {
|
|
732
732
|
if (!super.equals(other))
|
|
733
733
|
return false;
|
|
734
|
-
return (other instanceof MinMaxValueTransformer &&
|
|
734
|
+
return (other instanceof MinMaxValueTransformer &&
|
|
735
|
+
this.minimum === other.minimum &&
|
|
736
|
+
this.maximum === other.maximum);
|
|
735
737
|
}
|
|
736
738
|
}
|
|
737
739
|
exports.MinMaxValueTransformer = MinMaxValueTransformer;
|
|
@@ -80,7 +80,10 @@ function normalizeURI(uri) {
|
|
|
80
80
|
if (typeof uri === "string") {
|
|
81
81
|
uri = new URI(uri);
|
|
82
82
|
}
|
|
83
|
-
return new URI(URI.decode(uri
|
|
83
|
+
return new URI(URI.decode(uri
|
|
84
|
+
.clone()
|
|
85
|
+
.normalize()
|
|
86
|
+
.toString()));
|
|
84
87
|
}
|
|
85
88
|
class Ref {
|
|
86
89
|
constructor(addressURI, path) {
|
|
@@ -1017,7 +1020,10 @@ class JSONSchemaInput {
|
|
|
1017
1020
|
else {
|
|
1018
1021
|
normalizedURIs = uris.map(uri => {
|
|
1019
1022
|
const normalizedURI = normalizeURI(uri);
|
|
1020
|
-
if (normalizedURI
|
|
1023
|
+
if (normalizedURI
|
|
1024
|
+
.clone()
|
|
1025
|
+
.hash("")
|
|
1026
|
+
.toString() === "") {
|
|
1021
1027
|
normalizedURI.path(name);
|
|
1022
1028
|
}
|
|
1023
1029
|
return normalizedURI;
|
|
@@ -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,30 +22,12 @@ 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
|
-
|
|
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"),
|
|
25
|
+
typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [["single-source", true], ["multi-source", false]], "single-source", "secondary"),
|
|
26
|
+
includeLocation: new RendererOptions_1.EnumOption("include-location", "Whether json.hpp is to be located globally or locally", [["local-include", true], ["global-include", false]], "local-include", "secondary"),
|
|
27
|
+
codeFormat: new RendererOptions_1.EnumOption("code-format", "Generate classes with getters/setters, instead of structs", [["with-struct", false], ["with-getter-setter", true]], "with-getter-setter"),
|
|
28
|
+
wstring: new RendererOptions_1.EnumOption("wstring", "Store strings using Utf-16 std::wstring, rather than Utf-8 std::string", [["use-string", false], ["use-wstring", true]], "use-string"),
|
|
29
|
+
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", [["not-permissive", false], ["use-permissive", true]], "not-permissive", "secondary"),
|
|
30
|
+
westConst: new RendererOptions_1.EnumOption("const-style", "Put const to the left/west (const T) or right/east (T const)", [["west-const", true], ["east-const", false]], "west-const"),
|
|
49
31
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
50
32
|
namespace: new RendererOptions_1.StringOption("namespace", "Name of the generated namespace(s)", "NAME", "quicktype"),
|
|
51
33
|
enumType: new RendererOptions_1.StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"),
|
|
@@ -74,7 +56,7 @@ exports.cPlusPlusOptions = {
|
|
|
74
56
|
camelUpperAcronymsValue
|
|
75
57
|
]),
|
|
76
58
|
boost: new RendererOptions_1.BooleanOption("boost", "Require a dependency on boost. Without boost, C++17 is required", true),
|
|
77
|
-
hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false)
|
|
59
|
+
hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false),
|
|
78
60
|
};
|
|
79
61
|
class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
80
62
|
constructor(displayName = "C++", names = ["c++", "cpp", "cplusplus"], extension = "cpp") {
|
|
@@ -95,7 +77,7 @@ class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
95
77
|
exports.cPlusPlusOptions.enumeratorNamingStyle,
|
|
96
78
|
exports.cPlusPlusOptions.enumType,
|
|
97
79
|
exports.cPlusPlusOptions.boost,
|
|
98
|
-
exports.cPlusPlusOptions.hideNullOptional
|
|
80
|
+
exports.cPlusPlusOptions.hideNullOptional,
|
|
99
81
|
];
|
|
100
82
|
}
|
|
101
83
|
get supportsUnionsWithBothNumberTypes() {
|
|
@@ -322,7 +304,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
322
304
|
super(targetLanguage, renderContext);
|
|
323
305
|
this._options = _options;
|
|
324
306
|
this._gettersAndSettersForPropertyName = new Map();
|
|
325
|
-
this.NarrowString = new
|
|
307
|
+
this.NarrowString = new class extends BaseString {
|
|
326
308
|
constructor() {
|
|
327
309
|
super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
|
|
328
310
|
}
|
|
@@ -332,8 +314,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
332
314
|
emitHelperFunctions() {
|
|
333
315
|
return;
|
|
334
316
|
}
|
|
335
|
-
}
|
|
336
|
-
this.WideString = new
|
|
317
|
+
}();
|
|
318
|
+
this.WideString = new class extends BaseString {
|
|
337
319
|
constructor(superThis) {
|
|
338
320
|
super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
|
|
339
321
|
this.superThis = superThis;
|
|
@@ -416,7 +398,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
416
398
|
});
|
|
417
399
|
this.superThis.ensureBlankLine();
|
|
418
400
|
}
|
|
419
|
-
}
|
|
401
|
+
}(this);
|
|
420
402
|
this._enumType = _options.enumType;
|
|
421
403
|
this._namespaceNames = _options.namespace.split("::");
|
|
422
404
|
this.typeNamingStyle = _options.typeNamingStyle;
|
|
@@ -559,7 +541,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
559
541
|
this.emitCommentLines(this.leadingComments);
|
|
560
542
|
}
|
|
561
543
|
else if (!this._options.justTypes) {
|
|
562
|
-
this.emitCommentLines([
|
|
544
|
+
this.emitCommentLines([
|
|
545
|
+
" To parse this JSON data, first install",
|
|
546
|
+
"",
|
|
547
|
+
]);
|
|
563
548
|
if (this._options.boost) {
|
|
564
549
|
this.emitCommentLines([" Boost http://www.boost.org"]);
|
|
565
550
|
}
|
|
@@ -679,12 +664,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
679
664
|
return [optionalType, "<", variant, ">"];
|
|
680
665
|
}
|
|
681
666
|
ourQualifier(inJsonNamespace) {
|
|
682
|
-
return inJsonNamespace || this._options.msbuildPermissive
|
|
683
|
-
? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"]
|
|
684
|
-
: [];
|
|
667
|
+
return (inJsonNamespace || this._options.msbuildPermissive) ? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"] : [];
|
|
685
668
|
}
|
|
686
669
|
jsonQualifier(inJsonNamespace) {
|
|
687
|
-
return inJsonNamespace || this._options.msbuildPermissive ? [] : "nlohmann::";
|
|
670
|
+
return (inJsonNamespace || this._options.msbuildPermissive) ? [] : "nlohmann::";
|
|
688
671
|
}
|
|
689
672
|
variantIndirection(needIndirection, typeSrc) {
|
|
690
673
|
if (!needIndirection)
|
|
@@ -693,8 +676,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
693
676
|
}
|
|
694
677
|
cppType(t, ctx, withIssues, forceNarrowString, isOptional) {
|
|
695
678
|
const inJsonNamespace = ctx.inJsonNamespace;
|
|
696
|
-
if (isOptional && t instanceof Type_1.UnionType) {
|
|
697
|
-
// avoid have optionalType<optionalType<Type>>
|
|
679
|
+
if (isOptional && t instanceof Type_1.UnionType) { // avoid have optionalType<optionalType<Type>>
|
|
698
680
|
for (const tChild of t.getChildren()) {
|
|
699
681
|
if (tChild.isNullable) {
|
|
700
682
|
isOptional = false;
|
|
@@ -704,16 +686,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
704
686
|
}
|
|
705
687
|
let typeSource = TypeUtils_1.matchType(t, _anyType => {
|
|
706
688
|
isOptional = false;
|
|
707
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [
|
|
708
|
-
this.jsonQualifier(inJsonNamespace),
|
|
709
|
-
"json"
|
|
710
|
-
]);
|
|
689
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
|
|
711
690
|
}, _nullType => {
|
|
712
691
|
isOptional = false;
|
|
713
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [
|
|
714
|
-
this.jsonQualifier(inJsonNamespace),
|
|
715
|
-
"json"
|
|
716
|
-
]);
|
|
692
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
|
|
717
693
|
}, _boolType => "bool", _integerType => "int64_t", _doubleType => "double", _stringType => {
|
|
718
694
|
if (forceNarrowString) {
|
|
719
695
|
return "std::string";
|
|
@@ -725,7 +701,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
725
701
|
"std::vector<",
|
|
726
702
|
this.cppType(arrayType.items, { needsForwardIndirection: false, needsOptionalIndirection: true, inJsonNamespace }, withIssues, forceNarrowString, false),
|
|
727
703
|
">"
|
|
728
|
-
], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [
|
|
704
|
+
], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [
|
|
705
|
+
this.ourQualifier(inJsonNamespace),
|
|
706
|
+
this.nameForNamedType(classType)
|
|
707
|
+
]), mapType => {
|
|
729
708
|
let keyType = this._stringType.getType();
|
|
730
709
|
if (forceNarrowString) {
|
|
731
710
|
keyType = "std::string";
|
|
@@ -746,7 +725,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
746
725
|
});
|
|
747
726
|
if (!isOptional)
|
|
748
727
|
return typeSource;
|
|
749
|
-
return [
|
|
728
|
+
return [
|
|
729
|
+
optionalType,
|
|
730
|
+
"<",
|
|
731
|
+
typeSource,
|
|
732
|
+
">"
|
|
733
|
+
];
|
|
750
734
|
}
|
|
751
735
|
/**
|
|
752
736
|
* similar to cppType, it practically gathers all the generated types within
|
|
@@ -850,8 +834,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
850
834
|
* a member called 'value' value = value will screw up the compiler
|
|
851
835
|
*/
|
|
852
836
|
const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
|
|
853
|
-
if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) ||
|
|
854
|
-
(property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
|
|
837
|
+
if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) || (property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
|
|
855
838
|
this.emitLine(rendered, " ", getterName, "() const { return ", name, "; }");
|
|
856
839
|
if (constraints !== undefined && constraints.has(jsonName)) {
|
|
857
840
|
this.emitLine("void ", setterName, "(", rendered, " value) { if (value) ", checkConst, "(", this._stringType.createStringLiteral([name]), ", ", this.constraintMember(jsonName), ", *value); this->", name, " = value; }");
|
|
@@ -884,26 +867,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
884
867
|
res.set(jsonName, [
|
|
885
868
|
this.constraintMember(jsonName),
|
|
886
869
|
"(",
|
|
887
|
-
minMax !== undefined && minMax[0] !== undefined ? String(minMax[0]) : this._nulloptType,
|
|
870
|
+
(minMax !== undefined && minMax[0] !== undefined) ? String(minMax[0]) : this._nulloptType,
|
|
888
871
|
", ",
|
|
889
|
-
minMax !== undefined && minMax[1] !== undefined ? String(minMax[1]) : this._nulloptType,
|
|
872
|
+
(minMax !== undefined && minMax[1] !== undefined) ? String(minMax[1]) : this._nulloptType,
|
|
890
873
|
", ",
|
|
891
|
-
minMaxLength !== undefined && minMaxLength[0] !== undefined
|
|
892
|
-
? String(minMaxLength[0])
|
|
893
|
-
: this._nulloptType,
|
|
874
|
+
(minMaxLength !== undefined && minMaxLength[0] !== undefined) ? String(minMaxLength[0]) : this._nulloptType,
|
|
894
875
|
", ",
|
|
895
|
-
minMaxLength !== undefined && minMaxLength[1] !== undefined
|
|
896
|
-
? String(minMaxLength[1])
|
|
897
|
-
: this._nulloptType,
|
|
876
|
+
(minMaxLength !== undefined && minMaxLength[1] !== undefined) ? String(minMaxLength[1]) : this._nulloptType,
|
|
898
877
|
", ",
|
|
899
|
-
pattern === undefined
|
|
900
|
-
? this._nulloptType
|
|
901
|
-
: [
|
|
902
|
-
this._stringType.getType(),
|
|
903
|
-
"(",
|
|
904
|
-
this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]),
|
|
905
|
-
")"
|
|
906
|
-
],
|
|
878
|
+
(pattern === undefined) ? this._nulloptType : [this._stringType.getType(), "(", this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]), ")"],
|
|
907
879
|
")"
|
|
908
880
|
]);
|
|
909
881
|
});
|
|
@@ -964,11 +936,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
964
936
|
toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
|
|
965
937
|
this.emitLine([
|
|
966
938
|
"x = ",
|
|
967
|
-
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
968
|
-
"j.get<",
|
|
969
|
-
cppType,
|
|
970
|
-
">()"
|
|
971
|
-
]),
|
|
939
|
+
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["j.get<", cppType, ">()"]),
|
|
972
940
|
";"
|
|
973
941
|
]);
|
|
974
942
|
});
|
|
@@ -1008,7 +976,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1008
976
|
return;
|
|
1009
977
|
}
|
|
1010
978
|
if (p.isOptional || t instanceof Type_1.UnionType) {
|
|
1011
|
-
const [nullOrOptional, typeSet] =
|
|
979
|
+
const [nullOrOptional, typeSet] = function () {
|
|
1012
980
|
if (t instanceof Type_1.UnionType) {
|
|
1013
981
|
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(t, true);
|
|
1014
982
|
return [maybeNull !== null || p.isOptional, nonNulls];
|
|
@@ -1018,7 +986,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1018
986
|
set.add(t);
|
|
1019
987
|
return [true, set];
|
|
1020
988
|
}
|
|
1021
|
-
}
|
|
989
|
+
}();
|
|
1022
990
|
if (nullOrOptional) {
|
|
1023
991
|
cppType = this.cppTypeInOptional(typeSet, {
|
|
1024
992
|
needsForwardIndirection: false,
|
|
@@ -1077,11 +1045,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1077
1045
|
";"
|
|
1078
1046
|
];
|
|
1079
1047
|
if (p.isOptional && this._options.hideNullOptional) {
|
|
1080
|
-
this.emitBlock([
|
|
1081
|
-
"if (",
|
|
1082
|
-
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
|
|
1083
|
-
")"
|
|
1084
|
-
], false, () => {
|
|
1048
|
+
this.emitBlock(["if (", this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]), ")"], false, () => {
|
|
1085
1049
|
this.emitLine(assignment);
|
|
1086
1050
|
});
|
|
1087
1051
|
}
|
|
@@ -1195,14 +1159,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1195
1159
|
const ourQualifier = this.ourQualifier(true);
|
|
1196
1160
|
this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, enumName, " & x)"], false, () => {
|
|
1197
1161
|
if (this.isLargeEnum(e)) {
|
|
1198
|
-
this.emitBlock([
|
|
1199
|
-
"static std::unordered_map<",
|
|
1200
|
-
this._stringType.getType(),
|
|
1201
|
-
", ",
|
|
1202
|
-
ourQualifier,
|
|
1203
|
-
enumName,
|
|
1204
|
-
"> enumValues"
|
|
1205
|
-
], true, () => {
|
|
1162
|
+
this.emitBlock(["static std::unordered_map<", this._stringType.getType(), ", ", ourQualifier, enumName, "> enumValues"], true, () => {
|
|
1206
1163
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1207
1164
|
this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), ", ", ourQualifier, enumName, "::", name, "},");
|
|
1208
1165
|
});
|
|
@@ -1349,15 +1306,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1349
1306
|
this.ensureBlankLine();
|
|
1350
1307
|
}
|
|
1351
1308
|
const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
|
|
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, () => {
|
|
1309
|
+
this.emitBlock(["inline void ", checkConst, "(", this._stringType.getConstType(), " name, ", this.withConst(classConstraint), " & c, int64_t value)"], false, () => {
|
|
1361
1310
|
this.emitBlock(["if (c.", getterMinValue, "() != ", this._nulloptType, " && value < *c.", getterMinValue, "())"], false, () => {
|
|
1362
1311
|
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([")"]), ");");
|
|
1363
1312
|
});
|
|
@@ -1368,38 +1317,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1368
1317
|
this.ensureBlankLine();
|
|
1369
1318
|
});
|
|
1370
1319
|
this.ensureBlankLine();
|
|
1371
|
-
this.emitBlock([
|
|
1372
|
-
"
|
|
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, () => {
|
|
1320
|
+
this.emitBlock(["inline void ", checkConst, "(", this._stringType.getConstType(), " name, ", this.withConst(classConstraint), " & c, ", this._stringType.getConstType(), " value)"], false, () => {
|
|
1321
|
+
this.emitBlock(["if (c.", getterMinLength, "() != ", this._nulloptType, " && value.length() < *c.", getterMinLength, "())"], false, () => {
|
|
1391
1322
|
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([")"]), ");");
|
|
1392
1323
|
});
|
|
1393
1324
|
this.ensureBlankLine();
|
|
1394
|
-
this.emitBlock([
|
|
1395
|
-
"if (c.",
|
|
1396
|
-
getterMaxLength,
|
|
1397
|
-
"() != ",
|
|
1398
|
-
this._nulloptType,
|
|
1399
|
-
" && value.length() > *c.",
|
|
1400
|
-
getterMaxLength,
|
|
1401
|
-
"())"
|
|
1402
|
-
], false, () => {
|
|
1325
|
+
this.emitBlock(["if (c.", getterMaxLength, "() != ", this._nulloptType, " && value.length() > *c.", getterMaxLength, "())"], false, () => {
|
|
1403
1326
|
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([")"]), ");");
|
|
1404
1327
|
});
|
|
1405
1328
|
this.ensureBlankLine();
|
|
@@ -1420,28 +1343,24 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1420
1343
|
this.emitConstraintClasses();
|
|
1421
1344
|
this.ensureBlankLine();
|
|
1422
1345
|
}
|
|
1423
|
-
this.emitBlock([
|
|
1346
|
+
this.emitBlock([
|
|
1347
|
+
"inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"
|
|
1348
|
+
], false, () => {
|
|
1424
1349
|
this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
|
|
1425
1350
|
this.emitLine("return j.at(property).get<json>();");
|
|
1426
1351
|
});
|
|
1427
1352
|
this.emitLine("return json();");
|
|
1428
1353
|
});
|
|
1429
1354
|
this.ensureBlankLine();
|
|
1430
|
-
this.emitBlock([
|
|
1355
|
+
this.emitBlock([
|
|
1356
|
+
"inline json get_untyped(", this.withConst("json"), " & j, std::string property)"
|
|
1357
|
+
], false, () => {
|
|
1431
1358
|
this.emitLine("return get_untyped(j, property.data());");
|
|
1432
1359
|
});
|
|
1433
1360
|
this.ensureBlankLine();
|
|
1434
1361
|
if (this.haveUnions || this.haveOptionalProperties) {
|
|
1435
1362
|
this.emitLine("template <typename T>");
|
|
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, () => {
|
|
1363
|
+
this.emitBlock(["inline ", optionalType, "<T> get_optional(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
|
|
1445
1364
|
this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
|
|
1446
1365
|
this.emitLine("return j.at(property).get<", optionalType, "<T>>();");
|
|
1447
1366
|
});
|