quicktype-core 23.3.1 → 23.3.3

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.
@@ -767,33 +767,43 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
767
767
  return;
768
768
  const { minMax, minMaxLength, pattern } = constraints;
769
769
  // TODO is there a better way to check if property.type is an integer or a number?
770
+ // We only generate this to classify the underlying type, so we
771
+ // always pass `false` for `isOptional` — otherwise `cppType`
772
+ // wraps the type in the optional<> container and the comparisons
773
+ // below never match.
770
774
  const cppType = this.cppType(property.type, {
771
775
  needsForwardIndirection: true,
772
776
  needsOptionalIndirection: true,
773
777
  inJsonNamespace: false,
774
- }, true, false, property.isOptional);
778
+ }, true, false, false);
779
+ // Compare bounds against `undefined` explicitly, since 0 is a
780
+ // valid constraint value too.
775
781
  res.set(jsonName, [
776
782
  this.constraintMember(jsonName),
777
783
  "(",
778
- (minMax === null || minMax === void 0 ? void 0 : minMax[0]) && cppType === "int64_t"
784
+ (minMax === null || minMax === void 0 ? void 0 : minMax[0]) !== undefined && cppType === "int64_t"
779
785
  ? String(minMax[0])
780
786
  : this._nulloptType,
781
787
  ", ",
782
- (minMax === null || minMax === void 0 ? void 0 : minMax[1]) && cppType === "int64_t"
788
+ (minMax === null || minMax === void 0 ? void 0 : minMax[1]) !== undefined && cppType === "int64_t"
783
789
  ? String(minMax[1])
784
790
  : this._nulloptType,
785
791
  ", ",
786
- (minMax === null || minMax === void 0 ? void 0 : minMax[0]) && cppType === "double"
792
+ (minMax === null || minMax === void 0 ? void 0 : minMax[0]) !== undefined && cppType === "double"
787
793
  ? String(minMax[0])
788
794
  : this._nulloptType,
789
795
  ", ",
790
- (minMax === null || minMax === void 0 ? void 0 : minMax[1]) && cppType === "double"
796
+ (minMax === null || minMax === void 0 ? void 0 : minMax[1]) !== undefined && cppType === "double"
791
797
  ? String(minMax[1])
792
798
  : this._nulloptType,
793
799
  ", ",
794
- (minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[0]) ? String(minMaxLength[0]) : this._nulloptType,
800
+ (minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[0]) !== undefined
801
+ ? String(minMaxLength[0])
802
+ : this._nulloptType,
795
803
  ", ",
796
- (minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[1]) ? String(minMaxLength[1]) : this._nulloptType,
804
+ (minMaxLength === null || minMaxLength === void 0 ? void 0 : minMaxLength[1]) !== undefined
805
+ ? String(minMaxLength[1])
806
+ : this._nulloptType,
797
807
  ", ",
798
808
  pattern === undefined
799
809
  ? this._nulloptType
@@ -168,9 +168,6 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
168
168
  if (transformedStringType.kind === "date-time") {
169
169
  return "DateTime";
170
170
  }
171
- if (transformedStringType.kind === "uuid") {
172
- throw Error('transformedStringType.kind === "uuid"');
173
- }
174
171
  return "string";
175
172
  });
176
173
  }
@@ -191,6 +188,9 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
191
188
  if (transformedStringType.kind === "date-time") {
192
189
  return "DateTime";
193
190
  }
191
+ if (transformedStringType.kind === "uuid") {
192
+ return "string";
193
+ }
194
194
  throw Error('transformedStringType.kind === "unknown"');
195
195
  });
196
196
  }
@@ -206,6 +206,9 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
206
206
  if (transformedStringType.kind === "date-time") {
207
207
  return "string";
208
208
  }
209
+ if (transformedStringType.kind === "uuid") {
210
+ return "string";
211
+ }
209
212
  throw Error('transformedStringType.kind === "unknown"');
210
213
  });
211
214
  }
@@ -242,6 +245,10 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
242
245
  this.emitLine(...lhs, ...args, "->format(DateTimeInterface::ISO8601);");
243
246
  return;
244
247
  }
248
+ if (transformedStringType.kind === "uuid") {
249
+ this.emitLine(...lhs, ...args, "; /*uuid*/");
250
+ return;
251
+ }
245
252
  throw Error('transformedStringType.kind === "unknown"');
246
253
  });
247
254
  }
@@ -286,6 +293,10 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
286
293
  this.emitLine("return $tmp;");
287
294
  return;
288
295
  }
296
+ if (transformedStringType.kind === "uuid") {
297
+ this.emitLine(...lhs, ...args, "; /*uuid*/");
298
+ return;
299
+ }
289
300
  throw Error('transformedStringType.kind === "unknown"');
290
301
  });
291
302
  }
@@ -317,6 +328,10 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
317
328
  // this.emitLine("return sample();");
318
329
  return;
319
330
  }
331
+ if (transformedStringType.kind === "uuid") {
332
+ this.emitLine(...lhs, "'9277b8fb-2a65-4663-a36c-8d417e2d284b'", suffix, " /*", `${idx}`, ":", args, "*/");
333
+ return;
334
+ }
320
335
  throw Error('transformedStringType.kind === "unknown"');
321
336
  });
322
337
  }
@@ -357,6 +372,15 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
357
372
  ]);
358
373
  return;
359
374
  }
375
+ if (transformedStringType.kind === "uuid") {
376
+ is("is_string");
377
+ this.emitBlock([
378
+ "if (!preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', ",
379
+ scopeAttrName,
380
+ "))",
381
+ ], () => this.emitLine('throw new Exception("Attribute Error:', className, "::", attrName, '");'));
382
+ return;
383
+ }
360
384
  throw Error(`transformedStringType.kind === ${transformedStringType.kind}`);
361
385
  });
362
386
  }
@@ -35,7 +35,7 @@ class PhpTargetLanguage extends TargetLanguage_1.TargetLanguage {
35
35
  const mapping = new Map();
36
36
  mapping.set("date", "date"); // TODO is not implemented yet
37
37
  mapping.set("time", "time"); // TODO is not implemented yet
38
- mapping.set("uuid", "uuid"); // TODO is not implemented yet
38
+ mapping.set("uuid", "uuid");
39
39
  mapping.set("date-time", "date-time");
40
40
  return mapping;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.1",
3
+ "version": "23.3.3",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",