quicktype-core 23.0.40 → 23.0.42

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.
@@ -16,6 +16,7 @@ export declare const dartOptions: {
16
16
  generateCopyWith: BooleanOption;
17
17
  useFreezed: BooleanOption;
18
18
  useHive: BooleanOption;
19
+ useJsonAnnotation: BooleanOption;
19
20
  partName: StringOption;
20
21
  };
21
22
  export declare class DartTargetLanguage extends TargetLanguage {
@@ -22,6 +22,7 @@ exports.dartOptions = {
22
22
  generateCopyWith: new RendererOptions_1.BooleanOption("copy-with", "Generate CopyWith method", false),
23
23
  useFreezed: new RendererOptions_1.BooleanOption("use-freezed", "Generate class definitions with @freezed compatibility", false, "secondary"),
24
24
  useHive: new RendererOptions_1.BooleanOption("use-hive", "Generate annotations for Hive type adapters", false, "secondary"),
25
+ useJsonAnnotation: new RendererOptions_1.BooleanOption("use-json-annotation", "Generate annotations for json_serializable", false, "secondary"),
25
26
  partName: new RendererOptions_1.StringOption("part-name", "Use this name in `part` directive", "NAME", "", "secondary")
26
27
  };
27
28
  class DartTargetLanguage extends TargetLanguage_1.TargetLanguage {
@@ -39,6 +40,7 @@ class DartTargetLanguage extends TargetLanguage_1.TargetLanguage {
39
40
  exports.dartOptions.generateCopyWith,
40
41
  exports.dartOptions.useFreezed,
41
42
  exports.dartOptions.useHive,
43
+ exports.dartOptions.useJsonAnnotation,
42
44
  exports.dartOptions.partName
43
45
  ];
44
46
  }
@@ -245,8 +247,11 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
245
247
  if (this._options.useHive) {
246
248
  this.emitLine("import 'package:hive/hive.dart';");
247
249
  }
250
+ if (this._options.useJsonAnnotation) {
251
+ this.emitLine("import 'package:json_annotation/json_annotation.dart';");
252
+ }
248
253
  this.emitLine("import 'dart:convert';");
249
- if (this._options.useFreezed || this._options.useHive) {
254
+ if (this._options.useFreezed || this._options.useHive || this._options.useJsonAnnotation) {
250
255
  this.ensureBlankLine();
251
256
  const optionNameIsEmpty = this._options.partName.length === 0;
252
257
  // FIXME: This should use a `Name`, not `modifySource`
@@ -429,6 +434,10 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
429
434
  this.classPropertyCounter++;
430
435
  this.emitLine(`@HiveField(${this.classPropertyCounter})`);
431
436
  }
437
+ if (this._options.useJsonAnnotation) {
438
+ this.classPropertyCounter++;
439
+ this.emitLine(`@JsonKey(name:"${jsonName}")`);
440
+ }
432
441
  this.emitLine(this._options.finalProperties ? "final " : "", this.dartType(p.type, true), " ", name, ";");
433
442
  });
434
443
  }
@@ -482,6 +491,9 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
482
491
  this.emitLine(`@HiveType(typeId: ${this.classCounter})`);
483
492
  this.classPropertyCounter = 0;
484
493
  }
494
+ if (this._options.useJsonAnnotation) {
495
+ this.emitLine(`@JsonSerializable()`);
496
+ }
485
497
  this.emitBlock(["class ", className], () => {
486
498
  if (c.getProperties().size === 0) {
487
499
  this._emitEmptyConstructor(className);
@@ -494,12 +506,24 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
494
506
  if (this._options.generateCopyWith) {
495
507
  this._emitCopyConstructor(c, className);
496
508
  }
497
- if (this._options.justTypes)
498
- return;
499
- if (this._options.codersInClass) {
500
- this._emitStringJsonEncoderDecoder(className);
509
+ if (this._options.useJsonAnnotation) {
510
+ this.ensureBlankLine();
511
+ this.emitLine(
512
+ // factory PublicAnswer.fromJson(Map<String, dynamic> json) => _$PublicAnswerFromJson(json);
513
+ "factory ", className, ".fromJson(Map<String, dynamic> json) => ", "_$", className, "FromJson(json);");
514
+ this.ensureBlankLine();
515
+ this.emitLine(
516
+ // Map<String, dynamic> toJson() => _$PublicAnswerToJson(this);
517
+ "Map<String, dynamic> toJson() => ", "_$", className, "ToJson(this);");
518
+ }
519
+ else {
520
+ if (this._options.justTypes)
521
+ return;
522
+ if (this._options.codersInClass) {
523
+ this._emitStringJsonEncoderDecoder(className);
524
+ }
525
+ this._emitMapEncoderDecoder(c, className);
501
526
  }
502
- this._emitMapEncoderDecoder(c, className);
503
527
  });
504
528
  }
505
529
  emitFreezedClassDefinition(c, className) {
@@ -668,6 +668,9 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
668
668
  if (!this._options.justTypes && this._options.alamofire) {
669
669
  this.emitLineOnce("import Alamofire");
670
670
  }
671
+ if (this._options.optionalEnums) {
672
+ this.emitLineOnce("import OptionallyDecodable // https://github.com/idrougge/OptionallyDecodable");
673
+ }
671
674
  this.ensureBlankLine();
672
675
  }
673
676
  renderTopLevelAlias(t, name) {
@@ -785,7 +788,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
785
788
  let sources = [
786
789
  [
787
790
  this._options.optionalEnums && lastProperty.type.kind === "enum"
788
- ? `@NilOnFail${this._options.namedTypePrefix} `
791
+ ? `@OptionallyDecodable `
789
792
  : "",
790
793
  this.accessLevel,
791
794
  useMutableProperties || (this._options.optionalEnums && lastProperty.type.kind === "enum")
@@ -1155,18 +1158,6 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
1155
1158
  if (!this._options.justTypes) {
1156
1159
  this.emitSupportFunctions4();
1157
1160
  }
1158
- if (this._options.optionalEnums) {
1159
- this.emitBlockWithAccess(`@propertyWrapper public struct NilOnFail${this._options.namedTypePrefix}<T: Codable>: Codable`, () => {
1160
- this.emitMultiline(`
1161
- public let wrappedValue: T?
1162
- public init(from decoder: Decoder) throws {
1163
- wrappedValue = try? T(from: decoder)
1164
- }
1165
- public init(_ wrappedValue: T?) {
1166
- self.wrappedValue = wrappedValue
1167
- }`);
1168
- });
1169
- }
1170
1161
  }
1171
1162
  emitAlamofireExtension() {
1172
1163
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.40",
3
+ "version": "23.0.42",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",