quicktype-core 23.0.63 → 23.0.64
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/language/Dart.js +21 -11
- package/package.json +1 -1
package/dist/language/Dart.js
CHANGED
|
@@ -230,12 +230,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
230
230
|
}
|
|
231
231
|
if (this._options.justTypes)
|
|
232
232
|
return;
|
|
233
|
-
this.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
if (!this._options.codersInClass) {
|
|
234
|
+
this.emitLine("// To parse this JSON data, do");
|
|
235
|
+
this.emitLine("//");
|
|
236
|
+
this.forEachTopLevel("none", (_t, name) => {
|
|
237
|
+
const { decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
|
|
238
|
+
this.emitLine("// final ", (0, Source_1.modifySource)(Strings_1.decapitalize, name), " = ", decoder, "(jsonString);");
|
|
239
|
+
});
|
|
240
|
+
}
|
|
239
241
|
this.ensureBlankLine();
|
|
240
242
|
if (this._options.requiredProperties) {
|
|
241
243
|
this.emitLine("import 'package:meta/meta.dart';");
|
|
@@ -246,7 +248,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
246
248
|
if (this._options.useHive) {
|
|
247
249
|
this.emitLine("import 'package:hive/hive.dart';");
|
|
248
250
|
}
|
|
249
|
-
if (this._options.useJsonAnnotation) {
|
|
251
|
+
if (this._options.useJsonAnnotation && !this._options.useFreezed) {
|
|
252
|
+
// The freezed annotatation import already provides the import for json_annotation
|
|
250
253
|
this.emitLine("import 'package:json_annotation/json_annotation.dart';");
|
|
251
254
|
}
|
|
252
255
|
this.emitLine("import 'dart:convert';");
|
|
@@ -416,7 +419,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
416
419
|
this.emitLine(className, "({");
|
|
417
420
|
this.indent(() => {
|
|
418
421
|
this.forEachClassProperty(c, "none", (name, _, prop) => {
|
|
419
|
-
const required = this._options.requiredProperties ||
|
|
422
|
+
const required = this._options.requiredProperties ||
|
|
423
|
+
(this._options.nullSafety && (!prop.type.isNullable || !prop.isOptional));
|
|
420
424
|
this.emitLine(required ? "required " : "", "this.", name, ",");
|
|
421
425
|
});
|
|
422
426
|
});
|
|
@@ -435,7 +439,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
435
439
|
}
|
|
436
440
|
if (this._options.useJsonAnnotation) {
|
|
437
441
|
this.classPropertyCounter++;
|
|
438
|
-
this.emitLine(`@JsonKey(name:"${jsonName}")`);
|
|
442
|
+
this.emitLine(`@JsonKey(name: "${jsonName}")`);
|
|
439
443
|
}
|
|
440
444
|
this.emitLine(this._options.finalProperties ? "final " : "", this.dartType(p.type, true), " ", name, ";");
|
|
441
445
|
});
|
|
@@ -535,8 +539,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
535
539
|
else {
|
|
536
540
|
this.emitLine("const factory ", className, "({");
|
|
537
541
|
this.indent(() => {
|
|
538
|
-
this.forEachClassProperty(c, "none", (name,
|
|
539
|
-
|
|
542
|
+
this.forEachClassProperty(c, "none", (name, jsonName, prop) => {
|
|
543
|
+
const required = this._options.requiredProperties ||
|
|
544
|
+
(this._options.nullSafety && (!prop.type.isNullable || !prop.isOptional));
|
|
545
|
+
if (this._options.useJsonAnnotation) {
|
|
546
|
+
this.classPropertyCounter++;
|
|
547
|
+
this.emitLine(`@JsonKey(name: "${jsonName}")`);
|
|
548
|
+
}
|
|
549
|
+
this.emitLine(required ? "required " : "", this.dartType(prop.type, true), " ", name, ",");
|
|
540
550
|
});
|
|
541
551
|
});
|
|
542
552
|
this.emitLine("}) = _", className, ";");
|