quicktype-core 23.0.2 → 23.0.4

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.
@@ -1280,7 +1280,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1280
1280
  });
1281
1281
  onFirst = false;
1282
1282
  }
1283
- this.emitLine('else throw "Could not deserialize";');
1283
+ // this.emitLine('else throw "Could not deserialize";');
1284
+ this.emitLine('else throw std::runtime_error("Could not deserialise!");');
1284
1285
  });
1285
1286
  this.ensureBlankLine();
1286
1287
  this.emitBlock(["inline void adl_serializer<", variantType, ">::to_json(json & j, ", this.withConst(variantType), " & x)"], false, () => {
@@ -1308,7 +1309,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1308
1309
  });
1309
1310
  i++;
1310
1311
  }
1311
- this.emitLine('default: throw "Input JSON does not conform to schema";');
1312
+ // this.emitLine('default: throw "Input JSON does not conform to schema";');
1313
+ this.emitLine('default: throw std::runtime_error("Input JSON does not conform to schema!");');
1312
1314
  });
1313
1315
  });
1314
1316
  }
@@ -1350,7 +1352,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1350
1352
  this.emitLine(maybeElse, "if (j == ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), ") x = ", ourQualifier, enumName, "::", name, ";");
1351
1353
  onFirst = false;
1352
1354
  });
1353
- this.emitLine('else throw "Input JSON does not conform to schema";');
1355
+ // this.emitLine('else throw "Input JSON does not conform to schema";');
1356
+ this.emitLine('else { throw std::runtime_error("Input JSON does not conform to schema!"); }');
1354
1357
  }
1355
1358
  });
1356
1359
  this.ensureBlankLine();
@@ -1359,7 +1362,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1359
1362
  this.forEachEnumCase(e, "none", (name, jsonName) => {
1360
1363
  this.emitLine("case ", ourQualifier, enumName, "::", name, ": j = ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), "; break;");
1361
1364
  });
1362
- this.emitLine('default: throw "This should not happen";');
1365
+ // this.emitLine('default: throw "This should not happen";');
1366
+ this.emitLine('default: throw std::runtime_error("This should not happen");');
1363
1367
  });
1364
1368
  });
1365
1369
  }
@@ -46,7 +46,7 @@ export declare class PythonRenderer extends ConvenienceRenderer {
46
46
  protected withImport(module: string, name: string): Sourcelike;
47
47
  protected withTyping(name: string): Sourcelike;
48
48
  protected namedType(t: Type): Sourcelike;
49
- protected pythonType(t: Type): Sourcelike;
49
+ protected pythonType(t: Type, _isRootTypeDef?: boolean): Sourcelike;
50
50
  protected declarationLine(t: Type): Sourcelike;
51
51
  protected declareType<T extends Type>(t: T, emitter: () => void): void;
52
52
  protected emitClassMembers(t: ClassType): void;
@@ -240,15 +240,19 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
240
240
  return name;
241
241
  return ["'", name, "'"];
242
242
  }
243
- pythonType(t) {
243
+ pythonType(t, _isRootTypeDef = false) {
244
244
  const actualType = (0, Transformers_1.followTargetType)(t);
245
245
  return (0, TypeUtils_1.matchType)(actualType, _anyType => this.withTyping("Any"), _nullType => "None", _boolType => "bool", _integerType => "int", _doubletype => "float", _stringType => "str", arrayType => [this.withTyping("List"), "[", this.pythonType(arrayType.items), "]"], classType => this.namedType(classType), mapType => [this.withTyping("Dict"), "[str, ", this.pythonType(mapType.values), "]"], enumType => this.namedType(enumType), unionType => {
246
246
  const [hasNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(unionType);
247
247
  const memberTypes = Array.from(nonNulls).map(m => this.pythonType(m));
248
248
  if (hasNull !== null) {
249
249
  let rest = [];
250
- if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses)
250
+ if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses && _isRootTypeDef) {
251
+ // Only push "= None" if this is a root level type def
252
+ // otherwise we may get type defs like List[Optional[int] = None]
253
+ // which are invalid
251
254
  rest.push(" = None");
255
+ }
252
256
  if (nonNulls.size > 1) {
253
257
  this.withImport("typing", "Union");
254
258
  return [
@@ -344,7 +348,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
344
348
  else {
345
349
  this.forEachClassProperty(t, "none", (name, jsonName, cp) => {
346
350
  this.emitDescription(this.descriptionForClassProperty(t, jsonName));
347
- this.emitLine(name, this.typeHint(": ", this.pythonType(cp.type)));
351
+ this.emitLine(name, this.typeHint(": ", this.pythonType(cp.type, true)));
348
352
  });
349
353
  }
350
354
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.2",
3
+ "version": "23.0.4",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",