quicktype-core 23.3.11 → 23.3.13

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.
@@ -780,8 +780,10 @@ function addTypesInSchema(resolver, typeBuilder, references, attributeProducers)
780
780
  const includeArray = enumArray === undefined &&
781
781
  !isConst &&
782
782
  (typeSet === undefined || typeSet.has("array"));
783
+ const enumArrayHasString = (enumArray === null || enumArray === void 0 ? void 0 : enumArray.find((x) => typeof x === "string")) !== undefined;
784
+ const constIsString = isConst && typeof schema.const === "string";
783
785
  const needStringEnum = includedTypes.has("string") &&
784
- (enumArray === null || enumArray === void 0 ? void 0 : enumArray.find((x) => typeof x === "string")) !== undefined;
786
+ (enumArrayHasString || constIsString);
785
787
  const needUnion = typeSet !== undefined ||
786
788
  schema.properties !== undefined ||
787
789
  schema.additionalProperties !== undefined ||
@@ -807,8 +809,13 @@ function addTypesInSchema(resolver, typeBuilder, references, attributeProducers)
807
809
  unionTypes.push(typeBuilder.getPrimitiveType(kind, attributes));
808
810
  }
809
811
  const stringAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", inferredAttributes, combineProducedAttributes(({ forString }) => forString));
810
- if (needStringEnum || isConst) {
811
- const cases = isConst
812
+ // FIXME: A non-string const never takes this path, so it
813
+ // degrades to its plain primitive type and the literal value is
814
+ // dropped, because enum case name generation only works with
815
+ // strings. To fix this, the cases below have to support all
816
+ // types.
817
+ if (needStringEnum) {
818
+ const cases = constIsString
812
819
  ? [schema.const]
813
820
  : ((_a = enumArray === null || enumArray === void 0 ? void 0 : enumArray.filter((x) => typeof x === "string")) !== null && _a !== void 0 ? _a : []);
814
821
  unionTypes.push(typeBuilder.getStringType(stringAttributes, StringTypes_1.StringTypes.fromCases(cases)));
@@ -1258,7 +1258,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1258
1258
  onFirst = false;
1259
1259
  });
1260
1260
  }
1261
- this.emitLine('else { throw std::runtime_error("Input JSON does not conform to schema!"); }');
1261
+ this.emitLine('else { throw std::runtime_error("Cannot deserialize to enumeration \\"', enumName, '\\""); }');
1262
1262
  });
1263
1263
  this.ensureBlankLine();
1264
1264
  this.emitBlock([
@@ -251,7 +251,10 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
251
251
  (0, Support_1.defined)(this._enumValues.get(enumType)),
252
252
  ".map[",
253
253
  dynamic,
254
- this._options.nullSafety ? "]!" : "]",
254
+ this._options.nullSafety &&
255
+ (!isNullable || this._options.requiredProperties)
256
+ ? "]!"
257
+ : "]",
255
258
  ];
256
259
  }, (unionType) => {
257
260
  const maybeNullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.11",
3
+ "version": "23.3.13",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",