quicktype 15.0.260 → 15.0.261
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/quicktype-core/ConvenienceRenderer.js +2 -6
- package/dist/quicktype-core/index.d.ts +1 -1
- package/dist/quicktype-core/index.js +1 -0
- package/dist/quicktype-core/language/CSharp.d.ts +2 -0
- package/dist/quicktype-core/language/CSharp.js +9 -3
- package/dist/quicktype-core/language/Dart.d.ts +3 -0
- package/dist/quicktype-core/language/Dart.js +31 -9
- package/dist/quicktype-core/language/Java.js +2 -1
- package/dist/quicktype-core/language/Kotlin.js +2 -2
- package/dist/quicktype-core/language/Swift.js +1 -1
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +1 -0
- package/dist/quicktype-core/language/TypeScriptFlow.js +21 -6
- package/dist/quicktype-core/language/ruby/index.js +10 -8
- package/dist/quicktype-core/support/Strings.d.ts +1 -0
- package/dist/quicktype-core/support/Strings.js +5 -0
- package/package.json +5 -5
|
@@ -26,9 +26,7 @@ const unionMemberNameOrder = 40;
|
|
|
26
26
|
function splitDescription(descriptions) {
|
|
27
27
|
if (descriptions === undefined)
|
|
28
28
|
return undefined;
|
|
29
|
-
const description = Array.from(descriptions)
|
|
30
|
-
.join("\n\n")
|
|
31
|
-
.trim();
|
|
29
|
+
const description = Array.from(descriptions).join("\n\n").trim();
|
|
32
30
|
if (description === "")
|
|
33
31
|
return undefined;
|
|
34
32
|
return wordWrap(description)
|
|
@@ -475,9 +473,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
475
473
|
});
|
|
476
474
|
}
|
|
477
475
|
nameForUnionMember(u, t) {
|
|
478
|
-
return Support_1.defined(Support_1.defined(this._memberNamesStoreView)
|
|
479
|
-
.get(u)
|
|
480
|
-
.get(t));
|
|
476
|
+
return Support_1.defined(Support_1.defined(this._memberNamesStoreView).get(u).get(t));
|
|
481
477
|
}
|
|
482
478
|
nameForEnumCase(e, caseName) {
|
|
483
479
|
const caseNames = Support_1.defined(this._caseNamesStoreView).get(e);
|
|
@@ -28,7 +28,7 @@ export { StringTypes } from "./attributes/StringTypes";
|
|
|
28
28
|
export { removeNullFromUnion, matchType, nullableFromUnion } from "./TypeUtils";
|
|
29
29
|
export { ConvenienceRenderer } from "./ConvenienceRenderer";
|
|
30
30
|
export { uriTypeAttributeKind } from "./attributes/URIAttributes";
|
|
31
|
-
export { CPlusPlusTargetLanguage, CPlusPlusRenderer } from "./language/CPlusPlus";
|
|
31
|
+
export { CPlusPlusTargetLanguage, CPlusPlusRenderer, cPlusPlusOptions } from "./language/CPlusPlus";
|
|
32
32
|
export { CSharpTargetLanguage, cSharpOptions, CSharpRenderer, NewtonsoftCSharpTargetLanguage, newtonsoftCSharpOptions, NewtonsoftCSharpRenderer } from "./language/CSharp";
|
|
33
33
|
export { GoTargetLanguage, GoRenderer, goOptions } from "./language/Golang";
|
|
34
34
|
export { ObjectiveCTargetLanguage, ObjectiveCRenderer, objcOptions } from "./language/Objective-C";
|
|
@@ -106,6 +106,7 @@ exports.uriTypeAttributeKind = URIAttributes_1.uriTypeAttributeKind;
|
|
|
106
106
|
var CPlusPlus_1 = require("./language/CPlusPlus");
|
|
107
107
|
exports.CPlusPlusTargetLanguage = CPlusPlus_1.CPlusPlusTargetLanguage;
|
|
108
108
|
exports.CPlusPlusRenderer = CPlusPlus_1.CPlusPlusRenderer;
|
|
109
|
+
exports.cPlusPlusOptions = CPlusPlus_1.cPlusPlusOptions;
|
|
109
110
|
var CSharp_1 = require("./language/CSharp");
|
|
110
111
|
exports.CSharpTargetLanguage = CSharp_1.CSharpTargetLanguage;
|
|
111
112
|
exports.cSharpOptions = CSharp_1.cSharpOptions;
|
|
@@ -23,6 +23,7 @@ export declare const cSharpOptions: {
|
|
|
23
23
|
dense: EnumOption<boolean>;
|
|
24
24
|
namespace: StringOption;
|
|
25
25
|
version: EnumOption<Version>;
|
|
26
|
+
virtual: BooleanOption;
|
|
26
27
|
typeForAny: EnumOption<CSharpTypeForAny>;
|
|
27
28
|
useDecimal: EnumOption<boolean>;
|
|
28
29
|
};
|
|
@@ -76,6 +77,7 @@ export declare const newtonsoftCSharpOptions: {
|
|
|
76
77
|
dense: EnumOption<boolean>;
|
|
77
78
|
namespace: StringOption;
|
|
78
79
|
version: EnumOption<Version>;
|
|
80
|
+
virtual: BooleanOption;
|
|
79
81
|
typeForAny: EnumOption<CSharpTypeForAny>;
|
|
80
82
|
useDecimal: EnumOption<boolean>;
|
|
81
83
|
} & {
|
|
@@ -87,6 +87,7 @@ exports.cSharpOptions = {
|
|
|
87
87
|
["5", 5],
|
|
88
88
|
["6", 6],
|
|
89
89
|
], "6", "secondary"),
|
|
90
|
+
virtual: new RendererOptions_1.BooleanOption("virtual", "Generate virtual properties", false),
|
|
90
91
|
typeForAny: new RendererOptions_1.EnumOption("any-type", 'Type to use for "any"', [
|
|
91
92
|
["object", "object"],
|
|
92
93
|
["dynamic", "dynamic"],
|
|
@@ -105,6 +106,7 @@ class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
105
106
|
exports.cSharpOptions.useList,
|
|
106
107
|
exports.cSharpOptions.useDecimal,
|
|
107
108
|
exports.cSharpOptions.typeForAny,
|
|
109
|
+
exports.cSharpOptions.virtual,
|
|
108
110
|
];
|
|
109
111
|
}
|
|
110
112
|
get stringTypeMapping() {
|
|
@@ -222,12 +224,12 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
222
224
|
return TypeUtils_1.matchType(actualType, (_anyType) => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this._csOptions.typeForAny), (_nullType) => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this._csOptions.typeForAny), (_boolType) => "bool", (_integerType) => "long", (_doubleType) => this.doubleType, (_stringType) => "string", (arrayType) => {
|
|
223
225
|
const itemsType = this.csType(arrayType.items, follow, withIssues);
|
|
224
226
|
if (this._csOptions.useList) {
|
|
225
|
-
return ["List<", itemsType, ">"];
|
|
227
|
+
return ["System.Collections.Generic.List<", itemsType, ">"];
|
|
226
228
|
}
|
|
227
229
|
else {
|
|
228
230
|
return [itemsType, "[]"];
|
|
229
231
|
}
|
|
230
|
-
}, (classType) => this.nameForNamedType(classType), (mapType) => ["Dictionary<string, ", this.csType(mapType.values, follow, withIssues), ">"], (enumType) => this.nameForNamedType(enumType), (unionType) => {
|
|
232
|
+
}, (classType) => this.nameForNamedType(classType), (mapType) => ["System.Collections.Generic.Dictionary<string, ", this.csType(mapType.values, follow, withIssues), ">"], (enumType) => this.nameForNamedType(enumType), (unionType) => {
|
|
231
233
|
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
232
234
|
if (nullable !== null)
|
|
233
235
|
return this.nullableCSType(nullable, noFollow);
|
|
@@ -275,7 +277,10 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
275
277
|
const csType = property.isOptional
|
|
276
278
|
? this.nullableCSType(t, Transformers_1.followTargetType, true)
|
|
277
279
|
: this.csType(t, Transformers_1.followTargetType, true);
|
|
278
|
-
|
|
280
|
+
const propertyArray = ["public "];
|
|
281
|
+
if (this._csOptions.virtual)
|
|
282
|
+
propertyArray.push("virtual ");
|
|
283
|
+
return [...propertyArray, csType, " ", name, " { get; set; }"];
|
|
279
284
|
}
|
|
280
285
|
emitDescriptionBlock(lines) {
|
|
281
286
|
const start = "/// <summary>";
|
|
@@ -471,6 +476,7 @@ class NewtonsoftCSharpTargetLanguage extends CSharpTargetLanguage {
|
|
|
471
476
|
exports.newtonsoftCSharpOptions.checkRequired,
|
|
472
477
|
exports.newtonsoftCSharpOptions.typeForAny,
|
|
473
478
|
exports.newtonsoftCSharpOptions.baseclass,
|
|
479
|
+
exports.newtonsoftCSharpOptions.virtual,
|
|
474
480
|
];
|
|
475
481
|
}
|
|
476
482
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
@@ -14,6 +14,7 @@ export declare const dartOptions: {
|
|
|
14
14
|
finalProperties: BooleanOption;
|
|
15
15
|
generateCopyWith: BooleanOption;
|
|
16
16
|
useFreezed: BooleanOption;
|
|
17
|
+
useHive: BooleanOption;
|
|
17
18
|
partName: StringOption;
|
|
18
19
|
};
|
|
19
20
|
export declare class DartTargetLanguage extends TargetLanguage {
|
|
@@ -29,6 +30,8 @@ export declare class DartRenderer extends ConvenienceRenderer {
|
|
|
29
30
|
private readonly _options;
|
|
30
31
|
private readonly _gettersAndSettersForPropertyName;
|
|
31
32
|
private _needEnumValues;
|
|
33
|
+
private classCounter;
|
|
34
|
+
private classPropertyCounter;
|
|
32
35
|
private readonly _topLevelDependents;
|
|
33
36
|
private readonly _enumValues;
|
|
34
37
|
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _options: OptionValues<typeof dartOptions>);
|
|
@@ -11,7 +11,6 @@ const RendererOptions_1 = require("../RendererOptions");
|
|
|
11
11
|
const Annotation_1 = require("../Annotation");
|
|
12
12
|
const Support_1 = require("../support/Support");
|
|
13
13
|
const collection_utils_1 = require("collection-utils");
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
14
|
exports.dartOptions = {
|
|
16
15
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Types only", false),
|
|
17
16
|
codersInClass: new RendererOptions_1.BooleanOption("coders-in-class", "Put encoder & decoder in Class", false),
|
|
@@ -20,7 +19,8 @@ exports.dartOptions = {
|
|
|
20
19
|
finalProperties: new RendererOptions_1.BooleanOption("final-props", "Make all properties final", false),
|
|
21
20
|
generateCopyWith: new RendererOptions_1.BooleanOption("copy-with", "Generate CopyWith method", false),
|
|
22
21
|
useFreezed: new RendererOptions_1.BooleanOption("use-freezed", "Generate class definitions with @freezed compatibility", false),
|
|
23
|
-
|
|
22
|
+
useHive: new RendererOptions_1.BooleanOption("use-hive", "Generate annotations for Hive type adapters", false),
|
|
23
|
+
partName: new RendererOptions_1.StringOption("part-name", "Use this name in `part` directive", "NAME", "")
|
|
24
24
|
};
|
|
25
25
|
class DartTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
26
26
|
constructor() {
|
|
@@ -35,7 +35,8 @@ class DartTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
35
35
|
exports.dartOptions.finalProperties,
|
|
36
36
|
exports.dartOptions.generateCopyWith,
|
|
37
37
|
exports.dartOptions.useFreezed,
|
|
38
|
-
exports.dartOptions.
|
|
38
|
+
exports.dartOptions.useHive,
|
|
39
|
+
exports.dartOptions.partName
|
|
39
40
|
];
|
|
40
41
|
}
|
|
41
42
|
get supportsUnionsWithBothNumberTypes() {
|
|
@@ -159,6 +160,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
159
160
|
this._options = _options;
|
|
160
161
|
this._gettersAndSettersForPropertyName = new Map();
|
|
161
162
|
this._needEnumValues = false;
|
|
163
|
+
this.classCounter = 0;
|
|
164
|
+
this.classPropertyCounter = 0;
|
|
162
165
|
this._topLevelDependents = new Map();
|
|
163
166
|
this._enumValues = new Map();
|
|
164
167
|
}
|
|
@@ -237,12 +240,18 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
237
240
|
if (this._options.useFreezed) {
|
|
238
241
|
this.emitLine("import 'package:freezed_annotation/freezed_annotation.dart';");
|
|
239
242
|
}
|
|
243
|
+
if (this._options.useHive) {
|
|
244
|
+
this.emitLine("import 'package:hive/hive.dart';");
|
|
245
|
+
}
|
|
240
246
|
this.emitLine("import 'dart:convert';");
|
|
241
|
-
if (this._options.useFreezed) {
|
|
247
|
+
if (this._options.useFreezed || this._options.useHive) {
|
|
242
248
|
this.ensureBlankLine();
|
|
243
249
|
const optionNameIsEmpty = this._options.partName.length === 0;
|
|
244
|
-
|
|
245
|
-
|
|
250
|
+
// FIXME: This should use a `Name`, not `modifySource`
|
|
251
|
+
const name = Source_1.modifySource(Strings_1.snakeCase, optionNameIsEmpty ? [...this.topLevels.keys()][0] : this._options.partName);
|
|
252
|
+
if (this._options.useFreezed) {
|
|
253
|
+
this.emitLine("part '", name, ".freezed.dart';");
|
|
254
|
+
}
|
|
246
255
|
if (!this._options.justTypes) {
|
|
247
256
|
this.emitLine("part '", name, ".g.dart';");
|
|
248
257
|
}
|
|
@@ -327,6 +336,11 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
327
336
|
}
|
|
328
337
|
emitClassDefinition(c, className) {
|
|
329
338
|
this.emitDescription(this.descriptionForType(c));
|
|
339
|
+
if (this._options.useHive) {
|
|
340
|
+
this.classCounter++;
|
|
341
|
+
this.emitLine(`@HiveType(typeId: ${this.classCounter})`);
|
|
342
|
+
this.classPropertyCounter = 0;
|
|
343
|
+
}
|
|
330
344
|
this.emitBlock(["class ", className], () => {
|
|
331
345
|
if (c.getProperties().size === 0) {
|
|
332
346
|
this.emitLine(className, "();");
|
|
@@ -340,7 +354,15 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
340
354
|
});
|
|
341
355
|
this.emitLine("});");
|
|
342
356
|
this.ensureBlankLine();
|
|
343
|
-
this.forEachClassProperty(c, "none", (name,
|
|
357
|
+
this.forEachClassProperty(c, "none", (name, jsonName, p) => {
|
|
358
|
+
const description = this.descriptionForClassProperty(c, jsonName);
|
|
359
|
+
if (description !== undefined) {
|
|
360
|
+
this.emitDescription(description);
|
|
361
|
+
}
|
|
362
|
+
if (this._options.useHive) {
|
|
363
|
+
this.classPropertyCounter++;
|
|
364
|
+
this.emitLine(`@HiveField(${this.classPropertyCounter})`);
|
|
365
|
+
}
|
|
344
366
|
this.emitLine(this._options.finalProperties ? "final " : "", this.dartType(p.type, true), " ", name, ";");
|
|
345
367
|
});
|
|
346
368
|
}
|
|
@@ -392,7 +414,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
392
414
|
emitFreezedClassDefinition(c, className) {
|
|
393
415
|
this.emitDescription(this.descriptionForType(c));
|
|
394
416
|
this.emitLine("@freezed");
|
|
395
|
-
this.emitBlock(["
|
|
417
|
+
this.emitBlock(["class ", className, " with _$", className], () => {
|
|
396
418
|
if (c.getProperties().size === 0) {
|
|
397
419
|
this.emitLine("const factory ", className, "() = _", className, ";");
|
|
398
420
|
}
|
|
@@ -400,7 +422,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
400
422
|
this.emitLine("const factory ", className, "({");
|
|
401
423
|
this.indent(() => {
|
|
402
424
|
this.forEachClassProperty(c, "none", (name, _, _p) => {
|
|
403
|
-
this.emitLine(this._options.requiredProperties ? "
|
|
425
|
+
this.emitLine(this._options.requiredProperties ? "required " : "", this.dartType(_p.type, true), this._options.requiredProperties ? "" : "?", " ", name, ",");
|
|
404
426
|
});
|
|
405
427
|
});
|
|
406
428
|
this.emitLine("}) = _", className, ";");
|
|
@@ -515,7 +515,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
515
515
|
javaTypeWithoutGenerics(reference, t) {
|
|
516
516
|
if (t instanceof Type_1.ArrayType) {
|
|
517
517
|
if (this._options.useList) {
|
|
518
|
-
return ["List
|
|
518
|
+
return ["List"];
|
|
519
519
|
}
|
|
520
520
|
else {
|
|
521
521
|
return [this.javaTypeWithoutGenerics(false, t.items), "[]"];
|
|
@@ -1055,6 +1055,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
1055
1055
|
const renderedForClass = this.javaTypeWithoutGenerics(false, topLevelType);
|
|
1056
1056
|
this.emitLine("ObjectMapper mapper = new ObjectMapper();");
|
|
1057
1057
|
this.emitLine("mapper.findAndRegisterModules();");
|
|
1058
|
+
this.emitLine("mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);");
|
|
1058
1059
|
this.emitLine("mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);");
|
|
1059
1060
|
this.emitOffsetDateTimeConverterModule();
|
|
1060
1061
|
this.emitLine(readerName, " = mapper.readerFor(", renderedForClass, ".class);");
|
|
@@ -770,7 +770,7 @@ class KotlinXRenderer extends KotlinRenderer {
|
|
|
770
770
|
this.emitLine("// To parse the JSON, install kotlin's serialization plugin and do:");
|
|
771
771
|
this.emitLine("//");
|
|
772
772
|
const table = [];
|
|
773
|
-
table.push(["// val ", "json", " = Json
|
|
773
|
+
table.push(["// val ", "json", " = Json { allowStructuredMapKeys = true }"]);
|
|
774
774
|
this.forEachTopLevel("none", (_, name) => {
|
|
775
775
|
table.push(["// val ", Source_1.modifySource(Strings_1.camelCase, name), ` = json.parse(${this.sourcelikeToString(name)}.serializer(), jsonString)`]);
|
|
776
776
|
});
|
|
@@ -802,7 +802,7 @@ 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(with = ", enumName, ".Companion::class)"]);
|
|
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) => {
|
|
@@ -621,7 +621,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
621
621
|
this.emitLineOnce("// let ", Source_1.modifySource(Strings_1.camelCase, topLevelName), " = try ", topLevelName, "(json)");
|
|
622
622
|
}
|
|
623
623
|
else {
|
|
624
|
-
this.emitLineOnce("// let ", Source_1.modifySource(Strings_1.camelCase, topLevelName), " = ", "try?
|
|
624
|
+
this.emitLineOnce("// let ", Source_1.modifySource(Strings_1.camelCase, topLevelName), " = ", "try? JSONDecoder().decode(", topLevelName, ".self, from: jsonData)");
|
|
625
625
|
}
|
|
626
626
|
});
|
|
627
627
|
}
|
|
@@ -15,6 +15,7 @@ export declare const tsFlowOptions: {
|
|
|
15
15
|
justTypes: BooleanOption;
|
|
16
16
|
nicePropertyNames: BooleanOption;
|
|
17
17
|
declareUnions: BooleanOption;
|
|
18
|
+
preferUnions: BooleanOption;
|
|
18
19
|
};
|
|
19
20
|
export declare abstract class TypeScriptFlowBaseTargetLanguage extends JavaScriptTargetLanguage {
|
|
20
21
|
protected getOptions(): Option<any>[];
|
|
@@ -12,7 +12,8 @@ const JavaScriptUnicodeMaps_1 = require("./JavaScriptUnicodeMaps");
|
|
|
12
12
|
exports.tsFlowOptions = Object.assign({}, JavaScript_1.javaScriptOptions, {
|
|
13
13
|
justTypes: new RendererOptions_1.BooleanOption("just-types", "Interfaces only", false),
|
|
14
14
|
nicePropertyNames: new RendererOptions_1.BooleanOption("nice-property-names", "Transform property names to be JavaScripty", false),
|
|
15
|
-
declareUnions: new RendererOptions_1.BooleanOption("explicit-unions", "Explicitly name unions", false)
|
|
15
|
+
declareUnions: new RendererOptions_1.BooleanOption("explicit-unions", "Explicitly name unions", false),
|
|
16
|
+
preferUnions: new RendererOptions_1.BooleanOption("prefer-unions", "Use union type instead of enum", false)
|
|
16
17
|
});
|
|
17
18
|
const tsFlowTypeAnnotations = {
|
|
18
19
|
any: ": any",
|
|
@@ -32,7 +33,8 @@ class TypeScriptFlowBaseTargetLanguage extends JavaScript_1.JavaScriptTargetLang
|
|
|
32
33
|
exports.tsFlowOptions.runtimeTypecheckIgnoreUnknownProperties,
|
|
33
34
|
exports.tsFlowOptions.acronymStyle,
|
|
34
35
|
exports.tsFlowOptions.converters,
|
|
35
|
-
exports.tsFlowOptions.rawType
|
|
36
|
+
exports.tsFlowOptions.rawType,
|
|
37
|
+
exports.tsFlowOptions.preferUnions
|
|
36
38
|
];
|
|
37
39
|
}
|
|
38
40
|
get supportsOptionalClassProperties() {
|
|
@@ -207,11 +209,24 @@ class TypeScriptRenderer extends TypeScriptFlowBaseRenderer {
|
|
|
207
209
|
}
|
|
208
210
|
emitEnum(e, enumName) {
|
|
209
211
|
this.emitDescription(this.descriptionForType(e));
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
if (this._tsFlowOptions.preferUnions) {
|
|
213
|
+
let items = "";
|
|
214
|
+
e.cases.forEach((item) => {
|
|
215
|
+
if (items === "") {
|
|
216
|
+
items += `"${Strings_1.utf16StringEscape(item)}"`;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
items += ` | "${Strings_1.utf16StringEscape(item)}"`;
|
|
213
220
|
});
|
|
214
|
-
|
|
221
|
+
this.emitLine("export type ", enumName, " = ", items, ";");
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.emitBlock(["export enum ", enumName, " "], "", () => {
|
|
225
|
+
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
226
|
+
this.emitLine(name, ` = "${Strings_1.utf16StringEscape(jsonName)}",`);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
215
230
|
}
|
|
216
231
|
emitClassBlock(c, className) {
|
|
217
232
|
this.emitBlock(["export interface ", className, " "], "", () => {
|
|
@@ -13,10 +13,6 @@ const Strings_1 = require("../../support/Strings");
|
|
|
13
13
|
function unicodeEscape(codePoint) {
|
|
14
14
|
return "\\u{" + Strings_1.intToHex(codePoint, 0) + "}";
|
|
15
15
|
}
|
|
16
|
-
function snakeCase(str) {
|
|
17
|
-
const words = Strings_1.splitIntoWords(str).map(({ word }) => word.toLowerCase());
|
|
18
|
-
return words.join("_");
|
|
19
|
-
}
|
|
20
16
|
const stringEscape = Strings_1.utf32ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isPrintable, unicodeEscape));
|
|
21
17
|
var Strictness;
|
|
22
18
|
(function (Strictness) {
|
|
@@ -284,11 +280,17 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
284
280
|
: // This will raise a runtime error if the key is not found in the hash
|
|
285
281
|
`d.fetch("${stringEscape(jsonName)}")`;
|
|
286
282
|
if (this.propertyTypeMarshalsImplicitlyFromDynamic(p.type)) {
|
|
287
|
-
inits.push([
|
|
283
|
+
inits.push([
|
|
284
|
+
[name, ": "],
|
|
285
|
+
[dynamic, ","]
|
|
286
|
+
]);
|
|
288
287
|
}
|
|
289
288
|
else {
|
|
290
289
|
const expression = this.fromDynamic(p.type, dynamic, p.isOptional);
|
|
291
|
-
inits.push([
|
|
290
|
+
inits.push([
|
|
291
|
+
[name, ": "],
|
|
292
|
+
[expression, ","]
|
|
293
|
+
]);
|
|
292
294
|
}
|
|
293
295
|
});
|
|
294
296
|
this.emitTable(inits);
|
|
@@ -452,7 +454,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
452
454
|
this.emitLine("# To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do:");
|
|
453
455
|
this.emitLine("#");
|
|
454
456
|
this.forEachTopLevel("none", (topLevel, name) => {
|
|
455
|
-
const variable = Source_1.modifySource(snakeCase, name);
|
|
457
|
+
const variable = Source_1.modifySource(Strings_1.snakeCase, name);
|
|
456
458
|
this.emitLine("# ", variable, " = ", name, ".from_json! ", this.jsonSample(topLevel));
|
|
457
459
|
this.emitLine("# puts ", this.exampleUse(topLevel, variable));
|
|
458
460
|
this.emitLine("#");
|
|
@@ -474,7 +476,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
474
476
|
this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClass(c, n), (e, n) => this.emitEnum(e, n), (u, n) => this.emitUnion(u, n));
|
|
475
477
|
if (!this._options.justTypes) {
|
|
476
478
|
this.forEachTopLevel("leading-and-interposing", (topLevel, name) => {
|
|
477
|
-
const self = Source_1.modifySource(snakeCase, name);
|
|
479
|
+
const self = Source_1.modifySource(Strings_1.snakeCase, name);
|
|
478
480
|
// The json gem defines to_json on maps and primitives, so we only need to supply
|
|
479
481
|
// it for arrays.
|
|
480
482
|
const needsToJsonDefined = "array" === topLevel.kind;
|
|
@@ -24,6 +24,7 @@ export declare function capitalize(str: string): string;
|
|
|
24
24
|
export declare function decapitalize(str: string): string;
|
|
25
25
|
export declare function pascalCase(str: string): string;
|
|
26
26
|
export declare function camelCase(str: string): string;
|
|
27
|
+
export declare function snakeCase(str: string): string;
|
|
27
28
|
export declare function startWithLetter(isAllowedStart: (codePoint: number) => boolean, // FIXME: technically, this operates on UTF16 units
|
|
28
29
|
upper: boolean, str: string): string;
|
|
29
30
|
export declare type WordInName = {
|
|
@@ -273,6 +273,11 @@ function camelCase(str) {
|
|
|
273
273
|
return decapitalize(pascalCase(str));
|
|
274
274
|
}
|
|
275
275
|
exports.camelCase = camelCase;
|
|
276
|
+
function snakeCase(str) {
|
|
277
|
+
const words = splitIntoWords(str).map(({ word }) => word.toLowerCase());
|
|
278
|
+
return words.join("_");
|
|
279
|
+
}
|
|
280
|
+
exports.snakeCase = snakeCase;
|
|
276
281
|
function startWithLetter(isAllowedStart, // FIXME: technically, this operates on UTF16 units
|
|
277
282
|
upper, str) {
|
|
278
283
|
const modify = upper ? capitalize : decapitalize;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quicktype",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.261",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/cli/index.js",
|
|
6
6
|
"types": "dist/cli/index.d.ts",
|
|
7
7
|
"repository": "https://github.com/quicktype/quicktype",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"pub": "
|
|
9
|
+
"pub": "script/publish.sh",
|
|
10
10
|
"prepare": "npm run build",
|
|
11
11
|
"build": "script/build.ts",
|
|
12
12
|
"test": "jest && script/test",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"graphql": "^0.11.7",
|
|
24
24
|
"is-url": "^1.2.4",
|
|
25
25
|
"js-base64": "^2.4.3",
|
|
26
|
-
"lodash": "^4.17.
|
|
26
|
+
"lodash": "^4.17.21",
|
|
27
27
|
"moment": "^2.22.1",
|
|
28
28
|
"node-fetch": "^2.6.1",
|
|
29
29
|
"pako": "^1.0.6",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "~3.2.1",
|
|
34
34
|
"@mark.probst/typescript-json-schema": "~0.32.0",
|
|
35
35
|
"@mark.probst/unicode-properties": "~1.1.0",
|
|
36
|
-
"urijs": "^1.19.
|
|
36
|
+
"urijs": "^1.19.6",
|
|
37
37
|
"uuid": "^3.2.1",
|
|
38
38
|
"wordwrap": "^1.0.0",
|
|
39
39
|
"yaml": "^1.5.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/yaml": "^1.0.2",
|
|
53
53
|
"ajv": "^5.5.2",
|
|
54
54
|
"deep-equal": "^1.0.1",
|
|
55
|
-
"elm": "0.
|
|
55
|
+
"elm": "0.18.0-exp5",
|
|
56
56
|
"exit": "^0.1.2",
|
|
57
57
|
"flow-bin": "^0.66.0",
|
|
58
58
|
"flow-remove-types": "^1.2.3",
|