quicktype-core 23.0.67 → 23.0.69

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.
@@ -32,6 +32,8 @@ export declare const cJSONOptions: {
32
32
  typeSourceStyle: EnumOption<boolean>;
33
33
  typeIntegerSize: EnumOption<string>;
34
34
  hashtableSize: StringOption;
35
+ addTypedefAlias: EnumOption<boolean>;
36
+ printStyle: EnumOption<boolean>;
35
37
  typeNamingStyle: EnumOption<NamingStyle>;
36
38
  memberNamingStyle: EnumOption<NamingStyle>;
37
39
  enumeratorNamingStyle: EnumOption<NamingStyle>;
@@ -173,6 +175,12 @@ export declare class CJSONRenderer extends ConvenienceRenderer {
173
175
  * @return Proposed union member name
174
176
  */
175
177
  protected proposeUnionMemberName(unionType: UnionType, unionName: Name, fieldType: Type, lookup: (n: Name) => string): string;
178
+ /**
179
+ * Function called to emit typedef alias for a a given type
180
+ * @param fieldType: the variable type
181
+ * @param fieldName: name of the variable
182
+ */
183
+ protected emitTypdefAlias(fieldType: Type, fieldName: Name): void;
176
184
  /**
177
185
  * Function called to create header file(s)
178
186
  * @param proposedFilename: source filename provided from stdin
@@ -47,6 +47,8 @@ exports.cJSONOptions = {
47
47
  typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [["single-source", true], ["multi-source", false]], "single-source", "secondary"),
48
48
  typeIntegerSize: new RendererOptions_1.EnumOption("integer-size", "Integer code generation type (int64_t by default)", [["int8_t", "int8_t"], ["int16_t", "int16_t"], ["int32_t", "int32_t"], ["int64_t", "int64_t"]], "int64_t", "secondary"),
49
49
  hashtableSize: new RendererOptions_1.StringOption("hashtable-size", "Hashtable size, used when maps are created (64 by default)", "SIZE", "64"),
50
+ addTypedefAlias: new RendererOptions_1.EnumOption("typedef-alias", "Add typedef alias to unions, structs, and enums (no typedef by default)", [["no-typedef", false], ["add-typedef", true]], "no-typedef", "secondary"),
51
+ printStyle: new RendererOptions_1.EnumOption("print-style", "Which cJSON print should be used (formatted by default)", [["print-formatted", false], ["print-unformatted", true]], "print-formatted", "secondary"),
50
52
  typeNamingStyle: new RendererOptions_1.EnumOption("type-style", "Naming style for types", [pascalValue, underscoreValue, camelValue, upperUnderscoreValue, pascalUpperAcronymsValue, camelUpperAcronymsValue]),
51
53
  memberNamingStyle: new RendererOptions_1.EnumOption("member-style", "Naming style for members", [underscoreValue, pascalValue, camelValue, upperUnderscoreValue, pascalUpperAcronymsValue, camelUpperAcronymsValue]),
52
54
  enumeratorNamingStyle: new RendererOptions_1.EnumOption("enumerator-style", "Naming style for enumerators", [upperUnderscoreValue, underscoreValue, pascalValue, camelValue, pascalUpperAcronymsValue, camelUpperAcronymsValue])
@@ -70,6 +72,8 @@ class CJSONTargetLanguage extends TargetLanguage_1.TargetLanguage {
70
72
  return [
71
73
  exports.cJSONOptions.typeSourceStyle,
72
74
  exports.cJSONOptions.typeIntegerSize,
75
+ exports.cJSONOptions.addTypedefAlias,
76
+ exports.cJSONOptions.printStyle,
73
77
  exports.cJSONOptions.hashtableSize,
74
78
  exports.cJSONOptions.typeNamingStyle,
75
79
  exports.cJSONOptions.memberNamingStyle,
@@ -340,6 +344,17 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
340
344
  }
341
345
  return fieldName;
342
346
  }
347
+ /**
348
+ * Function called to emit typedef alias for a a given type
349
+ * @param fieldType: the variable type
350
+ * @param fieldName: name of the variable
351
+ */
352
+ emitTypdefAlias(fieldType, fieldName) {
353
+ if (this._options.addTypedefAlias) {
354
+ this.emitLine("typedef ", this.quicktypeTypeToCJSON(fieldType, false).cType, " ", fieldName, ";");
355
+ this.ensureBlankLine();
356
+ }
357
+ }
343
358
  /**
344
359
  * Function called to create header file(s)
345
360
  * @param proposedFilename: source filename provided from stdin
@@ -471,6 +486,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
471
486
  });
472
487
  }, "", true);
473
488
  this.ensureBlankLine();
489
+ this.emitTypdefAlias(enumType, enumName);
474
490
  }
475
491
  /**
476
492
  * Function called to create enum prototypes
@@ -555,6 +571,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
555
571
  }, "value", true);
556
572
  }, "", true);
557
573
  this.ensureBlankLine();
574
+ this.emitTypdefAlias(unionType, unionName);
558
575
  }
559
576
  /**
560
577
  * Function called to create union prototypes
@@ -945,6 +962,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
945
962
  });
946
963
  }, "", true);
947
964
  this.ensureBlankLine();
965
+ this.emitTypdefAlias(classType, className);
948
966
  }
949
967
  /**
950
968
  * Function called to create class prototypes
@@ -1403,7 +1421,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1403
1421
  this.emitBlock(["if (NULL != x)"], () => {
1404
1422
  this.emitLine("cJSON * j = cJSON_Create", className, "(x);");
1405
1423
  this.emitBlock(["if (NULL != j)"], () => {
1406
- this.emitLine("s = cJSON_Print(j);");
1424
+ this.emitLine(this._options.printStyle ? "s = cJSON_PrintUnformatted(j);" : "s = cJSON_Print(j);");
1407
1425
  this.emitLine("cJSON_Delete(j);");
1408
1426
  });
1409
1427
  });
@@ -1573,6 +1591,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1573
1591
  this.emitLine(cJSON.cType, (cJSON.optionalQualifier !== "") ? " " : "", cJSON.optionalQualifier, " value;");
1574
1592
  }, "", true);
1575
1593
  this.ensureBlankLine();
1594
+ this.emitTypdefAlias(type, className);
1576
1595
  }
1577
1596
  /**
1578
1597
  * Function called to create top level prototypes
@@ -335,7 +335,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
335
335
  sortClassProperties(properties, propertyNames) {
336
336
  if (this.pyOptions.features.dataClasses) {
337
337
  return (0, collection_utils_1.mapSortBy)(properties, (p) => {
338
- return p.type instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(p.type) != null ? 1 : 0;
338
+ return ((p.type instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(p.type) != null) || p.isOptional) ? 1 : 0;
339
339
  });
340
340
  }
341
341
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.67",
3
+ "version": "23.0.69",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",