quicktype-core 6.1.0 → 6.1.1
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/MarkovChain.js +2 -2
- package/dist/attributes/Description.js +1 -1
- package/dist/attributes/TypeNames.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/input/JSONSchemaInput.js +4 -4
- package/dist/input/io/NodeIO.js +11 -8
- package/dist/language/CPlusPlus.js +2 -2
- package/dist/language/Dart.js +1 -1
- package/dist/language/Java.js +1 -0
- package/dist/language/Kotlin.js +6 -22
- package/dist/language/Objective-C.js +3 -3
- package/dist/language/Rust.js +7 -1
- package/dist/language/Swift.d.ts +0 -2
- package/dist/language/Swift.js +22 -55
- package/dist/language/TypeScriptFlow.js +4 -0
- package/dist/support/Strings.js +1 -1
- package/package.json +2 -2
- package/dist/AccessorNames.d.ts +0 -18
- package/dist/AccessorNames.js +0 -181
- package/dist/Constraints.d.ts +0 -38
- package/dist/Constraints.js +0 -165
- package/dist/Description.d.ts +0 -9
- package/dist/Description.js +0 -96
- package/dist/EnumValues.d.ts +0 -8
- package/dist/EnumValues.js +0 -30
- package/dist/StringTypes.d.ts +0 -28
- package/dist/StringTypes.js +0 -186
- package/dist/TypeAttributes.d.ts +0 -34
- package/dist/TypeAttributes.js +0 -117
- package/dist/TypeNames.d.ts +0 -46
- package/dist/TypeNames.js +0 -246
- package/dist/URIAttributes.d.ts +0 -11
- package/dist/URIAttributes.js +0 -78
- package/dist/get-stream/buffer-stream.d.ts +0 -2
- package/dist/get-stream/buffer-stream.js +0 -45
- package/dist/get-stream/index.d.ts +0 -10
- package/dist/get-stream/index.js +0 -48
package/dist/MarkovChain.js
CHANGED
|
@@ -61,7 +61,7 @@ function train(lines, depth) {
|
|
|
61
61
|
const trie = makeTrie();
|
|
62
62
|
for (const l of lines) {
|
|
63
63
|
for (let i = depth; i <= l.length; i++) {
|
|
64
|
-
increment(trie, l.
|
|
64
|
+
increment(trie, l.slice(i - depth, i), 0);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
return { trie, depth };
|
|
@@ -79,7 +79,7 @@ function evaluateFull(mc, word) {
|
|
|
79
79
|
let p = 1;
|
|
80
80
|
const scores = [];
|
|
81
81
|
for (let i = depth; i <= word.length; i++) {
|
|
82
|
-
let cp = lookup(trie, word.
|
|
82
|
+
let cp = lookup(trie, word.slice(i - depth, i), 0);
|
|
83
83
|
if (typeof cp === "object") {
|
|
84
84
|
return Support_1.panic("Did we mess up the depth?");
|
|
85
85
|
}
|
|
@@ -27,7 +27,7 @@ class DescriptionTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
|
27
27
|
if (result === undefined)
|
|
28
28
|
return undefined;
|
|
29
29
|
if (result.length > 5 + 3) {
|
|
30
|
-
result = `${result.
|
|
30
|
+
result = `${result.slice(0, 5)}...`;
|
|
31
31
|
}
|
|
32
32
|
if (descriptions.size > 1) {
|
|
33
33
|
result = `${result}, ...`;
|
|
@@ -60,8 +60,8 @@ function combineNames(names) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const prefix = prefixLength > 2 ? first.
|
|
64
|
-
const suffix = suffixLength > 2 ? first.
|
|
63
|
+
const prefix = prefixLength > 2 ? first.slice(0, prefixLength) : "";
|
|
64
|
+
const suffix = suffixLength > 2 ? first.slice(first.length - suffixLength) : "";
|
|
65
65
|
const combined = prefix + suffix;
|
|
66
66
|
if (combined.length > 2) {
|
|
67
67
|
return combined;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Input, InputData, JSONInput, JSONSourceData, jsonInputForTargetLanguage
|
|
|
4
4
|
export { JSONSchemaInput, JSONSchemaSourceData } from "./input/JSONSchemaInput";
|
|
5
5
|
export { Ref, JSONSchemaType, JSONSchemaAttributes } from "./input/JSONSchemaInput";
|
|
6
6
|
export { RenderContext } from "./Renderer";
|
|
7
|
-
export { Option, OptionDefinition, getOptionValues } from "./RendererOptions";
|
|
7
|
+
export { Option, OptionDefinition, getOptionValues, OptionValues } from "./RendererOptions";
|
|
8
8
|
export { TargetLanguage, MultiFileRenderResult } from "./TargetLanguage";
|
|
9
9
|
export { all as defaultTargetLanguages, languageNamed } from "./language/All";
|
|
10
10
|
export { MultiWord, Sourcelike, SerializedRenderResult, Annotation, modifySource, singleWord, parenIfNeeded } from "./Source";
|
|
@@ -104,7 +104,7 @@ class Ref {
|
|
|
104
104
|
const elements = [];
|
|
105
105
|
if (path.startsWith("/")) {
|
|
106
106
|
elements.push({ kind: PathElementKind.Root });
|
|
107
|
-
path = path.
|
|
107
|
+
path = path.slice(1);
|
|
108
108
|
}
|
|
109
109
|
if (path !== "") {
|
|
110
110
|
const parts = path.split("/");
|
|
@@ -171,7 +171,7 @@ class Ref {
|
|
|
171
171
|
let name = this.addressURI !== undefined ? this.addressURI.filename() : "";
|
|
172
172
|
const suffix = this.addressURI !== undefined ? this.addressURI.suffix() : "";
|
|
173
173
|
if (name.length > suffix.length + 1) {
|
|
174
|
-
name = name.
|
|
174
|
+
name = name.slice(0, name.length - suffix.length - 1);
|
|
175
175
|
}
|
|
176
176
|
if (name === "") {
|
|
177
177
|
return "Something";
|
|
@@ -853,7 +853,7 @@ function removeExtension(fn) {
|
|
|
853
853
|
const extensions = [".json", ".schema"];
|
|
854
854
|
for (const ext of extensions) {
|
|
855
855
|
if (lower.endsWith(ext)) {
|
|
856
|
-
const base = fn.
|
|
856
|
+
const base = fn.slice(0, fn.length - ext.length);
|
|
857
857
|
if (base.length > 0) {
|
|
858
858
|
return base;
|
|
859
859
|
}
|
|
@@ -884,7 +884,7 @@ function refsInSchemaForURI(resolver, uri, defaultName) {
|
|
|
884
884
|
const fragment = uri.fragment();
|
|
885
885
|
let propertiesAreTypes = fragment.endsWith("/");
|
|
886
886
|
if (propertiesAreTypes) {
|
|
887
|
-
uri = uri.clone().fragment(fragment.
|
|
887
|
+
uri = uri.clone().fragment(fragment.slice(0, -1));
|
|
888
888
|
}
|
|
889
889
|
const ref = Ref.parseURI(uri);
|
|
890
890
|
if (ref.isRoot) {
|
package/dist/input/io/NodeIO.js
CHANGED
|
@@ -35,19 +35,22 @@ function parseHeaders(httpHeaders) {
|
|
|
35
35
|
function readableFromFileOrURL(fileOrURL, httpHeaders) {
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
try {
|
|
38
|
-
if (
|
|
39
|
-
// Cast node readable to isomorphic readable from readable-stream
|
|
40
|
-
return process.stdin;
|
|
41
|
-
}
|
|
42
|
-
else if (isURL(fileOrURL)) {
|
|
38
|
+
if (isURL(fileOrURL)) {
|
|
43
39
|
const response = yield fetch(fileOrURL, {
|
|
44
40
|
headers: parseHeaders(httpHeaders)
|
|
45
41
|
});
|
|
46
42
|
return response.body;
|
|
47
43
|
}
|
|
48
|
-
else if (browser_or_node_1.isNode
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
else if (browser_or_node_1.isNode) {
|
|
45
|
+
if (fileOrURL === "-") {
|
|
46
|
+
// Cast node readable to isomorphic readable from readable-stream
|
|
47
|
+
return process.stdin;
|
|
48
|
+
}
|
|
49
|
+
const filePath = fs.lstatSync(fileOrURL).isSymbolicLink() ? fs.readlinkSync(fileOrURL) : fileOrURL;
|
|
50
|
+
if (fs.existsSync(filePath)) {
|
|
51
|
+
// Cast node readable to isomorphic readable from readable-stream
|
|
52
|
+
return fs.createReadStream(filePath, "utf8");
|
|
53
|
+
}
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
catch (e) {
|
|
@@ -438,13 +438,13 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
438
438
|
name: MemberNames.MinValue,
|
|
439
439
|
getter: MemberNames.GetMinValue,
|
|
440
440
|
setter: MemberNames.SetMinValue,
|
|
441
|
-
cppType: "
|
|
441
|
+
cppType: "int64_t"
|
|
442
442
|
},
|
|
443
443
|
{
|
|
444
444
|
name: MemberNames.MaxValue,
|
|
445
445
|
getter: MemberNames.GetMaxValue,
|
|
446
446
|
setter: MemberNames.SetMaxValue,
|
|
447
|
-
cppType: "
|
|
447
|
+
cppType: "int64_t"
|
|
448
448
|
},
|
|
449
449
|
{
|
|
450
450
|
name: MemberNames.MinLength,
|
package/dist/language/Dart.js
CHANGED
|
@@ -349,7 +349,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
349
349
|
this.emitLine(className, "({");
|
|
350
350
|
this.indent(() => {
|
|
351
351
|
this.forEachClassProperty(c, "none", (name, _, _p) => {
|
|
352
|
-
this.emitLine(this._options.requiredProperties ? "
|
|
352
|
+
this.emitLine(this._options.requiredProperties ? "required " : "", "this.", name, ",");
|
|
353
353
|
});
|
|
354
354
|
});
|
|
355
355
|
this.emitLine("});");
|
package/dist/language/Java.js
CHANGED
package/dist/language/Kotlin.js
CHANGED
|
@@ -735,12 +735,12 @@ class KotlinXRenderer extends KotlinRenderer {
|
|
|
735
735
|
super(targetLanguage, renderContext, _kotlinOptions);
|
|
736
736
|
}
|
|
737
737
|
anySourceType(optional) {
|
|
738
|
-
return ["
|
|
738
|
+
return ["JsonElement", optional];
|
|
739
739
|
}
|
|
740
740
|
arrayType(arrayType, withIssues = false, noOptional = false) {
|
|
741
741
|
const valType = this.kotlinType(arrayType.items, withIssues, true);
|
|
742
742
|
const name = this.sourcelikeToString(valType);
|
|
743
|
-
if (name === "JsonObject") {
|
|
743
|
+
if (name === "JsonObject" || name === "JsonElement") {
|
|
744
744
|
return "JsonArray";
|
|
745
745
|
}
|
|
746
746
|
return super.arrayType(arrayType, withIssues, noOptional);
|
|
@@ -748,7 +748,7 @@ class KotlinXRenderer extends KotlinRenderer {
|
|
|
748
748
|
mapType(mapType, withIssues = false, noOptional = false) {
|
|
749
749
|
const valType = this.kotlinType(mapType.values, withIssues, true);
|
|
750
750
|
const name = this.sourcelikeToString(valType);
|
|
751
|
-
if (name === "JsonObject") {
|
|
751
|
+
if (name === "JsonObject" || name === "JsonElement") {
|
|
752
752
|
return "JsonObject";
|
|
753
753
|
}
|
|
754
754
|
return super.mapType(mapType, withIssues, noOptional);
|
|
@@ -802,28 +802,12 @@ class KotlinXRenderer extends KotlinRenderer {
|
|
|
802
802
|
}
|
|
803
803
|
emitEnumDefinition(e, enumName) {
|
|
804
804
|
this.emitDescription(this.descriptionForType(e));
|
|
805
|
-
this.emitLine(["@Serializable
|
|
805
|
+
this.emitLine(["@Serializable"]);
|
|
806
806
|
this.emitBlock(["enum class ", enumName, "(val value: String)"], () => {
|
|
807
807
|
let count = e.cases.size;
|
|
808
808
|
this.forEachEnumCase(e, "none", (name, json) => {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
this.ensureBlankLine();
|
|
812
|
-
this.emitBlock(["companion object : KSerializer<", enumName, ">"], () => {
|
|
813
|
-
this.emitBlock("override val descriptor: SerialDescriptor get()", () => {
|
|
814
|
-
this.emitLine("return PrimitiveSerialDescriptor(\"", this._kotlinOptions.packageName, ".", enumName, "\", PrimitiveKind.STRING)");
|
|
815
|
-
});
|
|
816
|
-
this.emitBlock(["override fun deserialize(decoder: Decoder): ", enumName, " = when (val value = decoder.decodeString())"], () => {
|
|
817
|
-
let table = [];
|
|
818
|
-
this.forEachEnumCase(e, "none", (name, json) => {
|
|
819
|
-
table.push([[`"${stringEscape(json)}"`], [" -> ", name]]);
|
|
820
|
-
});
|
|
821
|
-
table.push([["else"], [" -> throw IllegalArgumentException(\"", enumName, " could not parse: $value\")"]]);
|
|
822
|
-
this.emitTable(table);
|
|
823
|
-
});
|
|
824
|
-
this.emitBlock(["override fun serialize(encoder: Encoder, value: ", enumName, ")"], () => {
|
|
825
|
-
this.emitLine(["return encoder.encodeString(value.value)"]);
|
|
826
|
-
});
|
|
809
|
+
const jsonEnum = stringEscape(json);
|
|
810
|
+
this.emitLine(`@SerialName("${jsonEnum}") `, name, `("${jsonEnum}")`, --count === 0 ? ";" : ",");
|
|
827
811
|
});
|
|
828
812
|
});
|
|
829
813
|
}
|
|
@@ -162,7 +162,7 @@ const forbiddenForEnumCases = ["new", staticEnumValuesIdentifier];
|
|
|
162
162
|
function splitExtension(filename) {
|
|
163
163
|
const i = filename.lastIndexOf(".");
|
|
164
164
|
const extension = i !== -1 ? filename.split(".").pop() : "m";
|
|
165
|
-
filename = i !== -1 ? filename.
|
|
165
|
+
filename = i !== -1 ? filename.slice(0, i) : filename;
|
|
166
166
|
return [filename, extension === undefined ? "m" : extension];
|
|
167
167
|
}
|
|
168
168
|
class ObjectiveCRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
@@ -186,7 +186,7 @@ class ObjectiveCRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
186
186
|
}
|
|
187
187
|
if (firstNonUpper < 2)
|
|
188
188
|
return DEFAULT_CLASS_PREFIX;
|
|
189
|
-
return name.
|
|
189
|
+
return name.slice(0, firstNonUpper - 1);
|
|
190
190
|
}
|
|
191
191
|
forbiddenNamesForGlobalNamespace() {
|
|
192
192
|
return keywords;
|
|
@@ -605,7 +605,7 @@ class ObjectiveCRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
605
605
|
variableNameForTopLevel(name) {
|
|
606
606
|
const camelCaseName = Source_1.modifySource(serialized => {
|
|
607
607
|
// 1. remove class prefix
|
|
608
|
-
serialized = serialized.
|
|
608
|
+
serialized = serialized.slice(this._classPrefix.length);
|
|
609
609
|
// 2. camel case
|
|
610
610
|
return Strings_1.camelCase(serialized);
|
|
611
611
|
}, name);
|
package/dist/language/Rust.js
CHANGED
|
@@ -43,7 +43,13 @@ class RustTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
43
43
|
super("Rust", ["rust", "rs", "rustlang"], "rs");
|
|
44
44
|
}
|
|
45
45
|
getOptions() {
|
|
46
|
-
return [
|
|
46
|
+
return [
|
|
47
|
+
exports.rustOptions.density,
|
|
48
|
+
exports.rustOptions.visibility,
|
|
49
|
+
exports.rustOptions.deriveDebug,
|
|
50
|
+
exports.rustOptions.edition2018,
|
|
51
|
+
exports.rustOptions.leadingComments
|
|
52
|
+
];
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
exports.RustTargetLanguage = RustTargetLanguage;
|
package/dist/language/Swift.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare const swiftOptions: {
|
|
|
12
12
|
justTypes: BooleanOption;
|
|
13
13
|
convenienceInitializers: BooleanOption;
|
|
14
14
|
explicitCodingKeys: BooleanOption;
|
|
15
|
-
urlSession: BooleanOption;
|
|
16
15
|
alamofire: BooleanOption;
|
|
17
16
|
namedTypePrefix: StringOption;
|
|
18
17
|
useClasses: EnumOption<boolean>;
|
|
@@ -92,6 +91,5 @@ export declare class SwiftRenderer extends ConvenienceRenderer {
|
|
|
92
91
|
private emitConvenienceMutator;
|
|
93
92
|
protected emitMark(line: Sourcelike, horizontalLine?: boolean): void;
|
|
94
93
|
protected emitSourceStructure(): void;
|
|
95
|
-
private emitURLSessionExtension;
|
|
96
94
|
private emitAlamofireExtension;
|
|
97
95
|
}
|
package/dist/language/Swift.js
CHANGED
|
@@ -19,18 +19,26 @@ exports.swiftOptions = {
|
|
|
19
19
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
20
20
|
convenienceInitializers: new RendererOptions_1.BooleanOption("initializers", "Generate initializers and mutators", true),
|
|
21
21
|
explicitCodingKeys: new RendererOptions_1.BooleanOption("coding-keys", "Explicit CodingKey values in Codable types", true),
|
|
22
|
-
urlSession: new RendererOptions_1.BooleanOption("url-session", "URLSession task extensions", false),
|
|
23
22
|
alamofire: new RendererOptions_1.BooleanOption("alamofire", "Alamofire extensions", false),
|
|
24
23
|
namedTypePrefix: new RendererOptions_1.StringOption("type-prefix", "Prefix for type names", "PREFIX", "", "secondary"),
|
|
25
|
-
useClasses: new RendererOptions_1.EnumOption("struct-or-class", "Structs or classes", [
|
|
24
|
+
useClasses: new RendererOptions_1.EnumOption("struct-or-class", "Structs or classes", [
|
|
25
|
+
["struct", false],
|
|
26
|
+
["class", true]
|
|
27
|
+
]),
|
|
26
28
|
mutableProperties: new RendererOptions_1.BooleanOption("mutable-properties", "Use var instead of let for object properties", false),
|
|
27
29
|
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
28
|
-
dense: new RendererOptions_1.EnumOption("density", "Code density", [
|
|
30
|
+
dense: new RendererOptions_1.EnumOption("density", "Code density", [
|
|
31
|
+
["dense", true],
|
|
32
|
+
["normal", false]
|
|
33
|
+
], "dense", "secondary"),
|
|
29
34
|
linux: new RendererOptions_1.BooleanOption("support-linux", "Support Linux", false, "secondary"),
|
|
30
35
|
objcSupport: new RendererOptions_1.BooleanOption("objective-c-support", "Objects inherit from NSObject and @objcMembers is added to classes", false),
|
|
31
36
|
swift5Support: new RendererOptions_1.BooleanOption("swift-5-support", "Renders output in a Swift 5 compatible mode", false),
|
|
32
37
|
multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Swift file", false),
|
|
33
|
-
accessLevel: new RendererOptions_1.EnumOption("access-level", "Access level", [
|
|
38
|
+
accessLevel: new RendererOptions_1.EnumOption("access-level", "Access level", [
|
|
39
|
+
["internal", "internal"],
|
|
40
|
+
["public", "public"]
|
|
41
|
+
], "internal", "secondary"),
|
|
34
42
|
protocol: new RendererOptions_1.EnumOption("protocol", "Make types implement protocol", [
|
|
35
43
|
["none", { equatable: false, hashable: false }],
|
|
36
44
|
["equatable", { equatable: true, hashable: false }],
|
|
@@ -65,7 +73,6 @@ class SwiftTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
65
73
|
exports.swiftOptions.convenienceInitializers,
|
|
66
74
|
exports.swiftOptions.explicitCodingKeys,
|
|
67
75
|
exports.swiftOptions.accessLevel,
|
|
68
|
-
exports.swiftOptions.urlSession,
|
|
69
76
|
exports.swiftOptions.alamofire,
|
|
70
77
|
exports.swiftOptions.linux,
|
|
71
78
|
exports.swiftOptions.namedTypePrefix,
|
|
@@ -97,6 +104,7 @@ class SwiftTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
97
104
|
}
|
|
98
105
|
exports.SwiftTargetLanguage = SwiftTargetLanguage;
|
|
99
106
|
const keywords = [
|
|
107
|
+
"await",
|
|
100
108
|
"associatedtype",
|
|
101
109
|
"class",
|
|
102
110
|
"deinit",
|
|
@@ -227,20 +235,12 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
227
235
|
this.ensureBlankLine();
|
|
228
236
|
this.forEachTopLevel("leading-and-interposing", (t, name) => this.emitTopLevelMapAndArrayConvenienceInitializerExtensions(t, name));
|
|
229
237
|
}
|
|
230
|
-
if ((!this._options.justTypes && this._options.convenienceInitializers) ||
|
|
231
|
-
this._options.urlSession ||
|
|
232
|
-
this._options.alamofire) {
|
|
238
|
+
if ((!this._options.justTypes && this._options.convenienceInitializers) || this._options.alamofire) {
|
|
233
239
|
this.ensureBlankLine();
|
|
234
240
|
this.emitMark("Helper functions for creating encoders and decoders", true);
|
|
235
241
|
this.ensureBlankLine();
|
|
236
242
|
this.emitNewEncoderDecoder();
|
|
237
243
|
}
|
|
238
|
-
if (this._options.urlSession) {
|
|
239
|
-
this.ensureBlankLine();
|
|
240
|
-
this.emitMark("URLSession response handlers", true);
|
|
241
|
-
this.ensureBlankLine();
|
|
242
|
-
this.emitURLSessionExtension();
|
|
243
|
-
}
|
|
244
244
|
if (this._options.alamofire) {
|
|
245
245
|
this.ensureBlankLine();
|
|
246
246
|
this.emitMark("Alamofire response handlers", true);
|
|
@@ -641,18 +641,6 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
641
641
|
this.emitLine("// let ", Source_1.modifySource(Strings_1.camelCase, name), " = ", "try? newJSONDecoder().decode(", name, ".self, from: jsonData)");
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
|
-
if (this._options.urlSession) {
|
|
645
|
-
this.emitLine("//");
|
|
646
|
-
this.emitLine("// To read values from URLs:");
|
|
647
|
-
const lowerName = Source_1.modifySource(Strings_1.camelCase, name);
|
|
648
|
-
this.emitLine("//");
|
|
649
|
-
this.emitLine("// let task = URLSession.shared.", lowerName, "Task(with: url) { ", lowerName, ", response, error in");
|
|
650
|
-
this.emitLine("// if let ", lowerName, " = ", lowerName, " {");
|
|
651
|
-
this.emitLine("// ...");
|
|
652
|
-
this.emitLine("// }");
|
|
653
|
-
this.emitLine("// }");
|
|
654
|
-
this.emitLine("// task.resume()");
|
|
655
|
-
}
|
|
656
644
|
if (this._options.alamofire) {
|
|
657
645
|
this.emitLine("//");
|
|
658
646
|
this.emitLine("// To parse values from Alamofire responses:");
|
|
@@ -756,7 +744,13 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
756
744
|
}
|
|
757
745
|
propertyLinesDefinition(name, parameter) {
|
|
758
746
|
const useMutableProperties = this._options.mutableProperties;
|
|
759
|
-
return [
|
|
747
|
+
return [
|
|
748
|
+
this.accessLevel,
|
|
749
|
+
useMutableProperties ? "var " : "let ",
|
|
750
|
+
name,
|
|
751
|
+
": ",
|
|
752
|
+
this.swiftPropertyType(parameter)
|
|
753
|
+
];
|
|
760
754
|
}
|
|
761
755
|
renderClassDefinition(c, className) {
|
|
762
756
|
this.startFile(className);
|
|
@@ -853,7 +847,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
853
847
|
}
|
|
854
848
|
if (this.propertyCount(c) === 0 && this._options.objcSupport) {
|
|
855
849
|
this.emitBlockWithAccess(["override init()"], () => {
|
|
856
|
-
"";
|
|
850
|
+
return "";
|
|
857
851
|
});
|
|
858
852
|
}
|
|
859
853
|
else {
|
|
@@ -1152,33 +1146,6 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
|
|
|
1152
1146
|
this.emitSupportFunctions4();
|
|
1153
1147
|
}
|
|
1154
1148
|
}
|
|
1155
|
-
emitURLSessionExtension() {
|
|
1156
|
-
this.ensureBlankLine();
|
|
1157
|
-
this.emitBlockWithAccess("extension URLSession", () => {
|
|
1158
|
-
this
|
|
1159
|
-
.emitMultiline(`fileprivate func codableTask<T: Codable>(with url: URL, completionHandler: @escaping (T?, URLResponse?, Error?) -> Void) -> URLSessionDataTask {
|
|
1160
|
-
return self.dataTask(with: url) { data, response, error in
|
|
1161
|
-
guard let data = data, error == nil else {
|
|
1162
|
-
completionHandler(nil, response, error)
|
|
1163
|
-
return
|
|
1164
|
-
}
|
|
1165
|
-
completionHandler(try? newJSONDecoder().decode(T.self, from: data), response, nil)
|
|
1166
|
-
}
|
|
1167
|
-
}`);
|
|
1168
|
-
this.ensureBlankLine();
|
|
1169
|
-
this.forEachTopLevel("leading-and-interposing", (_, name) => {
|
|
1170
|
-
this.emitBlock([
|
|
1171
|
-
"func ",
|
|
1172
|
-
Source_1.modifySource(Strings_1.camelCase, name),
|
|
1173
|
-
"Task(with url: URL, completionHandler: @escaping (",
|
|
1174
|
-
name,
|
|
1175
|
-
"?, URLResponse?, Error?) -> Void) -> URLSessionDataTask"
|
|
1176
|
-
], () => {
|
|
1177
|
-
this.emitLine(`return self.codableTask(with: url, completionHandler: completionHandler)`);
|
|
1178
|
-
});
|
|
1179
|
-
});
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
1149
|
emitAlamofireExtension() {
|
|
1183
1150
|
this.ensureBlankLine();
|
|
1184
1151
|
this.emitBlockWithAccess("extension DataRequest", () => {
|
|
@@ -119,6 +119,10 @@ class TypeScriptFlowBaseRenderer extends JavaScript_1.JavaScriptRenderer {
|
|
|
119
119
|
[this.sourceFor(t).source, ";"]
|
|
120
120
|
];
|
|
121
121
|
});
|
|
122
|
+
const additionalProperties = c.getAdditionalProperties();
|
|
123
|
+
if (additionalProperties) {
|
|
124
|
+
this.emitTable([["[property: string]", ": ", this.sourceFor(additionalProperties).source, ";"]]);
|
|
125
|
+
}
|
|
122
126
|
}
|
|
123
127
|
emitClass(c, className) {
|
|
124
128
|
this.emitDescription(this.descriptionForType(c));
|
package/dist/support/Strings.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quicktype-core",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "The quicktype engine as a library",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"fs": false
|
|
46
46
|
},
|
|
47
47
|
"config": {
|
|
48
|
-
"commit": "
|
|
48
|
+
"commit": "26b5da80a7fa3a91d11f7b3f76ff579e3a605645"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/dist/AccessorNames.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { TypeAttributeKind, TypeAttributes } from "./TypeAttributes";
|
|
2
|
-
import { EnumType, UnionType, Type, ObjectType } from "./Type";
|
|
3
|
-
import { JSONSchema } from "./input/JSONSchemaStore";
|
|
4
|
-
import { Ref, JSONSchemaType, JSONSchemaAttributes } from "./input/JSONSchemaInput";
|
|
5
|
-
export declare type AccessorEntry = string | Map<string, string>;
|
|
6
|
-
export declare type AccessorNames = Map<string, AccessorEntry>;
|
|
7
|
-
export declare const accessorNamesTypeAttributeKind: TypeAttributeKind<AccessorNames>;
|
|
8
|
-
export declare function lookupKey(accessors: AccessorNames, key: string, language: string): [string, boolean] | undefined;
|
|
9
|
-
export declare function objectPropertyNames(o: ObjectType, language: string): Map<string, [string, boolean] | undefined>;
|
|
10
|
-
export declare function enumCaseNames(e: EnumType, language: string): Map<string, [string, boolean] | undefined>;
|
|
11
|
-
export declare function getAccessorName(names: Map<string, [string, boolean] | undefined>, original: string): [string | undefined, boolean];
|
|
12
|
-
export declare const unionIdentifierTypeAttributeKind: TypeAttributeKind<ReadonlySet<number>>;
|
|
13
|
-
export declare function makeUnionIdentifierAttribute(): TypeAttributes;
|
|
14
|
-
export declare const unionMemberNamesTypeAttributeKind: TypeAttributeKind<Map<number, AccessorEntry>>;
|
|
15
|
-
export declare function makeUnionMemberNamesAttribute(unionAttributes: TypeAttributes, entry: AccessorEntry): TypeAttributes;
|
|
16
|
-
export declare function unionMemberName(u: UnionType, member: Type, language: string): [string | undefined, boolean];
|
|
17
|
-
export declare function makeAccessorNames(x: any): AccessorNames;
|
|
18
|
-
export declare function accessorNamesAttributeProducer(schema: JSONSchema, canonicalRef: Ref, _types: Set<JSONSchemaType>, cases: JSONSchema[] | undefined): JSONSchemaAttributes | undefined;
|
package/dist/AccessorNames.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const collection_utils_1 = require("collection-utils");
|
|
4
|
-
const TypeAttributes_1 = require("./TypeAttributes");
|
|
5
|
-
const Support_1 = require("./support/Support");
|
|
6
|
-
const Messages_1 = require("./Messages");
|
|
7
|
-
class AccessorNamesTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
8
|
-
constructor() {
|
|
9
|
-
super("accessorNames");
|
|
10
|
-
}
|
|
11
|
-
makeInferred(_) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.accessorNamesTypeAttributeKind = new AccessorNamesTypeAttributeKind();
|
|
16
|
-
// Returns [name, isFixed].
|
|
17
|
-
function getFromEntry(entry, language) {
|
|
18
|
-
if (typeof entry === "string")
|
|
19
|
-
return [entry, false];
|
|
20
|
-
const maybeForLanguage = entry.get(language);
|
|
21
|
-
if (maybeForLanguage !== undefined)
|
|
22
|
-
return [maybeForLanguage, true];
|
|
23
|
-
const maybeWildcard = entry.get("*");
|
|
24
|
-
if (maybeWildcard !== undefined)
|
|
25
|
-
return [maybeWildcard, false];
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
function lookupKey(accessors, key, language) {
|
|
29
|
-
const entry = accessors.get(key);
|
|
30
|
-
if (entry === undefined)
|
|
31
|
-
return undefined;
|
|
32
|
-
return getFromEntry(entry, language);
|
|
33
|
-
}
|
|
34
|
-
exports.lookupKey = lookupKey;
|
|
35
|
-
function objectPropertyNames(o, language) {
|
|
36
|
-
const accessors = exports.accessorNamesTypeAttributeKind.tryGetInAttributes(o.getAttributes());
|
|
37
|
-
const map = o.getProperties();
|
|
38
|
-
if (accessors === undefined)
|
|
39
|
-
return collection_utils_1.mapMap(map, _ => undefined);
|
|
40
|
-
return collection_utils_1.mapMap(map, (_cp, n) => lookupKey(accessors, n, language));
|
|
41
|
-
}
|
|
42
|
-
exports.objectPropertyNames = objectPropertyNames;
|
|
43
|
-
function enumCaseNames(e, language) {
|
|
44
|
-
const accessors = exports.accessorNamesTypeAttributeKind.tryGetInAttributes(e.getAttributes());
|
|
45
|
-
if (accessors === undefined)
|
|
46
|
-
return collection_utils_1.mapMap(e.cases.entries(), _ => undefined);
|
|
47
|
-
return collection_utils_1.mapMap(e.cases.entries(), c => lookupKey(accessors, c, language));
|
|
48
|
-
}
|
|
49
|
-
exports.enumCaseNames = enumCaseNames;
|
|
50
|
-
function getAccessorName(names, original) {
|
|
51
|
-
const maybeName = names.get(original);
|
|
52
|
-
if (maybeName === undefined)
|
|
53
|
-
return [undefined, false];
|
|
54
|
-
return maybeName;
|
|
55
|
-
}
|
|
56
|
-
exports.getAccessorName = getAccessorName;
|
|
57
|
-
// Union members can be recombined and reordered, and unions are combined as well, so
|
|
58
|
-
// we can't just store an array of accessor entries in a union, one array entry for each
|
|
59
|
-
// union member. Instead, we give each union in the origin type graph a union identifier,
|
|
60
|
-
// and each union member type gets a map from union identifiers to accessor entries.
|
|
61
|
-
// That way, no matter how the types are recombined, if we find a union member, we can look
|
|
62
|
-
// up its union's identifier(s), and then look up the member's accessor entries for that
|
|
63
|
-
// identifier. Of course we might find more than one, potentially conflicting.
|
|
64
|
-
class UnionIdentifierTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
65
|
-
constructor() {
|
|
66
|
-
super("unionIdentifier");
|
|
67
|
-
}
|
|
68
|
-
combine(arr) {
|
|
69
|
-
return collection_utils_1.setUnionManyInto(new Set(), arr);
|
|
70
|
-
}
|
|
71
|
-
makeInferred(_) {
|
|
72
|
-
return new Set();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.unionIdentifierTypeAttributeKind = new UnionIdentifierTypeAttributeKind();
|
|
76
|
-
let nextUnionIdentifier = 0;
|
|
77
|
-
function makeUnionIdentifierAttribute() {
|
|
78
|
-
const attributes = exports.unionIdentifierTypeAttributeKind.makeAttributes(new Set([nextUnionIdentifier]));
|
|
79
|
-
nextUnionIdentifier += 1;
|
|
80
|
-
return attributes;
|
|
81
|
-
}
|
|
82
|
-
exports.makeUnionIdentifierAttribute = makeUnionIdentifierAttribute;
|
|
83
|
-
class UnionMemberNamesTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
84
|
-
constructor() {
|
|
85
|
-
super("unionMemberNames");
|
|
86
|
-
}
|
|
87
|
-
combine(arr) {
|
|
88
|
-
const result = new Map();
|
|
89
|
-
for (const m of arr) {
|
|
90
|
-
collection_utils_1.mapMergeInto(result, m);
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.unionMemberNamesTypeAttributeKind = new UnionMemberNamesTypeAttributeKind();
|
|
96
|
-
function makeUnionMemberNamesAttribute(unionAttributes, entry) {
|
|
97
|
-
const identifiers = Support_1.defined(exports.unionIdentifierTypeAttributeKind.tryGetInAttributes(unionAttributes));
|
|
98
|
-
const map = collection_utils_1.mapFromIterable(identifiers, _ => entry);
|
|
99
|
-
return exports.unionMemberNamesTypeAttributeKind.makeAttributes(map);
|
|
100
|
-
}
|
|
101
|
-
exports.makeUnionMemberNamesAttribute = makeUnionMemberNamesAttribute;
|
|
102
|
-
function unionMemberName(u, member, language) {
|
|
103
|
-
const identifiers = exports.unionIdentifierTypeAttributeKind.tryGetInAttributes(u.getAttributes());
|
|
104
|
-
if (identifiers === undefined)
|
|
105
|
-
return [undefined, false];
|
|
106
|
-
const memberNames = exports.unionMemberNamesTypeAttributeKind.tryGetInAttributes(member.getAttributes());
|
|
107
|
-
if (memberNames === undefined)
|
|
108
|
-
return [undefined, false];
|
|
109
|
-
const names = new Set();
|
|
110
|
-
const fixedNames = new Set();
|
|
111
|
-
for (const i of identifiers) {
|
|
112
|
-
const maybeEntry = memberNames.get(i);
|
|
113
|
-
if (maybeEntry === undefined)
|
|
114
|
-
continue;
|
|
115
|
-
const maybeName = getFromEntry(maybeEntry, language);
|
|
116
|
-
if (maybeName === undefined)
|
|
117
|
-
continue;
|
|
118
|
-
const [name, isNameFixed] = maybeName;
|
|
119
|
-
if (isNameFixed) {
|
|
120
|
-
fixedNames.add(name);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
names.add(name);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
let size;
|
|
127
|
-
let isFixed;
|
|
128
|
-
let first = collection_utils_1.iterableFirst(fixedNames);
|
|
129
|
-
if (first !== undefined) {
|
|
130
|
-
size = fixedNames.size;
|
|
131
|
-
isFixed = true;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
first = collection_utils_1.iterableFirst(names);
|
|
135
|
-
if (first === undefined)
|
|
136
|
-
return [undefined, false];
|
|
137
|
-
size = names.size;
|
|
138
|
-
isFixed = false;
|
|
139
|
-
}
|
|
140
|
-
Messages_1.messageAssert(size === 1, "SchemaMoreThanOneUnionMemberName", { names: Array.from(names) });
|
|
141
|
-
return [first, isFixed];
|
|
142
|
-
}
|
|
143
|
-
exports.unionMemberName = unionMemberName;
|
|
144
|
-
function isAccessorEntry(x) {
|
|
145
|
-
if (typeof x === "string") {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
return Support_1.isStringMap(x, (v) => typeof v === "string");
|
|
149
|
-
}
|
|
150
|
-
function makeAccessorEntry(ae) {
|
|
151
|
-
if (typeof ae === "string")
|
|
152
|
-
return ae;
|
|
153
|
-
return collection_utils_1.mapFromObject(ae);
|
|
154
|
-
}
|
|
155
|
-
function makeAccessorNames(x) {
|
|
156
|
-
// FIXME: Do proper error reporting
|
|
157
|
-
const stringMap = Support_1.checkStringMap(x, isAccessorEntry);
|
|
158
|
-
return collection_utils_1.mapMap(collection_utils_1.mapFromObject(stringMap), makeAccessorEntry);
|
|
159
|
-
}
|
|
160
|
-
exports.makeAccessorNames = makeAccessorNames;
|
|
161
|
-
function accessorNamesAttributeProducer(schema, canonicalRef, _types, cases) {
|
|
162
|
-
if (typeof schema !== "object")
|
|
163
|
-
return undefined;
|
|
164
|
-
const maybeAccessors = schema["qt-accessors"];
|
|
165
|
-
if (maybeAccessors === undefined)
|
|
166
|
-
return undefined;
|
|
167
|
-
if (cases === undefined) {
|
|
168
|
-
return { forType: exports.accessorNamesTypeAttributeKind.makeAttributes(makeAccessorNames(maybeAccessors)) };
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
const identifierAttribute = makeUnionIdentifierAttribute();
|
|
172
|
-
const accessors = Support_1.checkArray(maybeAccessors, isAccessorEntry);
|
|
173
|
-
Messages_1.messageAssert(cases.length === accessors.length, "SchemaWrongAccessorEntryArrayLength", {
|
|
174
|
-
operation: "oneOf",
|
|
175
|
-
ref: canonicalRef.push("oneOf")
|
|
176
|
-
});
|
|
177
|
-
const caseAttributes = accessors.map(accessor => makeUnionMemberNamesAttribute(identifierAttribute, makeAccessorEntry(accessor)));
|
|
178
|
-
return { forUnion: identifierAttribute, forCases: caseAttributes };
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.accessorNamesAttributeProducer = accessorNamesAttributeProducer;
|