quicktype-core 23.1.0 → 23.1.2
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.
|
@@ -204,7 +204,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
204
204
|
// };
|
|
205
205
|
//
|
|
206
206
|
// checking to see if the collapse of the variant has
|
|
207
|
-
//
|
|
207
|
+
// occurred and then doing the isCycleBreakerType check
|
|
208
208
|
// on the single type the variant would contain seems
|
|
209
209
|
// to solve the problem. But does this point to a problem
|
|
210
210
|
// with the core library or with the CPlusPlus package
|
|
@@ -733,7 +733,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
733
733
|
if (constraints === undefined)
|
|
734
734
|
return;
|
|
735
735
|
const { minMax, minMaxLength, pattern } = constraints;
|
|
736
|
-
// TODO is there a better way to check if property.type is an
|
|
736
|
+
// TODO is there a better way to check if property.type is an integer or a number?
|
|
737
737
|
const cppType = this.cppType(property.type, {
|
|
738
738
|
needsForwardIndirection: true,
|
|
739
739
|
needsOptionalIndirection: true,
|
|
@@ -1171,7 +1171,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1171
1171
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1172
1172
|
this.emitLine("case ", ourQualifier, enumName, "::", name, ": j = ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), "; break;");
|
|
1173
1173
|
});
|
|
1174
|
-
this.emitLine(`default: throw std::runtime_error("Unexpected value in enumeration \\"
|
|
1174
|
+
this.emitLine(`default: throw std::runtime_error("Unexpected value in enumeration \\"`, enumName, `\\": " + std::to_string(static_cast<int>(x)));`);
|
|
1175
1175
|
});
|
|
1176
1176
|
});
|
|
1177
1177
|
}
|
|
@@ -41,11 +41,13 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
|
|
|
41
41
|
}
|
|
42
42
|
emitImports() {
|
|
43
43
|
this.ensureBlankLine();
|
|
44
|
-
this.emitLine(this.importStatement("* as S", '"
|
|
44
|
+
this.emitLine(this.importStatement("* as S", '"effect/Schema"'));
|
|
45
45
|
}
|
|
46
46
|
typeMapTypeForProperty(p) {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (!p.isOptional) {
|
|
48
|
+
return this.typeMapTypeFor(p.type);
|
|
49
|
+
}
|
|
50
|
+
return ["S.optional(", this.typeMapTypeFor(p.type), ")"];
|
|
49
51
|
}
|
|
50
52
|
typeMapTypeFor(t, required = true) {
|
|
51
53
|
if (t.kind === "class" || t.kind === "object" || t.kind === "enum") {
|
|
@@ -55,9 +57,22 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
|
|
|
55
57
|
}
|
|
56
58
|
return ["S.suspend(() => ", name, ")"];
|
|
57
59
|
}
|
|
58
|
-
const match = (0, TypeUtils_1.matchType)(t, _anyType => "S.Any", _nullType => "S.Null", _boolType => "S.Boolean", _integerType => "S.Number", _doubleType => "S.Number", _stringType => "S.String", arrayType => ["S.Array(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, Support_1.panic)("Should already be handled."), _mapType => ["S.Record(S.String, ", this.typeMapTypeFor(_mapType.values, false), ")"], _enumType => (0, Support_1.panic)("Should already be handled."), unionType => {
|
|
59
|
-
const
|
|
60
|
-
|
|
60
|
+
const match = (0, TypeUtils_1.matchType)(t, _anyType => "S.Any", _nullType => "S.Null", _boolType => "S.Boolean", _integerType => "S.Number", _doubleType => "S.Number", _stringType => "S.String", arrayType => ["S.Array(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, Support_1.panic)("Should already be handled."), _mapType => ["S.Record({ key: S.String, value: ", this.typeMapTypeFor(_mapType.values, false), "})"], _enumType => (0, Support_1.panic)("Should already be handled."), unionType => {
|
|
61
|
+
const types = Array.from(unionType.getChildren());
|
|
62
|
+
let children = [];
|
|
63
|
+
let nullable = false;
|
|
64
|
+
for (const type of types) {
|
|
65
|
+
if (type.kind === "null") {
|
|
66
|
+
nullable = true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
children.push(this.typeMapTypeFor(type, false));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (nullable && children.length === 1) {
|
|
73
|
+
return ["S.NullOr(", children[0], ")"];
|
|
74
|
+
}
|
|
75
|
+
return ["S.Union(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), nullable ? ", S.Null)" : ")"];
|
|
61
76
|
}, _transformedStringType => {
|
|
62
77
|
return "S.String";
|
|
63
78
|
});
|
|
@@ -128,7 +128,7 @@ function expandStrings(ctx, graph, inference) {
|
|
|
128
128
|
const transformations = mappedStringTypes.transformations;
|
|
129
129
|
// FIXME: This is probably wrong, or at least overly conservative. This is for the case
|
|
130
130
|
// where some attributes are identity ones, i.e. where we can't merge the primitive types,
|
|
131
|
-
// like it happens in the line after the `if`. The case where this
|
|
131
|
+
// like it happens in the line after the `if`. The case where this occurred was with URI
|
|
132
132
|
// attributes: we had two separate string types with different URI attributes, but because
|
|
133
133
|
// both are rewritten via `getPrimitiveType` below without any attributes, they end up
|
|
134
134
|
// being the same string type.
|