quicktype-core 6.1.7 → 6.1.8

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.
@@ -20,6 +20,7 @@ export declare const swiftOptions: {
20
20
  dense: EnumOption<boolean>;
21
21
  linux: BooleanOption;
22
22
  objcSupport: BooleanOption;
23
+ optionalEnums: BooleanOption;
23
24
  swift5Support: BooleanOption;
24
25
  multiFileOutput: BooleanOption;
25
26
  accessLevel: EnumOption<string>;
@@ -33,6 +33,7 @@ exports.swiftOptions = {
33
33
  ], "dense", "secondary"),
34
34
  linux: new RendererOptions_1.BooleanOption("support-linux", "Support Linux", false, "secondary"),
35
35
  objcSupport: new RendererOptions_1.BooleanOption("objective-c-support", "Objects inherit from NSObject and @objcMembers is added to classes", false),
36
+ optionalEnums: new RendererOptions_1.BooleanOption("optional-enums", "If no matching case is found enum value is set to null", false),
36
37
  swift5Support: new RendererOptions_1.BooleanOption("swift-5-support", "Renders output in a Swift 5 compatible mode", false),
37
38
  multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Swift file", false),
38
39
  accessLevel: new RendererOptions_1.EnumOption("access-level", "Access level", [
@@ -79,6 +80,7 @@ class SwiftTargetLanguage extends TargetLanguage_1.TargetLanguage {
79
80
  exports.swiftOptions.protocol,
80
81
  exports.swiftOptions.acronymStyle,
81
82
  exports.swiftOptions.objcSupport,
83
+ exports.swiftOptions.optionalEnums,
82
84
  exports.swiftOptions.swift5Support,
83
85
  exports.swiftOptions.multiFileOutput,
84
86
  exports.swiftOptions.mutableProperties
@@ -574,7 +576,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
574
576
  return Naming_1.funPrefixNamer("lower", s => swiftNameStyle("", false, s, Acronyms_1.acronymStyle(this._options.acronymStyle)));
575
577
  }
576
578
  swiftPropertyType(p) {
577
- if (p.isOptional) {
579
+ if (p.isOptional || (this._options.optionalEnums && p.type.kind === "enum")) {
578
580
  return [this.swiftType(p.type, true, true), "?"];
579
581
  }
580
582
  else {
@@ -771,7 +773,17 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
771
773
  if (lastProperty === undefined)
772
774
  return;
773
775
  const useMutableProperties = this._options.mutableProperties;
774
- let sources = [[this.accessLevel, useMutableProperties ? "var " : "let "]];
776
+ let sources = [
777
+ [
778
+ this._options.optionalEnums && lastProperty.type.kind === "enum"
779
+ ? `@NilOnFail${this._options.namedTypePrefix} `
780
+ : "",
781
+ this.accessLevel,
782
+ useMutableProperties || (this._options.optionalEnums && lastProperty.type.kind === "enum")
783
+ ? "var "
784
+ : "let "
785
+ ]
786
+ ];
775
787
  lastNames.forEach((n, i) => {
776
788
  if (i > 0)
777
789
  sources.push(", ");
@@ -1145,6 +1157,18 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
1145
1157
  if (!this._options.justTypes) {
1146
1158
  this.emitSupportFunctions4();
1147
1159
  }
1160
+ if (this._options.optionalEnums) {
1161
+ this.emitBlockWithAccess(`@propertyWrapper public struct NilOnFail${this._options.namedTypePrefix}<T: Codable>: Codable`, () => {
1162
+ this.emitMultiline(`
1163
+ public let wrappedValue: T?
1164
+ public init(from decoder: Decoder) throws {
1165
+ wrappedValue = try? T(from: decoder)
1166
+ }
1167
+ public init(_ wrappedValue: T?) {
1168
+ self.wrappedValue = wrappedValue
1169
+ }`);
1170
+ });
1171
+ }
1148
1172
  }
1149
1173
  emitAlamofireExtension() {
1150
1174
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "6.1.7",
3
+ "version": "6.1.8",
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": "99e0554e3a23b5e56dd56676b89a7e96fcfc2013"
48
+ "commit": "4523ba79ed0103e4d456538e6651451422c30977"
49
49
  }
50
50
  }