quicktype-core 6.0.71 → 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.d.ts +2 -0
- package/dist/language/Kotlin.js +14 -30
- 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
|
@@ -5,6 +5,7 @@ import { Sourcelike } from "../Source";
|
|
|
5
5
|
import { TargetLanguage } from "../TargetLanguage";
|
|
6
6
|
import { ArrayType, ClassType, EnumType, MapType, ObjectType, PrimitiveType, Type, UnionType } from "../Type";
|
|
7
7
|
import { RenderContext } from "../Renderer";
|
|
8
|
+
import { AcronymStyleOptions } from "../support/Acronyms";
|
|
8
9
|
export declare enum Framework {
|
|
9
10
|
None = 0,
|
|
10
11
|
Jackson = 1,
|
|
@@ -13,6 +14,7 @@ export declare enum Framework {
|
|
|
13
14
|
}
|
|
14
15
|
export declare const kotlinOptions: {
|
|
15
16
|
framework: EnumOption<Framework>;
|
|
17
|
+
acronymStyle: EnumOption<AcronymStyleOptions>;
|
|
16
18
|
packageName: StringOption;
|
|
17
19
|
};
|
|
18
20
|
export declare class KotlinTargetLanguage extends TargetLanguage {
|
package/dist/language/Kotlin.js
CHANGED
|
@@ -11,6 +11,7 @@ const Support_1 = require("../support/Support");
|
|
|
11
11
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
12
12
|
const Type_1 = require("../Type");
|
|
13
13
|
const TypeUtils_1 = require("../TypeUtils");
|
|
14
|
+
const Acronyms_1 = require("../support/Acronyms");
|
|
14
15
|
var Framework;
|
|
15
16
|
(function (Framework) {
|
|
16
17
|
Framework[Framework["None"] = 0] = "None";
|
|
@@ -20,6 +21,7 @@ var Framework;
|
|
|
20
21
|
})(Framework = exports.Framework || (exports.Framework = {}));
|
|
21
22
|
exports.kotlinOptions = {
|
|
22
23
|
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [["just-types", Framework.None], ["jackson", Framework.Jackson], ["klaxon", Framework.Klaxon], ["kotlinx", Framework.KotlinX]], "klaxon"),
|
|
24
|
+
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
23
25
|
packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
|
|
24
26
|
};
|
|
25
27
|
class KotlinTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
@@ -27,7 +29,7 @@ class KotlinTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
27
29
|
super("Kotlin", ["kotlin"], "kt");
|
|
28
30
|
}
|
|
29
31
|
getOptions() {
|
|
30
|
-
return [exports.kotlinOptions.framework, exports.kotlinOptions.packageName];
|
|
32
|
+
return [exports.kotlinOptions.framework, exports.kotlinOptions.acronymStyle, exports.kotlinOptions.packageName];
|
|
31
33
|
}
|
|
32
34
|
get supportsOptionalClassProperties() {
|
|
33
35
|
return true;
|
|
@@ -110,9 +112,9 @@ function isStartCharacter(codePoint) {
|
|
|
110
112
|
return isPartCharacter(codePoint) && !Strings_1.isDigit(codePoint);
|
|
111
113
|
}
|
|
112
114
|
const legalizeName = Strings_1.legalizeCharacters(isPartCharacter);
|
|
113
|
-
function kotlinNameStyle(isUpper, original) {
|
|
115
|
+
function kotlinNameStyle(isUpper, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
114
116
|
const words = Strings_1.splitIntoWords(original);
|
|
115
|
-
return Strings_1.combineWords(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle,
|
|
117
|
+
return Strings_1.combineWords(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, "", isStartCharacter);
|
|
116
118
|
}
|
|
117
119
|
function unicodeEscape(codePoint) {
|
|
118
120
|
return "\\u" + Strings_1.intToHex(codePoint, 4);
|
|
@@ -122,8 +124,6 @@ function stringEscape(s) {
|
|
|
122
124
|
// "$this" is a template string in Kotlin so we have to escape $
|
|
123
125
|
return _stringEscape(s).replace(/\$/g, "\\$");
|
|
124
126
|
}
|
|
125
|
-
const upperNamingFunction = Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s));
|
|
126
|
-
const lowerNamingFunction = Naming_1.funPrefixNamer("lower", s => kotlinNameStyle(false, s));
|
|
127
127
|
class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
128
128
|
constructor(targetLanguage, renderContext, _kotlinOptions) {
|
|
129
129
|
super(targetLanguage, renderContext);
|
|
@@ -145,16 +145,16 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
145
145
|
return kotlinNameStyle(true, rawName);
|
|
146
146
|
}
|
|
147
147
|
makeNamedTypeNamer() {
|
|
148
|
-
return
|
|
148
|
+
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
149
149
|
}
|
|
150
150
|
namerForObjectProperty() {
|
|
151
|
-
return
|
|
151
|
+
return Naming_1.funPrefixNamer("lower", s => kotlinNameStyle(false, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
152
152
|
}
|
|
153
153
|
makeUnionMemberNamer() {
|
|
154
154
|
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s) + "Value");
|
|
155
155
|
}
|
|
156
156
|
makeEnumCaseNamer() {
|
|
157
|
-
return
|
|
157
|
+
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
158
158
|
}
|
|
159
159
|
emitDescriptionBlock(lines) {
|
|
160
160
|
this.emitCommentLines(lines, " * ", "/**", " */");
|
|
@@ -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.
|
|
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;
|