quicktype-core 23.0.45 → 23.0.47
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.
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.descriptionAttributeProducer = exports.propertyDescriptionsTypeAttributeKind = exports.descriptionTypeAttributeKind = exports.addDescriptionToSchema = void 0;
|
|
4
4
|
const collection_utils_1 = require("collection-utils");
|
|
5
|
+
// There's a cyclic import here. Ignoring now because it requires a large refactor.
|
|
6
|
+
// skipcq: JS-E1008
|
|
5
7
|
const TypeAttributes_1 = require("./TypeAttributes");
|
|
8
|
+
// FIXME: This is a circular import
|
|
6
9
|
const JSONSchemaInput_1 = require("../input/JSONSchemaInput");
|
|
7
10
|
function addDescriptionToSchema(schema, description) {
|
|
8
11
|
if (description === undefined)
|
|
@@ -2,8 +2,8 @@ import URI from "urijs";
|
|
|
2
2
|
import { TypeBuilder } from "../TypeBuilder";
|
|
3
3
|
import { TypeAttributes } from "../attributes/TypeAttributes";
|
|
4
4
|
import { JSONSchema, JSONSchemaStore } from "./JSONSchemaStore";
|
|
5
|
-
import { RunContext } from "../Run";
|
|
6
|
-
import { Input } from "./Inputs";
|
|
5
|
+
import { type RunContext } from "../Run";
|
|
6
|
+
import { type Input } from "./Inputs";
|
|
7
7
|
export declare enum PathElementKind {
|
|
8
8
|
Root = 0,
|
|
9
9
|
KeyOrIndex = 1,
|
|
@@ -23,6 +23,8 @@ const TypeAttributes_1 = require("../attributes/TypeAttributes");
|
|
|
23
23
|
const JSONSchemaStore_1 = require("./JSONSchemaStore");
|
|
24
24
|
const Messages_1 = require("../Messages");
|
|
25
25
|
const StringTypes_1 = require("../attributes/StringTypes");
|
|
26
|
+
// There's a cyclic import here. Ignoring now because it requires a large refactor.
|
|
27
|
+
// skipcq: JS-E1008
|
|
26
28
|
const Description_1 = require("../attributes/Description");
|
|
27
29
|
const AccessorNames_1 = require("../attributes/AccessorNames");
|
|
28
30
|
const EnumValues_1 = require("../attributes/EnumValues");
|
|
@@ -102,8 +102,8 @@ export type TypeContext = {
|
|
|
102
102
|
inJsonNamespace: boolean;
|
|
103
103
|
};
|
|
104
104
|
declare class WrappingCode {
|
|
105
|
-
private readonly
|
|
106
|
-
private readonly
|
|
105
|
+
private readonly start;
|
|
106
|
+
private readonly end;
|
|
107
107
|
constructor(start: Sourcelike[], end: Sourcelike[]);
|
|
108
108
|
wrap(qualifier: Sourcelike, inner: Sourcelike): Sourcelike;
|
|
109
109
|
}
|
|
@@ -273,23 +273,23 @@ function addQualifier(qualifier, qualified) {
|
|
|
273
273
|
}
|
|
274
274
|
class WrappingCode {
|
|
275
275
|
constructor(start, end) {
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
276
|
+
this.start = start;
|
|
277
|
+
this.end = end;
|
|
278
278
|
}
|
|
279
279
|
wrap(qualifier, inner) {
|
|
280
|
-
return [addQualifier(qualifier, this.
|
|
280
|
+
return [addQualifier(qualifier, this.start), inner, this.end];
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
class BaseString {
|
|
284
284
|
constructor(stringType, constStringType, smatch, regex, stringLiteralPrefix, toString, encodingClass, encodingFunction) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
this._stringType = stringType;
|
|
286
|
+
this._constStringType = constStringType;
|
|
287
|
+
this._smatch = smatch;
|
|
288
|
+
this._regex = regex;
|
|
289
|
+
this._stringLiteralPrefix = stringLiteralPrefix;
|
|
290
|
+
this._toString = toString;
|
|
291
|
+
this._encodingClass = encodingClass;
|
|
292
|
+
this._encodingFunction = encodingFunction;
|
|
293
293
|
}
|
|
294
294
|
getType() {
|
|
295
295
|
return this._stringType;
|
|
@@ -900,7 +900,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
900
900
|
type: t,
|
|
901
901
|
level: l,
|
|
902
902
|
variant: isVariant,
|
|
903
|
-
forceInclude
|
|
903
|
+
forceInclude
|
|
904
904
|
});
|
|
905
905
|
}
|
|
906
906
|
else if (t instanceof Type_1.MapType) {
|
|
@@ -937,7 +937,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
937
937
|
type: t,
|
|
938
938
|
level: l,
|
|
939
939
|
variant: true,
|
|
940
|
-
forceInclude
|
|
940
|
+
forceInclude
|
|
941
941
|
});
|
|
942
942
|
/** intentional "fall-through", add all subtypes as well - but forced include */
|
|
943
943
|
}
|
|
@@ -953,7 +953,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
953
953
|
return result;
|
|
954
954
|
}
|
|
955
955
|
constraintMember(jsonName) {
|
|
956
|
-
return this._memberNameStyle(jsonName
|
|
956
|
+
return this._memberNameStyle(`${jsonName}Constraint`);
|
|
957
957
|
}
|
|
958
958
|
emitMember(cppType, name) {
|
|
959
959
|
this.emitLine(cppType, " ", name, ";");
|
|
@@ -1046,9 +1046,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1046
1046
|
", ",
|
|
1047
1047
|
(minMax === null || minMax === void 0 ? void 0 : minMax[1]) && cppType === "double" ? String(minMax[1]) : this._nulloptType,
|
|
1048
1048
|
", ",
|
|
1049
|
-
(minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[0])
|
|
1050
|
-
? String(minMaxLength[0])
|
|
1051
|
-
: this._nulloptType,
|
|
1049
|
+
(minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[0]) ? String(minMaxLength[0]) : this._nulloptType,
|
|
1052
1050
|
", ",
|
|
1053
1051
|
(minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[1]) ? String(minMaxLength[1]) : this._nulloptType,
|
|
1054
1052
|
", ",
|
|
@@ -1182,7 +1180,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1182
1180
|
this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, className, "& x)"], false, () => {
|
|
1183
1181
|
this.forEachClassProperty(c, "none", (name, json, p) => {
|
|
1184
1182
|
const [, , setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
|
|
1185
|
-
const
|
|
1183
|
+
const propType = p.type;
|
|
1186
1184
|
let assignment;
|
|
1187
1185
|
if (this._options.codeFormat) {
|
|
1188
1186
|
assignment = new WrappingCode(["x.", setterName, "("], [")"]);
|
|
@@ -1190,7 +1188,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1190
1188
|
else {
|
|
1191
1189
|
assignment = new WrappingCode(["x.", name, " = "], []);
|
|
1192
1190
|
}
|
|
1193
|
-
if (
|
|
1191
|
+
if (propType.kind === "null" || propType.kind === "any") {
|
|
1194
1192
|
this.emitLine(assignment.wrap([], [
|
|
1195
1193
|
ourQualifier,
|
|
1196
1194
|
"get_untyped(j, ",
|
|
@@ -1199,15 +1197,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1199
1197
|
]), ";");
|
|
1200
1198
|
return;
|
|
1201
1199
|
}
|
|
1202
|
-
if (p.isOptional ||
|
|
1200
|
+
if (p.isOptional || propType instanceof Type_1.UnionType) {
|
|
1203
1201
|
const [nullOrOptional, typeSet] = (function () {
|
|
1204
|
-
if (
|
|
1205
|
-
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(
|
|
1202
|
+
if (propType instanceof Type_1.UnionType) {
|
|
1203
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(propType, true);
|
|
1206
1204
|
return [maybeNull !== null || p.isOptional, nonNulls];
|
|
1207
1205
|
}
|
|
1208
1206
|
else {
|
|
1209
1207
|
const set = new Set();
|
|
1210
|
-
set.add(
|
|
1208
|
+
set.add(propType);
|
|
1211
1209
|
return [true, set];
|
|
1212
1210
|
}
|
|
1213
1211
|
})();
|
|
@@ -1223,9 +1221,9 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1223
1221
|
inJsonNamespace: false
|
|
1224
1222
|
}, false, false);
|
|
1225
1223
|
this.emitLine(assignment.wrap([], [
|
|
1226
|
-
this._stringType.wrapEncodingChange([ourQualifier], [this.optionalType(
|
|
1224
|
+
this._stringType.wrapEncodingChange([ourQualifier], [this.optionalType(propType), "<", cppType, ">"], [this.optionalType(propType), "<", toType, ">"], [
|
|
1227
1225
|
ourQualifier,
|
|
1228
|
-
`get_${this.optionalTypeLabel(
|
|
1226
|
+
`get_${this.optionalTypeLabel(propType)}_optional<`,
|
|
1229
1227
|
cppType,
|
|
1230
1228
|
">(j, ",
|
|
1231
1229
|
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])]),
|
|
@@ -1235,12 +1233,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1235
1233
|
return;
|
|
1236
1234
|
}
|
|
1237
1235
|
}
|
|
1238
|
-
cppType = this.cppType(
|
|
1236
|
+
cppType = this.cppType(propType, {
|
|
1239
1237
|
needsForwardIndirection: true,
|
|
1240
1238
|
needsOptionalIndirection: true,
|
|
1241
1239
|
inJsonNamespace: false
|
|
1242
1240
|
}, false, true, p.isOptional);
|
|
1243
|
-
toType = this.cppType(
|
|
1241
|
+
toType = this.cppType(propType, {
|
|
1244
1242
|
needsForwardIndirection: true,
|
|
1245
1243
|
needsOptionalIndirection: true,
|
|
1246
1244
|
inJsonNamespace: false
|
|
@@ -1258,13 +1256,13 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1258
1256
|
this.emitBlock(["inline void to_json(json & j, ", this.withConst([ourQualifier, className]), " & x)"], false, () => {
|
|
1259
1257
|
this.emitLine("j = json::object();");
|
|
1260
1258
|
this.forEachClassProperty(c, "none", (name, json, p) => {
|
|
1261
|
-
const
|
|
1262
|
-
cppType = this.cppType(
|
|
1259
|
+
const propType = p.type;
|
|
1260
|
+
cppType = this.cppType(propType, {
|
|
1263
1261
|
needsForwardIndirection: true,
|
|
1264
1262
|
needsOptionalIndirection: true,
|
|
1265
1263
|
inJsonNamespace: false
|
|
1266
1264
|
}, false, false, p.isOptional);
|
|
1267
|
-
toType = this.cppType(
|
|
1265
|
+
toType = this.cppType(propType, {
|
|
1268
1266
|
needsForwardIndirection: true,
|
|
1269
1267
|
needsOptionalIndirection: true,
|
|
1270
1268
|
inJsonNamespace: false
|
|
@@ -1525,23 +1523,23 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1525
1523
|
}
|
|
1526
1524
|
}
|
|
1527
1525
|
else if (decl.kind === "define") {
|
|
1528
|
-
const
|
|
1529
|
-
const name = this.nameForNamedType(
|
|
1530
|
-
if (
|
|
1531
|
-
this.emitClass(
|
|
1526
|
+
const type = decl.type;
|
|
1527
|
+
const name = this.nameForNamedType(type);
|
|
1528
|
+
if (type instanceof Type_1.ClassType) {
|
|
1529
|
+
this.emitClass(type, name);
|
|
1532
1530
|
}
|
|
1533
|
-
else if (
|
|
1534
|
-
this.emitEnum(
|
|
1531
|
+
else if (type instanceof Type_1.EnumType) {
|
|
1532
|
+
this.emitEnum(type, name);
|
|
1535
1533
|
}
|
|
1536
|
-
else if (
|
|
1537
|
-
this.emitUnionTypedefs(
|
|
1534
|
+
else if (type instanceof Type_1.UnionType) {
|
|
1535
|
+
this.emitUnionTypedefs(type, name);
|
|
1538
1536
|
}
|
|
1539
1537
|
else {
|
|
1540
|
-
|
|
1538
|
+
(0, Support_1.panic)(`Cannot declare type ${type.kind}`);
|
|
1541
1539
|
}
|
|
1542
1540
|
}
|
|
1543
1541
|
else {
|
|
1544
|
-
|
|
1542
|
+
(0, Support_1.assertNever)(decl.kind);
|
|
1545
1543
|
}
|
|
1546
1544
|
}
|
|
1547
1545
|
emitGetterSetter(t, getterName, setterName, memberName) {
|
|
@@ -1697,8 +1695,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1697
1695
|
});
|
|
1698
1696
|
untypedMacroName += "HELPER";
|
|
1699
1697
|
optionalMacroName += "HELPER";
|
|
1700
|
-
this.emitLine(
|
|
1701
|
-
this.emitLine(
|
|
1698
|
+
this.emitLine(`#ifndef ${untypedMacroName}`);
|
|
1699
|
+
this.emitLine(`#define ${untypedMacroName}`);
|
|
1702
1700
|
this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
|
|
1703
1701
|
this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
|
|
1704
1702
|
this.emitLine("return j.at(property).get<json>();");
|
|
@@ -1713,8 +1711,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1713
1711
|
this.ensureBlankLine();
|
|
1714
1712
|
if (this.haveUnions || this.haveOptionalProperties) {
|
|
1715
1713
|
this.ensureBlankLine();
|
|
1716
|
-
this.emitLine(
|
|
1717
|
-
this.emitLine(
|
|
1714
|
+
this.emitLine(`#ifndef ${optionalMacroName}`);
|
|
1715
|
+
this.emitLine(`#define ${optionalMacroName}`);
|
|
1718
1716
|
const emitGetOptional = (optionalType, label) => {
|
|
1719
1717
|
this.emitLine("template <typename T>");
|
|
1720
1718
|
this.emitBlock([
|
|
@@ -1754,28 +1752,28 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1754
1752
|
this.ensureBlankLine();
|
|
1755
1753
|
if (this._options.codeFormat) {
|
|
1756
1754
|
if (this._options.boost) {
|
|
1757
|
-
this.emitInclude(true,
|
|
1755
|
+
this.emitInclude(true, "boost/optional.hpp");
|
|
1758
1756
|
}
|
|
1759
1757
|
else {
|
|
1760
|
-
this.emitInclude(true,
|
|
1758
|
+
this.emitInclude(true, "optional");
|
|
1761
1759
|
}
|
|
1762
|
-
this.emitInclude(true,
|
|
1763
|
-
this.emitInclude(true,
|
|
1760
|
+
this.emitInclude(true, "stdexcept");
|
|
1761
|
+
this.emitInclude(true, "regex");
|
|
1764
1762
|
}
|
|
1765
1763
|
if (this._options.wstring) {
|
|
1766
|
-
this.emitInclude(true,
|
|
1767
|
-
this.emitInclude(true,
|
|
1764
|
+
this.emitInclude(true, "codecvt");
|
|
1765
|
+
this.emitInclude(true, "locale");
|
|
1768
1766
|
}
|
|
1769
1767
|
// Include unordered_map if contains large enums
|
|
1770
1768
|
if (Array.from(this.enums).some(enumType => this.isLargeEnum(enumType))) {
|
|
1771
|
-
this.emitInclude(true,
|
|
1769
|
+
this.emitInclude(true, "unordered_map");
|
|
1772
1770
|
}
|
|
1773
1771
|
this.ensureBlankLine();
|
|
1774
1772
|
}
|
|
1775
1773
|
emitHelper() {
|
|
1776
1774
|
this.startFile("helper.hpp", false);
|
|
1777
1775
|
this.emitExtraIncludes();
|
|
1778
|
-
this.emitInclude(true,
|
|
1776
|
+
this.emitInclude(true, "sstream");
|
|
1779
1777
|
this.ensureBlankLine();
|
|
1780
1778
|
this.emitNamespaces(this._namespaceNames, () => {
|
|
1781
1779
|
this.emitLine("using nlohmann::json;");
|
|
@@ -1835,13 +1833,13 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1835
1833
|
else {
|
|
1836
1834
|
const userNamespaceForwardDecls = this.gatherUserNamespaceForwardDecls();
|
|
1837
1835
|
const nlohmannNamespaceForwardDecls = this.gatherNlohmannNamespaceForwardDecls();
|
|
1838
|
-
if (userNamespaceForwardDecls.length
|
|
1836
|
+
if (userNamespaceForwardDecls.length === 0 && nlohmannNamespaceForwardDecls.length > 0) {
|
|
1839
1837
|
this.emitNamespaces(["nlohmann"], () => {
|
|
1840
1838
|
this.emitGatheredSource(nlohmannNamespaceForwardDecls);
|
|
1841
1839
|
this.emitNlohmannNamespaceImpls();
|
|
1842
1840
|
});
|
|
1843
1841
|
}
|
|
1844
|
-
else if (userNamespaceForwardDecls.length > 0 && nlohmannNamespaceForwardDecls.length
|
|
1842
|
+
else if (userNamespaceForwardDecls.length > 0 && nlohmannNamespaceForwardDecls.length === 0) {
|
|
1845
1843
|
this.emitNamespaces(this._namespaceNames, () => {
|
|
1846
1844
|
this.emitGatheredSource(userNamespaceForwardDecls);
|
|
1847
1845
|
this.emitUserNamespaceImpls();
|
|
@@ -1998,7 +1996,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1998
1996
|
}
|
|
1999
1997
|
}
|
|
2000
1998
|
emitDefinition(d, defName) {
|
|
2001
|
-
const name = this.sourcelikeToString(defName)
|
|
1999
|
+
const name = `${this.sourcelikeToString(defName)}.hpp`;
|
|
2002
2000
|
this.startFile(name, true);
|
|
2003
2001
|
this._generatedFiles.add(name);
|
|
2004
2002
|
this.emitIncludes(d, this.sourcelikeToString(defName));
|