Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
6test cases
59files differ
59modified
0new
0deleted
672changed lines
+560 −112insertions / deletions
Base 10cdaef273530caef2fdf9afdc07cdd0d1f9cae7 · PR merge e55c34d8df0f4b31e50142e57924e1beedf526c9 · Head d16f13f75fc54b6cee82012969b913ad8d6cac40 · raw patch
Test case

test/inputs/schema/minmaxlength.schema

27 generated files · +394 −84
Mschema-cplusplusdefault / quicktype.hpp+12 −3
@@ -224,16 +224,19 @@ namespace quicktype {
224224 class TopLevel {
225225 public:
226226 TopLevel() :
227- intersection_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 4, 5, std::nullopt),
227+ empty_only_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, 0, std::nullopt),
228+ intersection_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 4, 5, std::string("^[a-z]+$")),
228229 maxlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, 5, std::nullopt),
229230 minlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, std::nullopt, std::nullopt),
230231 min_max_intersection_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, 5, std::nullopt),
231- minmaxlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, 5, std::nullopt),
232- union_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, 6, std::nullopt)
232+ minmaxlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, 5, std::string("^[a-z]+$")),
233+ union_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, 6, std::string("^[a-z]+$"))
233234 {}
234235 virtual ~TopLevel() = default;
235236
236237 private:
238+ std::string empty_only;
239+ ClassMemberConstraints empty_only_constraint;
237240 std::string intersection;
238241 ClassMemberConstraints intersection_constraint;
239242 InUnion in_union;
@@ -250,6 +253,10 @@ namespace quicktype {
250253 ClassMemberConstraints union_constraint;
251254
252255 public:
256+ const std::string & get_empty_only() const { return empty_only; }
257+ std::string & get_mutable_empty_only() { return empty_only; }
258+ void set_empty_only(const std::string & value) { CheckConstraint("empty_only", empty_only_constraint, value); this->empty_only = value; }
259+
253260 const std::string & get_intersection() const { return intersection; }
254261 std::string & get_mutable_intersection() { return intersection; }
255262 void set_intersection(const std::string & value) { CheckConstraint("intersection", intersection_constraint, value); this->intersection = value; }
@@ -297,6 +304,7 @@ struct adl_serializer<std::variant<double, std::string>> {
297304 }
298305 namespace quicktype {
299306 inline void from_json(const json & j, TopLevel& x) {
307+ x.set_empty_only(j.at("emptyOnly").get<std::string>());
300308 x.set_intersection(j.at("intersection").get<std::string>());
301309 x.set_in_union(j.at("inUnion").get<InUnion>());
302310 x.set_maxlength(j.at("maxlength").get<std::string>());
@@ -309,6 +317,7 @@ namespace quicktype {
309317
310318 inline void to_json(json & j, const TopLevel & x) {
311319 j = json::object();
320+ j["emptyOnly"] = x.get_empty_only();
312321 j["intersection"] = x.get_intersection();
313322 j["inUnion"] = x.get_in_union();
314323 j["maxlength"] = x.get_maxlength();
Mschema-csharp-recordsdefault / QuickType.cs+76 −16
@@ -25,34 +25,38 @@ namespace QuickType
2525
2626 public partial record TopLevel
2727 {
28+ [JsonProperty("emptyOnly", Required = Required.Always)]
29+ [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
30+ public string EmptyOnly { get; set; }
31+
2832 [JsonProperty("intersection", Required = Required.Always)]
29- [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
33+ [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
3034 public string Intersection { get; set; }
3135
3236 [JsonProperty("inUnion", Required = Required.Always)]
3337 public InUnion InUnion { get; set; }
3438
3539 [JsonProperty("maxlength", Required = Required.Always)]
36- [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
40+ [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
3741 public string Maxlength { get; set; }
3842
3943 [JsonProperty("minlength", Required = Required.Always)]
40- [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
44+ [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))]
4145 public string Minlength { get; set; }
4246
4347 [JsonProperty("minMaxIntersection", Required = Required.Always)]
44- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
48+ [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
4549 public string MinMaxIntersection { get; set; }
4650
4751 [JsonProperty("minmaxlength", Required = Required.Always)]
48- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
52+ [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
4953 public string Minmaxlength { get; set; }
5054
5155 [JsonProperty("minMaxUnion", Required = Required.Always)]
5256 public string MinMaxUnion { get; set; }
5357
5458 [JsonProperty("union", Required = Required.Always)]
55- [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
59+ [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))]
5660 public string Union { get; set; }
5761 }
5862
@@ -89,6 +93,34 @@ namespace QuickType
8993 };
9094 }
9195
96+ internal class PurpleMinMaxLengthCheckConverter : JsonConverter
97+ {
98+ public override bool CanConvert(Type t) => t == typeof(string);
99+
100+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
101+ {
102+ var value = serializer.Deserialize<string>(reader);
103+ if (value.Length <= 0)
104+ {
105+ return value;
106+ }
107+ throw new Exception("Cannot unmarshal type string");
108+ }
109+
110+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
111+ {
112+ var value = (string)untypedValue;
113+ if (value.Length <= 0)
114+ {
115+ serializer.Serialize(writer, value);
116+ return;
117+ }
118+ throw new Exception("Cannot marshal type string");
119+ }
120+
121+ public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
122+ }
123+
92124 internal class InUnionConverter : JsonConverter
93125 {
94126 public override bool CanConvert(Type t) => t == typeof(InUnion) || t == typeof(InUnion?);
@@ -135,7 +167,7 @@ namespace QuickType
135167 public static readonly InUnionConverter Singleton = new InUnionConverter();
136168 }
137169
138- internal class PurpleMinMaxLengthCheckConverter : JsonConverter
170+ internal class FluffyMinMaxLengthCheckConverter : JsonConverter
139171 {
140172 public override bool CanConvert(Type t) => t == typeof(string);
141173
@@ -160,10 +192,10 @@ namespace QuickType
160192 throw new Exception("Cannot marshal type string");
161193 }
162194
163- public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
195+ public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
164196 }
165197
166- internal class FluffyMinMaxLengthCheckConverter : JsonConverter
198+ internal class TentacledMinMaxLengthCheckConverter : JsonConverter
167199 {
168200 public override bool CanConvert(Type t) => t == typeof(string);
169201
@@ -188,10 +220,10 @@ namespace QuickType
188220 throw new Exception("Cannot marshal type string");
189221 }
190222
191- public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
223+ public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
192224 }
193225
194- internal class TentacledMinMaxLengthCheckConverter : JsonConverter
226+ internal class StickyMinMaxLengthCheckConverter : JsonConverter
195227 {
196228 public override bool CanConvert(Type t) => t == typeof(string);
197229
@@ -216,10 +248,38 @@ namespace QuickType
216248 throw new Exception("Cannot marshal type string");
217249 }
218250
219- public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
251+ public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
220252 }
221253
222- internal class StickyMinMaxLengthCheckConverter : JsonConverter
254+ internal class IndigoMinMaxLengthCheckConverter : JsonConverter
255+ {
256+ public override bool CanConvert(Type t) => t == typeof(string);
257+
258+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
259+ {
260+ var value = serializer.Deserialize<string>(reader);
261+ if (value.Length >= 3 && value.Length <= 5)
262+ {
263+ return value;
264+ }
265+ throw new Exception("Cannot unmarshal type string");
266+ }
267+
268+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
269+ {
270+ var value = (string)untypedValue;
271+ if (value.Length >= 3 && value.Length <= 5)
272+ {
273+ serializer.Serialize(writer, value);
274+ return;
275+ }
276+ throw new Exception("Cannot marshal type string");
277+ }
278+
279+ public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
280+ }
281+
282+ internal class IndecentMinMaxLengthCheckConverter : JsonConverter
223283 {
224284 public override bool CanConvert(Type t) => t == typeof(string);
225285
@@ -244,10 +304,10 @@ namespace QuickType
244304 throw new Exception("Cannot marshal type string");
245305 }
246306
247- public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
307+ public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter();
248308 }
249309
250- internal class IndigoMinMaxLengthCheckConverter : JsonConverter
310+ internal class HilariousMinMaxLengthCheckConverter : JsonConverter
251311 {
252312 public override bool CanConvert(Type t) => t == typeof(string);
253313
@@ -272,7 +332,7 @@ namespace QuickType
272332 throw new Exception("Cannot marshal type string");
273333 }
274334
275- public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
335+ public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter();
276336 }
277337 }
278338 #pragma warning restore CS8618
Mschema-csharp-SystemTextJsondefault / QuickType.cs+75 −16
@@ -22,9 +22,14 @@ namespace QuickType
2222
2323 public partial class TopLevel
2424 {
25+ [JsonRequired]
26+ [JsonPropertyName("emptyOnly")]
27+ [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
28+ public string EmptyOnly { get; set; }
29+
2530 [JsonRequired]
2631 [JsonPropertyName("intersection")]
27- [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
32+ [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
2833 public string Intersection { get; set; }
2934
3035 [JsonRequired]
@@ -33,22 +38,22 @@ namespace QuickType
3338
3439 [JsonRequired]
3540 [JsonPropertyName("maxlength")]
36- [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
41+ [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
3742 public string Maxlength { get; set; }
3843
3944 [JsonRequired]
4045 [JsonPropertyName("minlength")]
41- [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
46+ [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))]
4247 public string Minlength { get; set; }
4348
4449 [JsonRequired]
4550 [JsonPropertyName("minMaxIntersection")]
46- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
51+ [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
4752 public string MinMaxIntersection { get; set; }
4853
4954 [JsonRequired]
5055 [JsonPropertyName("minmaxlength")]
51- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
56+ [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
5257 public string Minmaxlength { get; set; }
5358
5459 [JsonRequired]
@@ -57,7 +62,7 @@ namespace QuickType
5762
5863 [JsonRequired]
5964 [JsonPropertyName("union")]
60- [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
65+ [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))]
6166 public string Union { get; set; }
6267 }
6368
@@ -94,6 +99,33 @@ namespace QuickType
9499 };
95100 }
96101
102+ internal class PurpleMinMaxLengthCheckConverter : JsonConverter<string>
103+ {
104+ public override bool CanConvert(Type t) => t == typeof(string);
105+
106+ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
107+ {
108+ var value = reader.GetString();
109+ if (value.Length <= 0)
110+ {
111+ return value;
112+ }
113+ throw new JsonException("Cannot unmarshal type string");
114+ }
115+
116+ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
117+ {
118+ if (value.Length <= 0)
119+ {
120+ JsonSerializer.Serialize(writer, value, options);
121+ return;
122+ }
123+ throw new NotSupportedException("Cannot marshal type string");
124+ }
125+
126+ public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
127+ }
128+
97129 internal class InUnionConverter : JsonConverter<InUnion>
98130 {
99131 public override bool CanConvert(Type t) => t == typeof(InUnion);
@@ -137,7 +169,7 @@ namespace QuickType
137169 public static readonly InUnionConverter Singleton = new InUnionConverter();
138170 }
139171
140- internal class PurpleMinMaxLengthCheckConverter : JsonConverter<string>
172+ internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string>
141173 {
142174 public override bool CanConvert(Type t) => t == typeof(string);
143175
@@ -161,10 +193,10 @@ namespace QuickType
161193 throw new NotSupportedException("Cannot marshal type string");
162194 }
163195
164- public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
196+ public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
165197 }
166198
167- internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string>
199+ internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string>
168200 {
169201 public override bool CanConvert(Type t) => t == typeof(string);
170202
@@ -188,10 +220,10 @@ namespace QuickType
188220 throw new NotSupportedException("Cannot marshal type string");
189221 }
190222
191- public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
223+ public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
192224 }
193225
194- internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string>
226+ internal class StickyMinMaxLengthCheckConverter : JsonConverter<string>
195227 {
196228 public override bool CanConvert(Type t) => t == typeof(string);
197229
@@ -215,10 +247,37 @@ namespace QuickType
215247 throw new NotSupportedException("Cannot marshal type string");
216248 }
217249
218- public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
250+ public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
219251 }
220252
221- internal class StickyMinMaxLengthCheckConverter : JsonConverter<string>
253+ internal class IndigoMinMaxLengthCheckConverter : JsonConverter<string>
254+ {
255+ public override bool CanConvert(Type t) => t == typeof(string);
256+
257+ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
258+ {
259+ var value = reader.GetString();
260+ if (value.Length >= 3 && value.Length <= 5)
261+ {
262+ return value;
263+ }
264+ throw new JsonException("Cannot unmarshal type string");
265+ }
266+
267+ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
268+ {
269+ if (value.Length >= 3 && value.Length <= 5)
270+ {
271+ JsonSerializer.Serialize(writer, value, options);
272+ return;
273+ }
274+ throw new NotSupportedException("Cannot marshal type string");
275+ }
276+
277+ public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
278+ }
279+
280+ internal class IndecentMinMaxLengthCheckConverter : JsonConverter<string>
222281 {
223282 public override bool CanConvert(Type t) => t == typeof(string);
224283
@@ -242,10 +301,10 @@ namespace QuickType
242301 throw new NotSupportedException("Cannot marshal type string");
243302 }
244303
245- public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
304+ public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter();
246305 }
247306
248- internal class IndigoMinMaxLengthCheckConverter : JsonConverter<string>
307+ internal class HilariousMinMaxLengthCheckConverter : JsonConverter<string>
249308 {
250309 public override bool CanConvert(Type t) => t == typeof(string);
251310
@@ -269,7 +328,7 @@ namespace QuickType
269328 throw new NotSupportedException("Cannot marshal type string");
270329 }
271330
272- public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
331+ public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter();
273332 }
274333
275334 public class DateOnlyConverter : JsonConverter<DateOnly>
Mschema-csharpdefault / QuickType.cs+76 −16
@@ -25,34 +25,38 @@ namespace QuickType
2525
2626 public partial class TopLevel
2727 {
28+ [JsonProperty("emptyOnly", Required = Required.Always)]
29+ [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
30+ public string EmptyOnly { get; set; }
31+
2832 [JsonProperty("intersection", Required = Required.Always)]
29- [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
33+ [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
3034 public string Intersection { get; set; }
3135
3236 [JsonProperty("inUnion", Required = Required.Always)]
3337 public InUnion InUnion { get; set; }
3438
3539 [JsonProperty("maxlength", Required = Required.Always)]
36- [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
40+ [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
3741 public string Maxlength { get; set; }
3842
3943 [JsonProperty("minlength", Required = Required.Always)]
40- [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))]
44+ [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))]
4145 public string Minlength { get; set; }
4246
4347 [JsonProperty("minMaxIntersection", Required = Required.Always)]
44- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
48+ [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
4549 public string MinMaxIntersection { get; set; }
4650
4751 [JsonProperty("minmaxlength", Required = Required.Always)]
48- [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
52+ [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
4953 public string Minmaxlength { get; set; }
5054
5155 [JsonProperty("minMaxUnion", Required = Required.Always)]
5256 public string MinMaxUnion { get; set; }
5357
5458 [JsonProperty("union", Required = Required.Always)]
55- [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))]
59+ [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))]
5660 public string Union { get; set; }
5761 }
5862
@@ -89,6 +93,34 @@ namespace QuickType
8993 };
9094 }
9195
96+ internal class PurpleMinMaxLengthCheckConverter : JsonConverter
97+ {
98+ public override bool CanConvert(Type t) => t == typeof(string);
99+
100+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
101+ {
102+ var value = serializer.Deserialize<string>(reader);
103+ if (value.Length <= 0)
104+ {
105+ return value;
106+ }
107+ throw new Exception("Cannot unmarshal type string");
108+ }
109+
110+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
111+ {
112+ var value = (string)untypedValue;
113+ if (value.Length <= 0)
114+ {
115+ serializer.Serialize(writer, value);
116+ return;
117+ }
118+ throw new Exception("Cannot marshal type string");
119+ }
120+
121+ public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
122+ }
123+
92124 internal class InUnionConverter : JsonConverter
93125 {
94126 public override bool CanConvert(Type t) => t == typeof(InUnion) || t == typeof(InUnion?);
@@ -135,7 +167,7 @@ namespace QuickType
135167 public static readonly InUnionConverter Singleton = new InUnionConverter();
136168 }
137169
138- internal class PurpleMinMaxLengthCheckConverter : JsonConverter
170+ internal class FluffyMinMaxLengthCheckConverter : JsonConverter
139171 {
140172 public override bool CanConvert(Type t) => t == typeof(string);
141173
@@ -160,10 +192,10 @@ namespace QuickType
160192 throw new Exception("Cannot marshal type string");
161193 }
162194
163- public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
195+ public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
164196 }
165197
166- internal class FluffyMinMaxLengthCheckConverter : JsonConverter
198+ internal class TentacledMinMaxLengthCheckConverter : JsonConverter
167199 {
168200 public override bool CanConvert(Type t) => t == typeof(string);
169201
@@ -188,10 +220,10 @@ namespace QuickType
188220 throw new Exception("Cannot marshal type string");
189221 }
190222
191- public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
223+ public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
192224 }
193225
194- internal class TentacledMinMaxLengthCheckConverter : JsonConverter
226+ internal class StickyMinMaxLengthCheckConverter : JsonConverter
195227 {
196228 public override bool CanConvert(Type t) => t == typeof(string);
197229
@@ -216,10 +248,38 @@ namespace QuickType
216248 throw new Exception("Cannot marshal type string");
217249 }
218250
219- public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
251+ public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
220252 }
221253
222- internal class StickyMinMaxLengthCheckConverter : JsonConverter
254+ internal class IndigoMinMaxLengthCheckConverter : JsonConverter
255+ {
256+ public override bool CanConvert(Type t) => t == typeof(string);
257+
258+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
259+ {
260+ var value = serializer.Deserialize<string>(reader);
261+ if (value.Length >= 3 && value.Length <= 5)
262+ {
263+ return value;
264+ }
265+ throw new Exception("Cannot unmarshal type string");
266+ }
267+
268+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
269+ {
270+ var value = (string)untypedValue;
271+ if (value.Length >= 3 && value.Length <= 5)
272+ {
273+ serializer.Serialize(writer, value);
274+ return;
275+ }
276+ throw new Exception("Cannot marshal type string");
277+ }
278+
279+ public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
280+ }
281+
282+ internal class IndecentMinMaxLengthCheckConverter : JsonConverter
223283 {
224284 public override bool CanConvert(Type t) => t == typeof(string);
225285
@@ -244,10 +304,10 @@ namespace QuickType
244304 throw new Exception("Cannot marshal type string");
245305 }
246306
247- public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter();
307+ public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter();
248308 }
249309
250- internal class IndigoMinMaxLengthCheckConverter : JsonConverter
310+ internal class HilariousMinMaxLengthCheckConverter : JsonConverter
251311 {
252312 public override bool CanConvert(Type t) => t == typeof(string);
253313
@@ -272,7 +332,7 @@ namespace QuickType
272332 throw new Exception("Cannot marshal type string");
273333 }
274334
275- public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter();
335+ public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter();
276336 }
277337 }
278338 #pragma warning restore CS8618
Mschema-dartdefault / TopLevel.dart+4 −0
@@ -9,6 +9,7 @@ TopLevel topLevelFromJson(String str) => TopLevel.fromJson(json.decode(str));
99 String topLevelToJson(TopLevel data) => json.encode(data.toJson());
1010
1111 class TopLevel {
12+ final String emptyOnly;
1213 final String intersection;
1314 final dynamic inUnion;
1415 final String maxlength;
@@ -19,6 +20,7 @@ class TopLevel {
1920 final String union;
2021
2122 TopLevel({
23+ required this.emptyOnly,
2224 required this.intersection,
2325 required this.inUnion,
2426 required this.maxlength,
@@ -30,6 +32,7 @@ class TopLevel {
3032 });
3133
3234 factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel(
35+ emptyOnly: json["emptyOnly"],
3336 intersection: json["intersection"],
3437 inUnion: json["inUnion"],
3538 maxlength: json["maxlength"],
@@ -41,6 +44,7 @@ class TopLevel {
4144 );
4245
4346 Map<String, dynamic> toJson() => {
47+ "emptyOnly": emptyOnly,
4448 "intersection": intersection,
4549 "inUnion": inUnion,
4650 "maxlength": maxlength,
Mschema-elixirdefault / QuickType.ex+5 −2
@@ -6,10 +6,11 @@
66 # Encode into a JSON string: TopLevel.to_json(struct)
77
88 defmodule TopLevel do
9- @enforce_keys [:intersection, :in_union, :maxlength, :minlength, :min_max_intersection, :minmaxlength, :min_max_union, :union]
10- defstruct [:intersection, :in_union, :maxlength, :minlength, :min_max_intersection, :minmaxlength, :min_max_union, :union]
9+ @enforce_keys [:empty_only, :intersection, :in_union, :maxlength, :minlength, :min_max_intersection, :minmaxlength, :min_max_union, :union]
10+ defstruct [:empty_only, :intersection, :in_union, :maxlength, :minlength, :min_max_intersection, :minmaxlength, :min_max_union, :union]
1111
1212 @type t :: %__MODULE__{
13+ empty_only: String.t(),
1314 intersection: String.t(),
1415 in_union: float() | String.t(),
1516 maxlength: String.t(),
@@ -22,6 +23,7 @@ defmodule TopLevel do
2223
2324 def from_map(m) do
2425 %TopLevel{
26+ empty_only: m["emptyOnly"],
2527 intersection: m["intersection"],
2628 in_union: m["inUnion"],
2729 maxlength: m["maxlength"],
@@ -41,6 +43,7 @@ defmodule TopLevel do
4143
4244 def to_map(struct) do
4345 %{
46+ "emptyOnly" => struct.empty_only,
4447 "intersection" => struct.intersection,
4548 "inUnion" => struct.in_union,
4649 "maxlength" => struct.maxlength,
Mschema-elmdefault / QuickType.elm+5 −2
@@ -24,7 +24,8 @@ import Json.Encode as Jenc
2424 import Dict exposing (Dict)
2525
2626 type alias QuickType =
27- { intersection : String
27+ { emptyOnly : String
28+ , intersection : String
2829 , inUnion : InUnion
2930 , maxlength : String
3031 , minlength : String
@@ -46,6 +47,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r)
4647 quickType : Jdec.Decoder QuickType
4748 quickType =
4849 Jdec.succeed QuickType
50+ |> Jpipe.required "emptyOnly" Jdec.string
4951 |> Jpipe.required "intersection" Jdec.string
5052 |> Jpipe.required "inUnion" inUnion
5153 |> Jpipe.required "maxlength" Jdec.string
@@ -58,7 +60,8 @@ quickType =
5860 encodeQuickType : QuickType -> Jenc.Value
5961 encodeQuickType x =
6062 Jenc.object
61- [ ("intersection", Jenc.string x.intersection)
63+ [ ("emptyOnly", Jenc.string x.emptyOnly)
64+ , ("intersection", Jenc.string x.intersection)
6265 , ("inUnion", encodeInUnion x.inUnion)
6366 , ("maxlength", Jenc.string x.maxlength)
6467 , ("minlength", Jenc.string x.minlength)
Mschema-flowdefault / TopLevel.js+2 −0
@@ -10,6 +10,7 @@
1010 // match the expected interface, even if the JSON is valid.
1111
1212 export type TopLevel = {
13+ emptyOnly: string;
1314 intersection: string;
1415 inUnion: InUnion;
1516 maxlength: string;
@@ -188,6 +189,7 @@ function r(name: string) {
188189
189190 const typeMap: any = {
190191 "TopLevel": o([
192+ { json: "emptyOnly", js: "emptyOnly", typ: "" },
191193 { json: "intersection", js: "intersection", typ: "" },
192194 { json: "inUnion", js: "inUnion", typ: u(3.14, "") },
193195 { json: "maxlength", js: "maxlength", typ: "" },
Mschema-golangdefault / quicktype.go+1 −0
@@ -22,6 +22,7 @@ func (r *TopLevel) Marshal() ([]byte, error) {
2222 }
2323
2424 type TopLevel struct {
25+ EmptyOnly string `json:"emptyOnly"`
2526 Intersection string `json:"intersection"`
2627 InUnion *InUnion `json:"inUnion"`
2728 Maxlength string `json:"maxlength"`
Mschema-haskelldefault / QuickType.hs+7 −4
@@ -14,7 +14,8 @@ import Data.HashMap.Strict (HashMap)
1414 import Data.Text (Text)
1515
1616 data QuickType = QuickType
17- { intersectionQuickType :: Text
17+ { emptyOnlyQuickType :: Text
18+ , intersectionQuickType :: Text
1819 , inUnionQuickType :: InUnion
1920 , maxlengthQuickType :: Text
2021 , minlengthQuickType :: Text
@@ -33,9 +34,10 @@ decodeTopLevel :: ByteString -> Maybe QuickType
3334 decodeTopLevel = decode
3435
3536 instance ToJSON QuickType where
36- toJSON (QuickType intersectionQuickType inUnionQuickType maxlengthQuickType minlengthQuickType minMaxIntersectionQuickType minmaxlengthQuickType minMaxUnionQuickType unionQuickType) =
37+ toJSON (QuickType emptyOnlyQuickType intersectionQuickType inUnionQuickType maxlengthQuickType minlengthQuickType minMaxIntersectionQuickType minmaxlengthQuickType minMaxUnionQuickType unionQuickType) =
3738 object
38- [ "intersection" .= intersectionQuickType
39+ [ "emptyOnly" .= emptyOnlyQuickType
40+ , "intersection" .= intersectionQuickType
3941 , "inUnion" .= inUnionQuickType
4042 , "maxlength" .= maxlengthQuickType
4143 , "minlength" .= minlengthQuickType
@@ -47,7 +49,8 @@ instance ToJSON QuickType where
4749
4850 instance FromJSON QuickType where
4951 parseJSON (Object v) = QuickType
50- <$> v .: "intersection"
52+ <$> v .: "emptyOnly"
53+ <*> v .: "intersection"
5154 <*> v .: "inUnion"
5255 <*> v .: "maxlength"
5356 <*> v .: "minlength"
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,6 +3,7 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String emptyOnly;
67 private String intersection;
78 private InUnion inUnion;
89 private String maxlength;
@@ -12,6 +13,11 @@ public class TopLevel {
1213 private String minMaxUnion;
1314 private String union;
1415
16+ @JsonProperty("emptyOnly")
17+ public String getEmptyOnly() { return emptyOnly; }
18+ @JsonProperty("emptyOnly")
19+ public void setEmptyOnly(String value) { this.emptyOnly = value; }
20+
1521 @JsonProperty("intersection")
1622 public String getIntersection() { return intersection; }
1723 @JsonProperty("intersection")
Mschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,6 +3,7 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String emptyOnly;
67 private String intersection;
78 private InUnion inUnion;
89 private String maxlength;
@@ -12,6 +13,11 @@ public class TopLevel {
1213 private String minMaxUnion;
1314 private String union;
1415
16+ @JsonProperty("emptyOnly")
17+ public String getEmptyOnly() { return emptyOnly; }
18+ @JsonProperty("emptyOnly")
19+ public void setEmptyOnly(String value) { this.emptyOnly = value; }
20+
1521 @JsonProperty("intersection")
1622 public String getIntersection() { return intersection; }
1723 @JsonProperty("intersection")
Mschema-javadefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,6 +3,7 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String emptyOnly;
67 private String intersection;
78 private InUnion inUnion;
89 private String maxlength;
@@ -12,6 +13,11 @@ public class TopLevel {
1213 private String minMaxUnion;
1314 private String union;
1415
16+ @JsonProperty("emptyOnly")
17+ public String getEmptyOnly() { return emptyOnly; }
18+ @JsonProperty("emptyOnly")
19+ public void setEmptyOnly(String value) { this.emptyOnly = value; }
20+
1521 @JsonProperty("intersection")
1622 public String getIntersection() { return intersection; }
1723 @JsonProperty("intersection")
Mschema-javascriptdefault / TopLevel.js+1 −0
@@ -172,6 +172,7 @@ function r(name) {
172172
173173 const typeMap = {
174174 "TopLevel": o([
175+ { json: "emptyOnly", js: "emptyOnly", typ: "" },
175176 { json: "intersection", js: "intersection", typ: "" },
176177 { json: "inUnion", js: "inUnion", typ: u(3.14, "") },
177178 { json: "maxlength", js: "maxlength", typ: "" },
Mschema-kotlin-jacksondefault / TopLevel.kt+3 −0
@@ -31,6 +31,9 @@ val mapper = jacksonObjectMapper().apply {
3131 }
3232
3333 data class TopLevel (
34+ @get:JsonProperty(required=true)@field:JsonProperty(required=true)
35+ val emptyOnly: String,
36+
3437 @get:JsonProperty(required=true)@field:JsonProperty(required=true)
3538 val intersection: String,
Mschema-kotlindefault / TopLevel.kt+1 −0
@@ -18,6 +18,7 @@ private val klaxon = Klaxon()
1818 .convert(InUnion::class, { InUnion.fromJson(it) }, { it.toJson() }, true)
1919
2020 data class TopLevel (
21+ val emptyOnly: String,
2122 val intersection: String,
2223 val inUnion: InUnion,
2324 val maxlength: String,
Mschema-phpdefault / TopLevel.php+66 −12
@@ -4,6 +4,7 @@ declare(strict_types=1);
44 // This is an autogenerated file:TopLevel
55
66 class TopLevel {
7+ private string $emptyOnly; // json:emptyOnly Required
78 private string $intersection; // json:intersection Required
89 private float|string $inUnion; // json:inUnion Required
910 private string $maxlength; // json:maxlength Required
@@ -14,6 +15,7 @@ class TopLevel {
1415 private string $union; // json:union Required
1516
1617 /**
18+ * @param string $emptyOnly
1719 * @param string $intersection
1820 * @param float|string $inUnion
1921 * @param string $maxlength
@@ -23,7 +25,8 @@ class TopLevel {
2325 * @param string $minMaxUnion
2426 * @param string $union
2527 */
26- public function __construct(string $intersection, float|string $inUnion, string $maxlength, string $minlength, string $minMaxIntersection, string $minmaxlength, string $minMaxUnion, string $union) {
28+ public function __construct(string $emptyOnly, string $intersection, float|string $inUnion, string $maxlength, string $minlength, string $minMaxIntersection, string $minmaxlength, string $minMaxUnion, string $union) {
29+ $this->emptyOnly = $emptyOnly;
2730 $this->intersection = $intersection;
2831 $this->inUnion = $inUnion;
2932 $this->maxlength = $maxlength;
@@ -34,6 +37,53 @@ class TopLevel {
3437 $this->union = $union;
3538 }
3639
40+ /**
41+ * @param string $value
42+ * @throws Exception
43+ * @return string
44+ */
45+ public static function fromEmptyOnly(string $value): string {
46+ return $value; /*string*/
47+ }
48+
49+ /**
50+ * @throws Exception
51+ * @return string
52+ */
53+ public function toEmptyOnly(): string {
54+ if (TopLevel::validateEmptyOnly($this->emptyOnly)) {
55+ return $this->emptyOnly; /*string*/
56+ }
57+ throw new Exception('never get to this TopLevel::emptyOnly');
58+ }
59+
60+ /**
61+ * @param string
62+ * @return bool
63+ * @throws Exception
64+ */
65+ public static function validateEmptyOnly(string $value): bool {
66+ return true;
67+ }
68+
69+ /**
70+ * @throws Exception
71+ * @return string
72+ */
73+ public function getEmptyOnly(): string {
74+ if (TopLevel::validateEmptyOnly($this->emptyOnly)) {
75+ return $this->emptyOnly;
76+ }
77+ throw new Exception('never get to getEmptyOnly TopLevel::emptyOnly');
78+ }
79+
80+ /**
81+ * @return string
82+ */
83+ public static function sampleEmptyOnly(): string {
84+ return 'TopLevel::emptyOnly::31'; /*31:emptyOnly*/
85+ }
86+
3787 /**
3888 * @param string $value
3989 * @throws Exception
@@ -78,7 +128,7 @@ class TopLevel {
78128 * @return string
79129 */
80130 public static function sampleIntersection(): string {
81- return 'TopLevel::intersection::31'; /*31:intersection*/
131+ return 'TopLevel::intersection::32'; /*32:intersection*/
82132 }
83133
84134 /**
@@ -148,7 +198,7 @@ class TopLevel {
148198 * @return float|string
149199 */
150200 public static function sampleInUnion(): float|string {
151- return 32.032; /*32:inUnion*/
201+ return 33.033; /*33:inUnion*/
152202 }
153203
154204 /**
@@ -195,7 +245,7 @@ class TopLevel {
195245 * @return string
196246 */
197247 public static function sampleMaxlength(): string {
198- return 'TopLevel::maxlength::33'; /*33:maxlength*/
248+ return 'TopLevel::maxlength::34'; /*34:maxlength*/
199249 }
200250
201251 /**
@@ -242,7 +292,7 @@ class TopLevel {
242292 * @return string
243293 */
244294 public static function sampleMinlength(): string {
245- return 'TopLevel::minlength::34'; /*34:minlength*/
295+ return 'TopLevel::minlength::35'; /*35:minlength*/
246296 }
247297
248298 /**
@@ -289,7 +339,7 @@ class TopLevel {
289339 * @return string
290340 */
291341 public static function sampleMinMaxIntersection(): string {
292- return 'TopLevel::minMaxIntersection::35'; /*35:minMaxIntersection*/
342+ return 'TopLevel::minMaxIntersection::36'; /*36:minMaxIntersection*/
293343 }
294344
295345 /**
@@ -336,7 +386,7 @@ class TopLevel {
336386 * @return string
337387 */
338388 public static function sampleMinmaxlength(): string {
339- return 'TopLevel::minmaxlength::36'; /*36:minmaxlength*/
389+ return 'TopLevel::minmaxlength::37'; /*37:minmaxlength*/
340390 }
341391
342392 /**
@@ -383,7 +433,7 @@ class TopLevel {
383433 * @return string
384434 */
385435 public static function sampleMinMaxUnion(): string {
386- return 'TopLevel::minMaxUnion::37'; /*37:minMaxUnion*/
436+ return 'TopLevel::minMaxUnion::38'; /*38:minMaxUnion*/
387437 }
388438
389439 /**
@@ -430,7 +480,7 @@ class TopLevel {
430480 * @return string
431481 */
432482 public static function sampleUnion(): string {
433- return 'TopLevel::union::38'; /*38:union*/
483+ return 'TopLevel::union::39'; /*39:union*/
434484 }
435485
436486 /**
@@ -438,7 +488,8 @@ class TopLevel {
438488 * @return bool
439489 */
440490 public function validate(): bool {
441- return TopLevel::validateIntersection($this->intersection)
491+ return TopLevel::validateEmptyOnly($this->emptyOnly)
492+ || TopLevel::validateIntersection($this->intersection)
442493 || TopLevel::validateInUnion($this->inUnion)
443494 || TopLevel::validateMaxlength($this->maxlength)
444495 || TopLevel::validateMinlength($this->minlength)
@@ -454,6 +505,7 @@ class TopLevel {
454505 */
455506 public function to(): stdClass {
456507 $out = new stdClass();
508+ $out->{'emptyOnly'} = $this->toEmptyOnly();
457509 $out->{'intersection'} = $this->toIntersection();
458510 $out->{'inUnion'} = $this->toInUnion();
459511 $out->{'maxlength'} = $this->toMaxlength();
@@ -472,7 +524,8 @@ class TopLevel {
472524 */
473525 public static function from(stdClass $obj): TopLevel {
474526 return new TopLevel(
475- TopLevel::fromIntersection($obj->{'intersection'})
527+ TopLevel::fromEmptyOnly($obj->{'emptyOnly'})
528+ ,TopLevel::fromIntersection($obj->{'intersection'})
476529 ,TopLevel::fromInUnion($obj->{'inUnion'})
477530 ,TopLevel::fromMaxlength($obj->{'maxlength'})
478531 ,TopLevel::fromMinlength($obj->{'minlength'})
@@ -488,7 +541,8 @@ class TopLevel {
488541 */
489542 public static function sample(): TopLevel {
490543 return new TopLevel(
491- TopLevel::sampleIntersection()
544+ TopLevel::sampleEmptyOnly()
545+ ,TopLevel::sampleIntersection()
492546 ,TopLevel::sampleInUnion()
493547 ,TopLevel::sampleMaxlength()
494548 ,TopLevel::sampleMinlength()
Mschema-pikedefault / TopLevel.pmod+3 −0
@@ -13,6 +13,7 @@
1313 // match the expected interface, even if the JSON itself is valid.
1414
1515 class TopLevel {
16+ string empty_only; // json: "emptyOnly"
1617 string intersection; // json: "intersection"
1718 InUnion in_union; // json: "inUnion"
1819 string maxlength; // json: "maxlength"
@@ -24,6 +25,7 @@ class TopLevel {
2425
2526 string encode_json() {
2627 mapping(string:mixed) json = ([
28+ "emptyOnly" : empty_only,
2729 "intersection" : intersection,
2830 "inUnion" : in_union,
2931 "maxlength" : maxlength,
@@ -41,6 +43,7 @@ class TopLevel {
4143 TopLevel TopLevel_from_JSON(mixed json) {
4244 TopLevel retval = TopLevel();
4345
46+ retval.empty_only = json["emptyOnly"];
4447 retval.intersection = json["intersection"];
4548 retval.in_union = json["inUnion"];
4649 retval.maxlength = json["maxlength"];
Mschema-pythondefault / quicktype.py+4 −1
@@ -36,6 +36,7 @@ def to_class(c: Type[T], x: Any) -> dict:
3636
3737 @dataclass
3838 class TopLevel:
39+ empty_only: str
3940 intersection: str
4041 in_union: float | str
4142 maxlength: str
@@ -48,6 +49,7 @@ class TopLevel:
4849 @staticmethod
4950 def from_dict(obj: Any) -> 'TopLevel':
5051 assert isinstance(obj, dict)
52+ empty_only = from_str(obj.get("emptyOnly"))
5153 intersection = from_str(obj.get("intersection"))
5254 in_union = from_union([from_float, from_str], obj.get("inUnion"))
5355 maxlength = from_str(obj.get("maxlength"))
@@ -56,10 +58,11 @@ class TopLevel:
5658 minmaxlength = from_str(obj.get("minmaxlength"))
5759 min_max_union = from_str(obj.get("minMaxUnion"))
5860 union = from_str(obj.get("union"))
59- return TopLevel(intersection, in_union, maxlength, minlength, min_max_intersection, minmaxlength, min_max_union, union)
61+ return TopLevel(empty_only, intersection, in_union, maxlength, minlength, min_max_intersection, minmaxlength, min_max_union, union)
6062
6163 def to_dict(self) -> dict:
6264 result: dict = {}
65+ result["emptyOnly"] = from_str(self.empty_only)
6366 result["intersection"] = from_str(self.intersection)
6467 result["inUnion"] = from_union([to_float, from_str], self.in_union)
6568 result["maxlength"] = from_str(self.maxlength)
Mschema-rubydefault / TopLevel.rb+4 −1
@@ -4,7 +4,7 @@
44 # To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do:
55 #
66 # top_level = TopLevel.from_json! "{…}"
7-# puts top_level.intersection
7+# puts top_level.empty_only
88 #
99 # If from_json! succeeds, the value returned matches the schema.
1010
@@ -52,6 +52,7 @@ class InUnion < Dry::Struct
5252 end
5353
5454 class TopLevel < Dry::Struct
55+ attribute :empty_only, Types::String
5556 attribute :intersection, Types::String
5657 attribute :in_union, Types.Instance(InUnion)
5758 attribute :maxlength, Types::String
@@ -64,6 +65,7 @@ class TopLevel < Dry::Struct
6465 def self.from_dynamic!(d)
6566 d = Types::Hash[d]
6667 new(
68+ empty_only: d.fetch("emptyOnly"),
6769 intersection: d.fetch("intersection"),
6870 in_union: InUnion.from_dynamic!(d.fetch("inUnion")),
6971 maxlength: d.fetch("maxlength"),
@@ -81,6 +83,7 @@ class TopLevel < Dry::Struct
8183
8284 def to_dynamic
8385 {
86+ "emptyOnly" => empty_only,
8487 "intersection" => intersection,
8588 "inUnion" => in_union.to_dynamic,
8689 "maxlength" => maxlength,
Mschema-rustdefault / module_under_test.rs+2 −0
@@ -16,6 +16,8 @@ use serde::{Serialize, Deserialize};
1616 #[derive(Debug, Clone, Serialize, Deserialize)]
1717 #[serde(rename_all = "camelCase")]
1818 pub struct TopLevel {
19+ pub empty_only: String,
20+
1921 pub intersection: String,
2022
2123 pub in_union: InUnion,
Mschema-scala3-upickledefault / TopLevel.scala+1 −0
@@ -66,6 +66,7 @@ end JsonExt
6666
6767
6868 case class TopLevel (
69+ val emptyOnly : String,
6970 val intersection : String,
7071 val inUnion : InUnion,
7172 val maxlength : String,
Mschema-scala3default / TopLevel.scala+1 −0
@@ -8,6 +8,7 @@ import cats.syntax.functor._
88 type NullValue = None.type
99
1010 case class TopLevel (
11+ val emptyOnly : String,
1112 val intersection : String,
1213 val inUnion : InUnion,
1314 val maxlength : String,
Mschema-schemadefault / TopLevel.schema+13 −4
@@ -6,10 +6,15 @@
66 "type": "object",
77 "additionalProperties": {},
88 "properties": {
9+ "emptyOnly": {
10+ "type": "string",
11+ "maxLength": 0
12+ },
913 "intersection": {
1014 "type": "string",
1115 "minLength": 4,
12- "maxLength": 5
16+ "maxLength": 5,
17+ "pattern": "^[a-z]+$"
1318 },
1419 "inUnion": {
1520 "$ref": "#/definitions/InUnion"
@@ -30,7 +35,8 @@
3035 "minmaxlength": {
3136 "type": "string",
3237 "minLength": 3,
33- "maxLength": 5
38+ "maxLength": 5,
39+ "pattern": "^[a-z]+$"
3440 },
3541 "minMaxUnion": {
3642 "type": "string"
@@ -38,10 +44,12 @@
3844 "union": {
3945 "type": "string",
4046 "minLength": 3,
41- "maxLength": 6
47+ "maxLength": 6,
48+ "pattern": "^[a-z]+$"
4249 }
4350 },
4451 "required": [
52+ "emptyOnly",
4553 "inUnion",
4654 "intersection",
4755 "maxlength",
@@ -61,7 +69,8 @@
6169 {
6270 "type": "string",
6371 "minLength": 3,
64- "maxLength": 5
72+ "maxLength": 5,
73+ "pattern": "^[a-z]+$"
6574 }
6675 ],
6776 "title": "InUnion"
Mschema-swiftdefault / quicktype.swift+4 −0
@@ -7,6 +7,7 @@ import Foundation
77
88 // MARK: - TopLevel
99 struct TopLevel: Codable {
10+ let emptyOnly: String
1011 let intersection: String
1112 let inUnion: InUnion
1213 let maxlength: String
@@ -17,6 +18,7 @@ struct TopLevel: Codable {
1718 let union: String
1819
1920 enum CodingKeys: String, CodingKey {
21+ case emptyOnly = "emptyOnly"
2022 case intersection = "intersection"
2123 case inUnion = "inUnion"
2224 case maxlength = "maxlength"
@@ -47,6 +49,7 @@ extension TopLevel {
4749 }
4850
4951 func with(
52+ emptyOnly: String? = nil,
5053 intersection: String? = nil,
5154 inUnion: InUnion? = nil,
5255 maxlength: String? = nil,
@@ -57,6 +60,7 @@ extension TopLevel {
5760 union: String? = nil
5861 ) -> TopLevel {
5962 return TopLevel(
63+ emptyOnly: emptyOnly ?? self.emptyOnly,
6064 intersection: intersection ?? self.intersection,
6165 inUnion: inUnion ?? self.inUnion,
6266 maxlength: maxlength ?? self.maxlength,
Mschema-typescript-zoddefault / TopLevel.ts+8 −7
@@ -2,13 +2,14 @@ import * as z from "zod";
22
33
44 export const TopLevelSchema = z.object({
5- "intersection": z.string(),
6- "inUnion": z.union([z.number(), z.string()]),
7- "maxlength": z.string(),
8- "minlength": z.string(),
9- "minMaxIntersection": z.string(),
10- "minmaxlength": z.string(),
5+ "emptyOnly": z.string().max(0),
6+ "intersection": z.string().min(4).max(5).regex(new RegExp("^[a-z]+$")),
7+ "inUnion": z.union([z.number(), z.string().min(3).max(5).regex(new RegExp("^[a-z]+$"))]),
8+ "maxlength": z.string().max(5),
9+ "minlength": z.string().min(3),
10+ "minMaxIntersection": z.string().min(3).max(5),
11+ "minmaxlength": z.string().min(3).max(5).regex(new RegExp("^[a-z]+$")),
1112 "minMaxUnion": z.string(),
12- "union": z.string(),
13+ "union": z.string().min(3).max(6).regex(new RegExp("^[a-z]+$")),
1314 });
1415 export type TopLevel = z.infer<typeof TopLevelSchema>;
Mschema-typescriptdefault / TopLevel.ts+2 −0
@@ -8,6 +8,7 @@
88 // match the expected interface, even if the JSON is valid.
99
1010 export interface TopLevel {
11+ emptyOnly: string;
1112 intersection: string;
1213 inUnion: InUnion;
1314 maxlength: string;
@@ -188,6 +189,7 @@ function r(name: string) {
188189
189190 const typeMap: any = {
190191 "TopLevel": o([
192+ { json: "emptyOnly", js: "emptyOnly", typ: "" },
191193 { json: "intersection", js: "intersection", typ: "" },
192194 { json: "inUnion", js: "inUnion", typ: u(3.14, "") },
193195 { json: "maxlength", js: "maxlength", typ: "" },
Test case

test/inputs/schema/optional-const-ref.schema

1 generated file · +2 −2
Mschema-typescript-zoddefault / TopLevel.ts+2 −2
@@ -10,10 +10,10 @@ export type Coordinate = z.infer<typeof CoordinateSchema>;
1010 export const TopLevelSchema = z.object({
1111 "coordinates": z.array(CoordinateSchema).optional(),
1212 "count": z.number().optional(),
13- "label": z.string().optional(),
13+ "label": z.string().min(2).max(16).optional(),
1414 "requiredCoordinates": z.array(CoordinateSchema),
1515 "requiredCount": z.number(),
16- "requiredLabel": z.string(),
16+ "requiredLabel": z.string().min(2).max(16),
1717 "weight": z.number().optional(),
1818 });
1919 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/schema/optional-constraints.schema

1 generated file · +2 −2
Mschema-typescript-zoddefault / TopLevel.ts+2 −2
@@ -4,8 +4,8 @@ import * as z from "zod";
44 export const TopLevelSchema = z.object({
55 "optDouble": z.number().optional(),
66 "optInt": z.number().optional(),
7- "optPattern": z.string().optional(),
8- "optString": z.string().optional(),
7+ "optPattern": z.string().regex(new RegExp("^[a-z]+$")).optional(),
8+ "optString": z.string().min(3).max(10).optional(),
99 "reqZeroMin": z.number(),
1010 });
1111 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/schema/pattern.schema

28 generated files · +158 −20
Mschema-cplusplusdefault / quicktype.hpp+9 −0
@@ -165,6 +165,7 @@ namespace quicktype {
165165 class TopLevel {
166166 public:
167167 TopLevel() :
168+ escaped_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("^\\d+\\.[a-z]+$")),
168169 pattern1_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("a[.]*")),
169170 pattern2_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("b[.]*")),
170171 union_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("(b[.]*)|(c[.]*)"))
@@ -172,6 +173,8 @@ namespace quicktype {
172173 virtual ~TopLevel() = default;
173174
174175 private:
176+ std::string escaped;
177+ ClassMemberConstraints escaped_constraint;
175178 std::string pattern1;
176179 ClassMemberConstraints pattern1_constraint;
177180 std::string pattern2;
@@ -180,6 +183,10 @@ namespace quicktype {
180183 ClassMemberConstraints union_constraint;
181184
182185 public:
186+ const std::string & get_escaped() const { return escaped; }
187+ std::string & get_mutable_escaped() { return escaped; }
188+ void set_escaped(const std::string & value) { CheckConstraint("escaped", escaped_constraint, value); this->escaped = value; }
189+
183190 const std::string & get_pattern1() const { return pattern1; }
184191 std::string & get_mutable_pattern1() { return pattern1; }
185192 void set_pattern1(const std::string & value) { CheckConstraint("pattern1", pattern1_constraint, value); this->pattern1 = value; }
@@ -199,6 +206,7 @@ namespace quicktype {
199206 void to_json(json & j, const TopLevel & x);
200207
201208 inline void from_json(const json & j, TopLevel& x) {
209+ x.set_escaped(j.at("escaped").get<std::string>());
202210 x.set_pattern1(j.at("pattern1").get<std::string>());
203211 x.set_pattern2(j.at("pattern2").get<std::string>());
204212 x.set_top_level_union(j.at("union").get<std::string>());
@@ -206,6 +214,7 @@ namespace quicktype {
206214
207215 inline void to_json(json & j, const TopLevel & x) {
208216 j = json::object();
217+ j["escaped"] = x.get_escaped();
209218 j["pattern1"] = x.get_pattern1();
210219 j["pattern2"] = x.get_pattern2();
211220 j["union"] = x.get_top_level_union();
Mschema-csharp-recordsdefault / QuickType.cs+3 −0
@@ -25,6 +25,9 @@ namespace QuickType
2525
2626 public partial record TopLevel
2727 {
28+ [JsonProperty("escaped", Required = Required.Always)]
29+ public string Escaped { get; set; }
30+
2831 [JsonProperty("pattern1", Required = Required.Always)]
2932 public string Pattern1 { get; set; }
Mschema-csharp-SystemTextJsondefault / QuickType.cs+4 −0
@@ -22,6 +22,10 @@ namespace QuickType
2222
2323 public partial class TopLevel
2424 {
25+ [JsonRequired]
26+ [JsonPropertyName("escaped")]
27+ public string Escaped { get; set; }
28+
2529 [JsonRequired]
2630 [JsonPropertyName("pattern1")]
2731 public string Pattern1 { get; set; }
Mschema-csharpdefault / QuickType.cs+3 −0
@@ -25,6 +25,9 @@ namespace QuickType
2525
2626 public partial class TopLevel
2727 {
28+ [JsonProperty("escaped", Required = Required.Always)]
29+ public string Escaped { get; set; }
30+
2831 [JsonProperty("pattern1", Required = Required.Always)]
2932 public string Pattern1 { get; set; }
Mschema-dartdefault / TopLevel.dart+4 −0
@@ -9,23 +9,27 @@ TopLevel topLevelFromJson(String str) => TopLevel.fromJson(json.decode(str));
99 String topLevelToJson(TopLevel data) => json.encode(data.toJson());
1010
1111 class TopLevel {
12+ final String escaped;
1213 final String pattern1;
1314 final String pattern2;
1415 final String union;
1516
1617 TopLevel({
18+ required this.escaped,
1719 required this.pattern1,
1820 required this.pattern2,
1921 required this.union,
2022 });
2123
2224 factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel(
25+ escaped: json["escaped"],
2326 pattern1: json["pattern1"],
2427 pattern2: json["pattern2"],
2528 union: json["union"],
2629 );
2730
2831 Map<String, dynamic> toJson() => {
32+ "escaped": escaped,
2933 "pattern1": pattern1,
3034 "pattern2": pattern2,
3135 "union": union,
Mschema-elixirdefault / QuickType.ex+5 −2
@@ -6,10 +6,11 @@
66 # Encode into a JSON string: TopLevel.to_json(struct)
77
88 defmodule TopLevel do
9- @enforce_keys [:pattern1, :pattern2, :union]
10- defstruct [:pattern1, :pattern2, :union]
9+ @enforce_keys [:escaped, :pattern1, :pattern2, :union]
10+ defstruct [:escaped, :pattern1, :pattern2, :union]
1111
1212 @type t :: %__MODULE__{
13+ escaped: String.t(),
1314 pattern1: String.t(),
1415 pattern2: String.t(),
1516 union: String.t()
@@ -17,6 +18,7 @@ defmodule TopLevel do
1718
1819 def from_map(m) do
1920 %TopLevel{
21+ escaped: m["escaped"],
2022 pattern1: m["pattern1"],
2123 pattern2: m["pattern2"],
2224 union: m["union"],
@@ -31,6 +33,7 @@ defmodule TopLevel do
3133
3234 def to_map(struct) do
3335 %{
36+ "escaped" => struct.escaped,
3437 "pattern1" => struct.pattern1,
3538 "pattern2" => struct.pattern2,
3639 "union" => struct.union,
Mschema-elmdefault / QuickType.elm+5 −2
@@ -23,7 +23,8 @@ import Json.Encode as Jenc
2323 import Dict exposing (Dict)
2424
2525 type alias QuickType =
26- { pattern1 : String
26+ { escaped : String
27+ , pattern1 : String
2728 , pattern2 : String
2829 , union : String
2930 }
@@ -36,6 +37,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r)
3637 quickType : Jdec.Decoder QuickType
3738 quickType =
3839 Jdec.succeed QuickType
40+ |> Jpipe.required "escaped" Jdec.string
3941 |> Jpipe.required "pattern1" Jdec.string
4042 |> Jpipe.required "pattern2" Jdec.string
4143 |> Jpipe.required "union" Jdec.string
@@ -43,7 +45,8 @@ quickType =
4345 encodeQuickType : QuickType -> Jenc.Value
4446 encodeQuickType x =
4547 Jenc.object
46- [ ("pattern1", Jenc.string x.pattern1)
48+ [ ("escaped", Jenc.string x.escaped)
49+ , ("pattern1", Jenc.string x.pattern1)
4750 , ("pattern2", Jenc.string x.pattern2)
4851 , ("union", Jenc.string x.union)
4952 ]
Mschema-flowdefault / TopLevel.js+2 −0
@@ -10,6 +10,7 @@
1010 // match the expected interface, even if the JSON is valid.
1111
1212 export type TopLevel = {
13+ escaped: string;
1314 pattern1: string;
1415 pattern2: string;
1516 union: string;
@@ -181,6 +182,7 @@ function r(name: string) {
181182
182183 const typeMap: any = {
183184 "TopLevel": o([
185+ { json: "escaped", js: "escaped", typ: "" },
184186 { json: "pattern1", js: "pattern1", typ: "" },
185187 { json: "pattern2", js: "pattern2", typ: "" },
186188 { json: "union", js: "union", typ: "" },
Mschema-golangdefault / quicktype.go+1 −0
@@ -19,6 +19,7 @@ func (r *TopLevel) Marshal() ([]byte, error) {
1919 }
2020
2121 type TopLevel struct {
22+ Escaped string `json:"escaped"`
2223 Pattern1 string `json:"pattern1"`
2324 Pattern2 string `json:"pattern2"`
2425 Union string `json:"union"`
Mschema-haskelldefault / QuickType.hs+7 −4
@@ -13,7 +13,8 @@ import Data.HashMap.Strict (HashMap)
1313 import Data.Text (Text)
1414
1515 data QuickType = QuickType
16- { pattern1QuickType :: Text
16+ { escapedQuickType :: Text
17+ , pattern1QuickType :: Text
1718 , pattern2QuickType :: Text
1819 , unionQuickType :: Text
1920 } deriving (Show)
@@ -22,15 +23,17 @@ decodeTopLevel :: ByteString -> Maybe QuickType
2223 decodeTopLevel = decode
2324
2425 instance ToJSON QuickType where
25- toJSON (QuickType pattern1QuickType pattern2QuickType unionQuickType) =
26+ toJSON (QuickType escapedQuickType pattern1QuickType pattern2QuickType unionQuickType) =
2627 object
27- [ "pattern1" .= pattern1QuickType
28+ [ "escaped" .= escapedQuickType
29+ , "pattern1" .= pattern1QuickType
2830 , "pattern2" .= pattern2QuickType
2931 , "union" .= unionQuickType
3032 ]
3133
3234 instance FromJSON QuickType where
3335 parseJSON (Object v) = QuickType
34- <$> v .: "pattern1"
36+ <$> v .: "escaped"
37+ <*> v .: "pattern1"
3538 <*> v .: "pattern2"
3639 <*> v .: "union"
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,10 +3,16 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String escaped;
67 private String pattern1;
78 private String pattern2;
89 private String union;
910
11+ @JsonProperty("escaped")
12+ public String getEscaped() { return escaped; }
13+ @JsonProperty("escaped")
14+ public void setEscaped(String value) { this.escaped = value; }
15+
1016 @JsonProperty("pattern1")
1117 public String getPattern1() { return pattern1; }
1218 @JsonProperty("pattern1")
Mschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,10 +3,16 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String escaped;
67 private String pattern1;
78 private String pattern2;
89 private String union;
910
11+ @JsonProperty("escaped")
12+ public String getEscaped() { return escaped; }
13+ @JsonProperty("escaped")
14+ public void setEscaped(String value) { this.escaped = value; }
15+
1016 @JsonProperty("pattern1")
1117 public String getPattern1() { return pattern1; }
1218 @JsonProperty("pattern1")
Mschema-javadefault / src / main / java / io / quicktype / TopLevel.java+6 −0
@@ -3,10 +3,16 @@ package io.quicktype;
33 import com.fasterxml.jackson.annotation.*;
44
55 public class TopLevel {
6+ private String escaped;
67 private String pattern1;
78 private String pattern2;
89 private String union;
910
11+ @JsonProperty("escaped")
12+ public String getEscaped() { return escaped; }
13+ @JsonProperty("escaped")
14+ public void setEscaped(String value) { this.escaped = value; }
15+
1016 @JsonProperty("pattern1")
1117 public String getPattern1() { return pattern1; }
1218 @JsonProperty("pattern1")
Mschema-javascriptdefault / TopLevel.js+1 −0
@@ -172,6 +172,7 @@ function r(name) {
172172
173173 const typeMap = {
174174 "TopLevel": o([
175+ { json: "escaped", js: "escaped", typ: "" },
175176 { json: "pattern1", js: "pattern1", typ: "" },
176177 { json: "pattern2", js: "pattern2", typ: "" },
177178 { json: "union", js: "union", typ: "" },
Mschema-kotlin-jacksondefault / TopLevel.kt+3 −0
@@ -19,6 +19,9 @@ val mapper = jacksonObjectMapper().apply {
1919 }
2020
2121 data class TopLevel (
22+ @get:JsonProperty(required=true)@field:JsonProperty(required=true)
23+ val escaped: String,
24+
2225 @get:JsonProperty(required=true)@field:JsonProperty(required=true)
2326 val pattern1: String,
Mschema-kotlindefault / TopLevel.kt+1 −0
@@ -9,6 +9,7 @@ import com.beust.klaxon.*
99 private val klaxon = Klaxon()
1010
1111 data class TopLevel (
12+ val escaped: String,
1213 val pattern1: String,
1314 val pattern2: String,
1415 val union: String
Mschema-kotlinxdefault / TopLevel.kt+1 −0
@@ -12,6 +12,7 @@ import kotlinx.serialization.encoding.*
1212
1313 @Serializable
1414 data class TopLevel (
15+ val escaped: String,
1516 val pattern1: String,
1617 val pattern2: String,
1718 val union: String
Mschema-phpdefault / TopLevel.php+61 −7
@@ -4,21 +4,71 @@ declare(strict_types=1);
44 // This is an autogenerated file:TopLevel
55
66 class TopLevel {
7+ private string $escaped; // json:escaped Required
78 private string $pattern1; // json:pattern1 Required
89 private string $pattern2; // json:pattern2 Required
910 private string $union; // json:union Required
1011
1112 /**
13+ * @param string $escaped
1214 * @param string $pattern1
1315 * @param string $pattern2
1416 * @param string $union
1517 */
16- public function __construct(string $pattern1, string $pattern2, string $union) {
18+ public function __construct(string $escaped, string $pattern1, string $pattern2, string $union) {
19+ $this->escaped = $escaped;
1720 $this->pattern1 = $pattern1;
1821 $this->pattern2 = $pattern2;
1922 $this->union = $union;
2023 }
2124
25+ /**
26+ * @param string $value
27+ * @throws Exception
28+ * @return string
29+ */
30+ public static function fromEscaped(string $value): string {
31+ return $value; /*string*/
32+ }
33+
34+ /**
35+ * @throws Exception
36+ * @return string
37+ */
38+ public function toEscaped(): string {
39+ if (TopLevel::validateEscaped($this->escaped)) {
40+ return $this->escaped; /*string*/
41+ }
42+ throw new Exception('never get to this TopLevel::escaped');
43+ }
44+
45+ /**
46+ * @param string
47+ * @return bool
48+ * @throws Exception
49+ */
50+ public static function validateEscaped(string $value): bool {
51+ return true;
52+ }
53+
54+ /**
55+ * @throws Exception
56+ * @return string
57+ */
58+ public function getEscaped(): string {
59+ if (TopLevel::validateEscaped($this->escaped)) {
60+ return $this->escaped;
61+ }
62+ throw new Exception('never get to getEscaped TopLevel::escaped');
63+ }
64+
65+ /**
66+ * @return string
67+ */
68+ public static function sampleEscaped(): string {
69+ return 'TopLevel::escaped::31'; /*31:escaped*/
70+ }
71+
2272 /**
2373 * @param string $value
2474 * @throws Exception
@@ -63,7 +113,7 @@ class TopLevel {
63113 * @return string
64114 */
65115 public static function samplePattern1(): string {
66- return 'TopLevel::pattern1::31'; /*31:pattern1*/
116+ return 'TopLevel::pattern1::32'; /*32:pattern1*/
67117 }
68118
69119 /**
@@ -110,7 +160,7 @@ class TopLevel {
110160 * @return string
111161 */
112162 public static function samplePattern2(): string {
113- return 'TopLevel::pattern2::32'; /*32:pattern2*/
163+ return 'TopLevel::pattern2::33'; /*33:pattern2*/
114164 }
115165
116166 /**
@@ -157,7 +207,7 @@ class TopLevel {
157207 * @return string
158208 */
159209 public static function sampleUnion(): string {
160- return 'TopLevel::union::33'; /*33:union*/
210+ return 'TopLevel::union::34'; /*34:union*/
161211 }
162212
163213 /**
@@ -165,7 +215,8 @@ class TopLevel {
165215 * @return bool
166216 */
167217 public function validate(): bool {
168- return TopLevel::validatePattern1($this->pattern1)
218+ return TopLevel::validateEscaped($this->escaped)
219+ || TopLevel::validatePattern1($this->pattern1)
169220 || TopLevel::validatePattern2($this->pattern2)
170221 || TopLevel::validateUnion($this->union);
171222 }
@@ -176,6 +227,7 @@ class TopLevel {
176227 */
177228 public function to(): stdClass {
178229 $out = new stdClass();
230+ $out->{'escaped'} = $this->toEscaped();
179231 $out->{'pattern1'} = $this->toPattern1();
180232 $out->{'pattern2'} = $this->toPattern2();
181233 $out->{'union'} = $this->toUnion();
@@ -189,7 +241,8 @@ class TopLevel {
189241 */
190242 public static function from(stdClass $obj): TopLevel {
191243 return new TopLevel(
192- TopLevel::fromPattern1($obj->{'pattern1'})
244+ TopLevel::fromEscaped($obj->{'escaped'})
245+ ,TopLevel::fromPattern1($obj->{'pattern1'})
193246 ,TopLevel::fromPattern2($obj->{'pattern2'})
194247 ,TopLevel::fromUnion($obj->{'union'})
195248 );
@@ -200,7 +253,8 @@ class TopLevel {
200253 */
201254 public static function sample(): TopLevel {
202255 return new TopLevel(
203- TopLevel::samplePattern1()
256+ TopLevel::sampleEscaped()
257+ ,TopLevel::samplePattern1()
204258 ,TopLevel::samplePattern2()
205259 ,TopLevel::sampleUnion()
206260 );
Mschema-pikedefault / TopLevel.pmod+3 −0
@@ -13,12 +13,14 @@
1313 // match the expected interface, even if the JSON itself is valid.
1414
1515 class TopLevel {
16+ string escaped; // json: "escaped"
1617 string pattern1; // json: "pattern1"
1718 string pattern2; // json: "pattern2"
1819 string union; // json: "union"
1920
2021 string encode_json() {
2122 mapping(string:mixed) json = ([
23+ "escaped" : escaped,
2224 "pattern1" : pattern1,
2325 "pattern2" : pattern2,
2426 "union" : union,
@@ -31,6 +33,7 @@ class TopLevel {
3133 TopLevel TopLevel_from_JSON(mixed json) {
3234 TopLevel retval = TopLevel();
3335
36+ retval.escaped = json["escaped"];
3437 retval.pattern1 = json["pattern1"];
3538 retval.pattern2 = json["pattern2"];
3639 retval.union = json["union"];
Mschema-pythondefault / quicktype.py+4 −1
@@ -17,6 +17,7 @@ def to_class(c: Type[T], x: Any) -> dict:
1717
1818 @dataclass
1919 class TopLevel:
20+ escaped: str
2021 pattern1: str
2122 pattern2: str
2223 union: str
@@ -24,13 +25,15 @@ class TopLevel:
2425 @staticmethod
2526 def from_dict(obj: Any) -> 'TopLevel':
2627 assert isinstance(obj, dict)
28+ escaped = from_str(obj.get("escaped"))
2729 pattern1 = from_str(obj.get("pattern1"))
2830 pattern2 = from_str(obj.get("pattern2"))
2931 union = from_str(obj.get("union"))
30- return TopLevel(pattern1, pattern2, union)
32+ return TopLevel(escaped, pattern1, pattern2, union)
3133
3234 def to_dict(self) -> dict:
3335 result: dict = {}
36+ result["escaped"] = from_str(self.escaped)
3437 result["pattern1"] = from_str(self.pattern1)
3538 result["pattern2"] = from_str(self.pattern2)
3639 result["union"] = from_str(self.union)
Mschema-rubydefault / TopLevel.rb+4 −1
@@ -4,7 +4,7 @@
44 # To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do:
55 #
66 # top_level = TopLevel.from_json! "{…}"
7-# puts top_level.pattern1
7+# puts top_level.escaped
88 #
99 # If from_json! succeeds, the value returned matches the schema.
1010
@@ -20,6 +20,7 @@ module Types
2020 end
2121
2222 class TopLevel < Dry::Struct
23+ attribute :escaped, Types::String
2324 attribute :pattern1, Types::String
2425 attribute :pattern2, Types::String
2526 attribute :union, Types::String
@@ -27,6 +28,7 @@ class TopLevel < Dry::Struct
2728 def self.from_dynamic!(d)
2829 d = Types::Hash[d]
2930 new(
31+ escaped: d.fetch("escaped"),
3032 pattern1: d.fetch("pattern1"),
3133 pattern2: d.fetch("pattern2"),
3234 union: d.fetch("union"),
@@ -39,6 +41,7 @@ class TopLevel < Dry::Struct
3941
4042 def to_dynamic
4143 {
44+ "escaped" => escaped,
4245 "pattern1" => pattern1,
4346 "pattern2" => pattern2,
4447 "union" => union,
Mschema-rustdefault / module_under_test.rs+2 −0
@@ -15,6 +15,8 @@ use serde::{Serialize, Deserialize};
1515
1616 #[derive(Debug, Clone, Serialize, Deserialize)]
1717 pub struct TopLevel {
18+ pub escaped: String,
19+
1820 pub pattern1: String,
1921
2022 pub pattern2: String,
Mschema-scala3-upickledefault / TopLevel.scala+1 −0
@@ -66,6 +66,7 @@ end JsonExt
6666
6767
6868 case class TopLevel (
69+ val escaped : String,
6970 val pattern1 : String,
7071 val pattern2 : String,
7172 val union : String
Mschema-scala3default / TopLevel.scala+1 −0
@@ -8,6 +8,7 @@ import cats.syntax.functor._
88 type NullValue = None.type
99
1010 case class TopLevel (
11+ val escaped : String,
1112 val pattern1 : String,
1213 val pattern2 : String,
1314 val union : String
Mschema-schemadefault / TopLevel.schema+5 −0
@@ -6,6 +6,10 @@
66 "type": "object",
77 "additionalProperties": {},
88 "properties": {
9+ "escaped": {
10+ "type": "string",
11+ "pattern": "^\\d+\\.[a-z]+$"
12+ },
913 "pattern1": {
1014 "type": "string",
1115 "pattern": "a[.]*"
@@ -20,6 +24,7 @@
2024 }
2125 },
2226 "required": [
27+ "escaped",
2328 "pattern1",
2429 "pattern2",
2530 "union"
Mschema-swiftdefault / quicktype.swift+4 −0
@@ -7,11 +7,13 @@ import Foundation
77
88 // MARK: - TopLevel
99 struct TopLevel: Codable {
10+ let escaped: String
1011 let pattern1: String
1112 let pattern2: String
1213 let union: String
1314
1415 enum CodingKeys: String, CodingKey {
16+ case escaped = "escaped"
1517 case pattern1 = "pattern1"
1618 case pattern2 = "pattern2"
1719 case union = "union"
@@ -37,11 +39,13 @@ extension TopLevel {
3739 }
3840
3941 func with(
42+ escaped: String? = nil,
4043 pattern1: String? = nil,
4144 pattern2: String? = nil,
4245 union: String? = nil
4346 ) -> TopLevel {
4447 return TopLevel(
48+ escaped: escaped ?? self.escaped,
4549 pattern1: pattern1 ?? self.pattern1,
4650 pattern2: pattern2 ?? self.pattern2,
4751 union: union ?? self.union
Mschema-typescript-zoddefault / TopLevel.ts+4 −3
@@ -2,8 +2,9 @@ import * as z from "zod";
22
33
44 export const TopLevelSchema = z.object({
5- "pattern1": z.string(),
6- "pattern2": z.string(),
7- "union": z.string(),
5+ "escaped": z.string().regex(new RegExp("^\\d+\\.[a-z]+$")),
6+ "pattern1": z.string().regex(new RegExp("a[.]*")),
7+ "pattern2": z.string().regex(new RegExp("b[.]*")),
8+ "union": z.string().regex(new RegExp("(b[.]*)|(c[.]*)")),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Mschema-typescriptdefault / TopLevel.ts+2 −0
@@ -8,6 +8,7 @@
88 // match the expected interface, even if the JSON is valid.
99
1010 export interface TopLevel {
11+ escaped: string;
1112 pattern1: string;
1213 pattern2: string;
1314 union: string;
@@ -181,6 +182,7 @@ function r(name: string) {
181182
182183 const typeMap: any = {
183184 "TopLevel": o([
185+ { json: "escaped", js: "escaped", typ: "" },
184186 { json: "pattern1", js: "pattern1", typ: "" },
185187 { json: "pattern2", js: "pattern2", typ: "" },
186188 { json: "union", js: "union", typ: "" },
Test case

test/inputs/schema/renaming-bug.schema

1 generated file · +3 −3
Mschema-typescript-zoddefault / TopLevel.ts+3 −3
@@ -78,7 +78,7 @@ export type Geometry = z.infer<typeof GeometrySchema>;
7878
7979 export const VehicleSchema = z.object({
8080 "brand": z.string().optional(),
81- "id": z.string().optional(),
81+ "id": z.string().min(1).optional(),
8282 "speed": SpeedSchema.optional(),
8383 "subModule": z.boolean().optional(),
8484 "type": VehicleTypeSchema.optional(),
@@ -94,7 +94,7 @@ export type Shape = z.infer<typeof ShapeSchema>;
9494
9595 export const BerrySchema = z.object({
9696 "color": ColorSchema.optional(),
97- "name": z.string().optional(),
97+ "name": z.string().min(1).optional(),
9898 "shapes": z.array(ShapeSchema).optional(),
9999 });
100100 export type Berry = z.infer<typeof BerrySchema>;
@@ -107,7 +107,7 @@ export const FruitSchema = z.object({
107107 export type Fruit = z.infer<typeof FruitSchema>;
108108
109109 export const TopLevelSchema = z.object({
110- "version": z.string().optional(),
110+ "version": z.string().regex(new RegExp("^\\d{1,5}.{1}\\d{1,5}.{1}\\d{1,5}$")).optional(),
111111 "fruits": z.array(FruitSchema).optional(),
112112 "vehicles": z.array(VehicleSchema).optional(),
113113 });
Test case

test/inputs/schema/schema-constraints.schema

1 generated file · +1 −1
Mschema-typescript-zoddefault / TopLevel.ts+1 −1
@@ -2,7 +2,7 @@ import * as z from "zod";
22
33
44 export const TopLevelSchema = z.object({
5- "minMaxLength": z.string(),
5+ "minMaxLength": z.string().min(5).max(5),
66 "percent": z.number(),
77 });
88 export type TopLevel = z.infer<typeof TopLevelSchema>;
No generated files match these filters.