Test case
1 generated file · +135 −0test/inputs/dart/dart-runtime-type-names.schema
Aschema-dartdefault / TopLevel.dart+135 −0
| @@ -0,0 +1,135 @@ | ||
| 1 | +// To parse this JSON data, do | |
| 2 | +// | |
| 3 | +// final topLevel = topLevelFromJson(jsonString); | |
| 4 | + | |
| 5 | +import 'dart:convert'; | |
| 6 | + | |
| 7 | +TopLevel topLevelFromJson(String str) => TopLevel.fromJson(json.decode(str)); | |
| 8 | + | |
| 9 | +String topLevelToJson(TopLevel data) => json.encode(data.toJson()); | |
| 10 | + | |
| 11 | +class TopLevel { | |
| 12 | + final String code; | |
| 13 | + final DateTimeClass dateTime; | |
| 14 | + final EnumValuesClass enumValues; | |
| 15 | + final FormatExceptionClass formatException; | |
| 16 | + final RegExpClass regExp; | |
| 17 | + final Status status; | |
| 18 | + final DateTime timestamp; | |
| 19 | + | |
| 20 | + TopLevel({ | |
| 21 | + required this.code, | |
| 22 | + required this.dateTime, | |
| 23 | + required this.enumValues, | |
| 24 | + required this.formatException, | |
| 25 | + required this.regExp, | |
| 26 | + required this.status, | |
| 27 | + required this.timestamp, | |
| 28 | + }); | |
| 29 | + | |
| 30 | + factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel( | |
| 31 | + code: ((x) => RegExp("^[a-z]+\u0024").hasMatch(x) ? x : throw FormatException("Expected matching string"))(((x) => x.length >= 1 && true ? x : throw FormatException("Expected bounded string"))(json["code"])), | |
| 32 | + dateTime: DateTimeClass.fromJson(json["dateTime"]), | |
| 33 | + enumValues: EnumValuesClass.fromJson(json["enumValues"]), | |
| 34 | + formatException: FormatExceptionClass.fromJson(json["formatException"]), | |
| 35 | + regExp: RegExpClass.fromJson(json["regExp"]), | |
| 36 | + status: statusValues.map[json["status"]]!, | |
| 37 | + timestamp: DateTime.parse(json["timestamp"]), | |
| 38 | + ); | |
| 39 | + | |
| 40 | + Map<String, dynamic> toJson() => { | |
| 41 | + "code": code, | |
| 42 | + "dateTime": dateTime.toJson(), | |
| 43 | + "enumValues": enumValues.toJson(), | |
| 44 | + "formatException": formatException.toJson(), | |
| 45 | + "regExp": regExp.toJson(), | |
| 46 | + "status": statusValues.reverse[status], | |
| 47 | + "timestamp": timestamp.toIso8601String(), | |
| 48 | + }; | |
| 49 | +} | |
| 50 | + | |
| 51 | +class DateTimeClass { | |
| 52 | + final int value; | |
| 53 | + | |
| 54 | + DateTimeClass({ | |
| 55 | + required this.value, | |
| 56 | + }); | |
| 57 | + | |
| 58 | + factory DateTimeClass.fromJson(Map<String, dynamic> json) => DateTimeClass( | |
| 59 | + value: json["value"], | |
| 60 | + ); | |
| 61 | + | |
| 62 | + Map<String, dynamic> toJson() => { | |
| 63 | + "value": value, | |
| 64 | + }; | |
| 65 | +} | |
| 66 | + | |
| 67 | +class EnumValuesClass { | |
| 68 | + final String label; | |
| 69 | + | |
| 70 | + EnumValuesClass({ | |
| 71 | + required this.label, | |
| 72 | + }); | |
| 73 | + | |
| 74 | + factory EnumValuesClass.fromJson(Map<String, dynamic> json) => EnumValuesClass( | |
| 75 | + label: json["label"], | |
| 76 | + ); | |
| 77 | + | |
| 78 | + Map<String, dynamic> toJson() => { | |
| 79 | + "label": label, | |
| 80 | + }; | |
| 81 | +} | |
| 82 | + | |
| 83 | +class FormatExceptionClass { | |
| 84 | + final int count; | |
| 85 | + | |
| 86 | + FormatExceptionClass({ | |
| 87 | + required this.count, | |
| 88 | + }); | |
| 89 | + | |
| 90 | + factory FormatExceptionClass.fromJson(Map<String, dynamic> json) => FormatExceptionClass( | |
| 91 | + count: json["count"], | |
| 92 | + ); | |
| 93 | + | |
| 94 | + Map<String, dynamic> toJson() => { | |
| 95 | + "count": count, | |
| 96 | + }; | |
| 97 | +} | |
| 98 | + | |
| 99 | +class RegExpClass { | |
| 100 | + final bool active; | |
| 101 | + | |
| 102 | + RegExpClass({ | |
| 103 | + required this.active, | |
| 104 | + }); | |
| 105 | + | |
| 106 | + factory RegExpClass.fromJson(Map<String, dynamic> json) => RegExpClass( | |
| 107 | + active: json["active"], | |
| 108 | + ); | |
| 109 | + | |
| 110 | + Map<String, dynamic> toJson() => { | |
| 111 | + "active": active, | |
| 112 | + }; | |
| 113 | +} | |
| 114 | + | |
| 115 | +enum Status { | |
| 116 | + READY, | |
| 117 | + DONE | |
| 118 | +} | |
| 119 | + | |
| 120 | +final statusValues = EnumValues({ | |
| 121 | + "ready": Status.READY, | |
| 122 | + "done": Status.DONE | |
| 123 | +}); | |
| 124 | + | |
| 125 | +class EnumValues<T> { | |
| 126 | + Map<String, T> map; | |
| 127 | + late Map<T, String> reverseMap; | |
| 128 | + | |
| 129 | + EnumValues(this.map); | |
| 130 | + | |
| 131 | + Map<T, String> get reverse { | |
| 132 | + reverseMap = map.map((k, v) => MapEntry(v, k)); | |
| 133 | + return reverseMap; | |
| 134 | + } | |
| 135 | +} |
Test case
1 generated file · +3 −3test/inputs/schema/vega-lite.schema
Mschema-dartdefault / TopLevel.dart+3 −3
| @@ -4840,7 +4840,7 @@ class Predicate { | ||
| 4840 | 4840 | ///If both month and quarter are provided, month has higher precedence. |
| 4841 | 4841 | ///`day` cannot be combined with other date. |
| 4842 | 4842 | ///We accept string for month and day names. |
| 4843 | -class DateTime { | |
| 4843 | +class DateTimeClass { | |
| 4844 | 4844 | |
| 4845 | 4845 | ///Integer value representing the date from 1-31. |
| 4846 | 4846 | final double? date; |
| @@ -4879,7 +4879,7 @@ class DateTime { | ||
| 4879 | 4879 | ///Integer value representing the year. |
| 4880 | 4880 | final double? year; |
| 4881 | 4881 | |
| 4882 | - DateTime({ | |
| 4882 | + DateTimeClass({ | |
| 4883 | 4883 | this.date, |
| 4884 | 4884 | this.day, |
| 4885 | 4885 | this.hours, |
| @@ -4892,7 +4892,7 @@ class DateTime { | ||
| 4892 | 4892 | this.year, |
| 4893 | 4893 | }); |
| 4894 | 4894 | |
| 4895 | - factory DateTime.fromJson(Map<String, dynamic> json) => DateTime( | |
| 4895 | + factory DateTimeClass.fromJson(Map<String, dynamic> json) => DateTimeClass( | |
| 4896 | 4896 | date: json["date"]?.toDouble() == null ? null : ((x) => x >= 1 && x <= 31 ? x : throw FormatException("Expected bounded number"))(json["date"]?.toDouble()), |
| 4897 | 4897 | day: json["day"], |
| 4898 | 4898 | hours: json["hours"]?.toDouble() == null ? null : ((x) => x >= 0 && x <= 23 ? x : throw FormatException("Expected bounded number"))(json["hours"]?.toDouble()), |
No generated files match these filters.