quicktype-core 23.0.62 → 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.
@@ -11,7 +11,6 @@ const TargetLanguage_1 = require("../TargetLanguage");
11
11
  const RendererOptions_1 = require("../RendererOptions");
12
12
  const Annotation_1 = require("../Annotation");
13
13
  const Support_1 = require("../support/Support");
14
- const collection_utils_1 = require("collection-utils");
15
14
  exports.dartOptions = {
16
15
  nullSafety: new RendererOptions_1.BooleanOption("null-safety", "Null Safety", true),
17
16
  justTypes: new RendererOptions_1.BooleanOption("just-types", "Types only", false),
@@ -231,12 +230,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
231
230
  }
232
231
  if (this._options.justTypes)
233
232
  return;
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
- });
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
+ }
240
241
  this.ensureBlankLine();
241
242
  if (this._options.requiredProperties) {
242
243
  this.emitLine("import 'package:meta/meta.dart';");
@@ -247,7 +248,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
247
248
  if (this._options.useHive) {
248
249
  this.emitLine("import 'package:hive/hive.dart';");
249
250
  }
250
- if (this._options.useJsonAnnotation) {
251
+ if (this._options.useJsonAnnotation && !this._options.useFreezed) {
252
+ // The freezed annotatation import already provides the import for json_annotation
251
253
  this.emitLine("import 'package:json_annotation/json_annotation.dart';");
252
254
  }
253
255
  this.emitLine("import 'dart:convert';");
@@ -417,7 +419,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
417
419
  this.emitLine(className, "({");
418
420
  this.indent(() => {
419
421
  this.forEachClassProperty(c, "none", (name, _, prop) => {
420
- const required = this._options.requiredProperties || (this._options.nullSafety && !prop.type.isNullable);
422
+ const required = this._options.requiredProperties ||
423
+ (this._options.nullSafety && (!prop.type.isNullable || !prop.isOptional));
421
424
  this.emitLine(required ? "required " : "", "this.", name, ",");
422
425
  });
423
426
  });
@@ -436,7 +439,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
436
439
  }
437
440
  if (this._options.useJsonAnnotation) {
438
441
  this.classPropertyCounter++;
439
- this.emitLine(`@JsonKey(name:"${jsonName}")`);
442
+ this.emitLine(`@JsonKey(name: "${jsonName}")`);
440
443
  }
441
444
  this.emitLine(this._options.finalProperties ? "final " : "", this.dartType(p.type, true), " ", name, ";");
442
445
  });
@@ -536,8 +539,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
536
539
  else {
537
540
  this.emitLine("const factory ", className, "({");
538
541
  this.indent(() => {
539
- this.forEachClassProperty(c, "none", (name, _, _p) => {
540
- this.emitLine(this._options.requiredProperties ? "required " : "", this.dartType(_p.type, true), this._options.requiredProperties ? "" : "?", " ", name, ",");
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, ",");
541
550
  });
542
551
  });
543
552
  this.emitLine("}) = _", className, ";");
@@ -551,9 +560,18 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
551
560
  });
552
561
  }
553
562
  emitEnumDefinition(e, enumName) {
554
- const caseNames = Array.from(e.cases).map(c => this.nameForEnumCase(e, c));
555
563
  this.emitDescription(this.descriptionForType(e));
556
- this.emitLine("enum ", enumName, " { ", (0, collection_utils_1.arrayIntercalate)(", ", caseNames), " }");
564
+ this.emitLine("enum ", enumName, " {");
565
+ this.indent(() => {
566
+ this.forEachEnumCase(e, "none", (name, jsonName, pos) => {
567
+ const comma = pos === "first" || pos === "middle" ? "," : [];
568
+ if (this._options.useJsonAnnotation) {
569
+ this.emitLine('@JsonValue("', stringEscape(jsonName), '")');
570
+ }
571
+ this.emitLine(name, comma);
572
+ });
573
+ });
574
+ this.emitLine("}");
557
575
  if (this._options.justTypes)
558
576
  return;
559
577
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.62",
3
+ "version": "23.0.64",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",