Test case
27 generated files · +394 −84test/inputs/schema/minmaxlength.schema
Mschema-cplusplusdefault / quicktype.hpp+12 −3
| @@ -224,16 +224,19 @@ namespace quicktype { | ||
| 224 | 224 | class TopLevel { |
| 225 | 225 | public: |
| 226 | 226 | 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]+$")), | |
| 228 | 229 | maxlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, 5, std::nullopt), |
| 229 | 230 | minlength_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, 3, std::nullopt, std::nullopt), |
| 230 | 231 | 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]+$")) | |
| 233 | 234 | {} |
| 234 | 235 | virtual ~TopLevel() = default; |
| 235 | 236 | |
| 236 | 237 | private: |
| 238 | + std::string empty_only; | |
| 239 | + ClassMemberConstraints empty_only_constraint; | |
| 237 | 240 | std::string intersection; |
| 238 | 241 | ClassMemberConstraints intersection_constraint; |
| 239 | 242 | InUnion in_union; |
| @@ -250,6 +253,10 @@ namespace quicktype { | ||
| 250 | 253 | ClassMemberConstraints union_constraint; |
| 251 | 254 | |
| 252 | 255 | 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 | + | |
| 253 | 260 | const std::string & get_intersection() const { return intersection; } |
| 254 | 261 | std::string & get_mutable_intersection() { return intersection; } |
| 255 | 262 | 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>> { | ||
| 297 | 304 | } |
| 298 | 305 | namespace quicktype { |
| 299 | 306 | inline void from_json(const json & j, TopLevel& x) { |
| 307 | + x.set_empty_only(j.at("emptyOnly").get<std::string>()); | |
| 300 | 308 | x.set_intersection(j.at("intersection").get<std::string>()); |
| 301 | 309 | x.set_in_union(j.at("inUnion").get<InUnion>()); |
| 302 | 310 | x.set_maxlength(j.at("maxlength").get<std::string>()); |
| @@ -309,6 +317,7 @@ namespace quicktype { | ||
| 309 | 317 | |
| 310 | 318 | inline void to_json(json & j, const TopLevel & x) { |
| 311 | 319 | j = json::object(); |
| 320 | + j["emptyOnly"] = x.get_empty_only(); | |
| 312 | 321 | j["intersection"] = x.get_intersection(); |
| 313 | 322 | j["inUnion"] = x.get_in_union(); |
| 314 | 323 | j["maxlength"] = x.get_maxlength(); |
Mschema-csharp-recordsdefault / QuickType.cs+76 −16
| @@ -25,34 +25,38 @@ namespace QuickType | ||
| 25 | 25 | |
| 26 | 26 | public partial record TopLevel |
| 27 | 27 | { |
| 28 | + [JsonProperty("emptyOnly", Required = Required.Always)] | |
| 29 | + [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 30 | + public string EmptyOnly { get; set; } | |
| 31 | + | |
| 28 | 32 | [JsonProperty("intersection", Required = Required.Always)] |
| 29 | - [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 33 | + [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 30 | 34 | public string Intersection { get; set; } |
| 31 | 35 | |
| 32 | 36 | [JsonProperty("inUnion", Required = Required.Always)] |
| 33 | 37 | public InUnion InUnion { get; set; } |
| 34 | 38 | |
| 35 | 39 | [JsonProperty("maxlength", Required = Required.Always)] |
| 36 | - [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 40 | + [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 37 | 41 | public string Maxlength { get; set; } |
| 38 | 42 | |
| 39 | 43 | [JsonProperty("minlength", Required = Required.Always)] |
| 40 | - [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 44 | + [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))] | |
| 41 | 45 | public string Minlength { get; set; } |
| 42 | 46 | |
| 43 | 47 | [JsonProperty("minMaxIntersection", Required = Required.Always)] |
| 44 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 48 | + [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 45 | 49 | public string MinMaxIntersection { get; set; } |
| 46 | 50 | |
| 47 | 51 | [JsonProperty("minmaxlength", Required = Required.Always)] |
| 48 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 52 | + [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 49 | 53 | public string Minmaxlength { get; set; } |
| 50 | 54 | |
| 51 | 55 | [JsonProperty("minMaxUnion", Required = Required.Always)] |
| 52 | 56 | public string MinMaxUnion { get; set; } |
| 53 | 57 | |
| 54 | 58 | [JsonProperty("union", Required = Required.Always)] |
| 55 | - [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 59 | + [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))] | |
| 56 | 60 | public string Union { get; set; } |
| 57 | 61 | } |
| 58 | 62 | |
| @@ -89,6 +93,34 @@ namespace QuickType | ||
| 89 | 93 | }; |
| 90 | 94 | } |
| 91 | 95 | |
| 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 | + | |
| 92 | 124 | internal class InUnionConverter : JsonConverter |
| 93 | 125 | { |
| 94 | 126 | public override bool CanConvert(Type t) => t == typeof(InUnion) || t == typeof(InUnion?); |
| @@ -135,7 +167,7 @@ namespace QuickType | ||
| 135 | 167 | public static readonly InUnionConverter Singleton = new InUnionConverter(); |
| 136 | 168 | } |
| 137 | 169 | |
| 138 | - internal class PurpleMinMaxLengthCheckConverter : JsonConverter | |
| 170 | + internal class FluffyMinMaxLengthCheckConverter : JsonConverter | |
| 139 | 171 | { |
| 140 | 172 | public override bool CanConvert(Type t) => t == typeof(string); |
| 141 | 173 | |
| @@ -160,10 +192,10 @@ namespace QuickType | ||
| 160 | 192 | throw new Exception("Cannot marshal type string"); |
| 161 | 193 | } |
| 162 | 194 | |
| 163 | - public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter(); | |
| 195 | + public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 164 | 196 | } |
| 165 | 197 | |
| 166 | - internal class FluffyMinMaxLengthCheckConverter : JsonConverter | |
| 198 | + internal class TentacledMinMaxLengthCheckConverter : JsonConverter | |
| 167 | 199 | { |
| 168 | 200 | public override bool CanConvert(Type t) => t == typeof(string); |
| 169 | 201 | |
| @@ -188,10 +220,10 @@ namespace QuickType | ||
| 188 | 220 | throw new Exception("Cannot marshal type string"); |
| 189 | 221 | } |
| 190 | 222 | |
| 191 | - public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 223 | + public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 192 | 224 | } |
| 193 | 225 | |
| 194 | - internal class TentacledMinMaxLengthCheckConverter : JsonConverter | |
| 226 | + internal class StickyMinMaxLengthCheckConverter : JsonConverter | |
| 195 | 227 | { |
| 196 | 228 | public override bool CanConvert(Type t) => t == typeof(string); |
| 197 | 229 | |
| @@ -216,10 +248,38 @@ namespace QuickType | ||
| 216 | 248 | throw new Exception("Cannot marshal type string"); |
| 217 | 249 | } |
| 218 | 250 | |
| 219 | - public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 251 | + public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 220 | 252 | } |
| 221 | 253 | |
| 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 | |
| 223 | 283 | { |
| 224 | 284 | public override bool CanConvert(Type t) => t == typeof(string); |
| 225 | 285 | |
| @@ -244,10 +304,10 @@ namespace QuickType | ||
| 244 | 304 | throw new Exception("Cannot marshal type string"); |
| 245 | 305 | } |
| 246 | 306 | |
| 247 | - public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 307 | + public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter(); | |
| 248 | 308 | } |
| 249 | 309 | |
| 250 | - internal class IndigoMinMaxLengthCheckConverter : JsonConverter | |
| 310 | + internal class HilariousMinMaxLengthCheckConverter : JsonConverter | |
| 251 | 311 | { |
| 252 | 312 | public override bool CanConvert(Type t) => t == typeof(string); |
| 253 | 313 | |
| @@ -272,7 +332,7 @@ namespace QuickType | ||
| 272 | 332 | throw new Exception("Cannot marshal type string"); |
| 273 | 333 | } |
| 274 | 334 | |
| 275 | - public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter(); | |
| 335 | + public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter(); | |
| 276 | 336 | } |
| 277 | 337 | } |
| 278 | 338 | #pragma warning restore CS8618 |
Mschema-csharp-SystemTextJsondefault / QuickType.cs+75 −16
| @@ -22,9 +22,14 @@ namespace QuickType | ||
| 22 | 22 | |
| 23 | 23 | public partial class TopLevel |
| 24 | 24 | { |
| 25 | + [JsonRequired] | |
| 26 | + [JsonPropertyName("emptyOnly")] | |
| 27 | + [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 28 | + public string EmptyOnly { get; set; } | |
| 29 | + | |
| 25 | 30 | [JsonRequired] |
| 26 | 31 | [JsonPropertyName("intersection")] |
| 27 | - [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 32 | + [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 28 | 33 | public string Intersection { get; set; } |
| 29 | 34 | |
| 30 | 35 | [JsonRequired] |
| @@ -33,22 +38,22 @@ namespace QuickType | ||
| 33 | 38 | |
| 34 | 39 | [JsonRequired] |
| 35 | 40 | [JsonPropertyName("maxlength")] |
| 36 | - [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 41 | + [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 37 | 42 | public string Maxlength { get; set; } |
| 38 | 43 | |
| 39 | 44 | [JsonRequired] |
| 40 | 45 | [JsonPropertyName("minlength")] |
| 41 | - [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 46 | + [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))] | |
| 42 | 47 | public string Minlength { get; set; } |
| 43 | 48 | |
| 44 | 49 | [JsonRequired] |
| 45 | 50 | [JsonPropertyName("minMaxIntersection")] |
| 46 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 51 | + [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 47 | 52 | public string MinMaxIntersection { get; set; } |
| 48 | 53 | |
| 49 | 54 | [JsonRequired] |
| 50 | 55 | [JsonPropertyName("minmaxlength")] |
| 51 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 56 | + [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 52 | 57 | public string Minmaxlength { get; set; } |
| 53 | 58 | |
| 54 | 59 | [JsonRequired] |
| @@ -57,7 +62,7 @@ namespace QuickType | ||
| 57 | 62 | |
| 58 | 63 | [JsonRequired] |
| 59 | 64 | [JsonPropertyName("union")] |
| 60 | - [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 65 | + [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))] | |
| 61 | 66 | public string Union { get; set; } |
| 62 | 67 | } |
| 63 | 68 | |
| @@ -94,6 +99,33 @@ namespace QuickType | ||
| 94 | 99 | }; |
| 95 | 100 | } |
| 96 | 101 | |
| 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 | + | |
| 97 | 129 | internal class InUnionConverter : JsonConverter<InUnion> |
| 98 | 130 | { |
| 99 | 131 | public override bool CanConvert(Type t) => t == typeof(InUnion); |
| @@ -137,7 +169,7 @@ namespace QuickType | ||
| 137 | 169 | public static readonly InUnionConverter Singleton = new InUnionConverter(); |
| 138 | 170 | } |
| 139 | 171 | |
| 140 | - internal class PurpleMinMaxLengthCheckConverter : JsonConverter<string> | |
| 172 | + internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string> | |
| 141 | 173 | { |
| 142 | 174 | public override bool CanConvert(Type t) => t == typeof(string); |
| 143 | 175 | |
| @@ -161,10 +193,10 @@ namespace QuickType | ||
| 161 | 193 | throw new NotSupportedException("Cannot marshal type string"); |
| 162 | 194 | } |
| 163 | 195 | |
| 164 | - public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter(); | |
| 196 | + public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 165 | 197 | } |
| 166 | 198 | |
| 167 | - internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string> | |
| 199 | + internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string> | |
| 168 | 200 | { |
| 169 | 201 | public override bool CanConvert(Type t) => t == typeof(string); |
| 170 | 202 | |
| @@ -188,10 +220,10 @@ namespace QuickType | ||
| 188 | 220 | throw new NotSupportedException("Cannot marshal type string"); |
| 189 | 221 | } |
| 190 | 222 | |
| 191 | - public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 223 | + public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 192 | 224 | } |
| 193 | 225 | |
| 194 | - internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string> | |
| 226 | + internal class StickyMinMaxLengthCheckConverter : JsonConverter<string> | |
| 195 | 227 | { |
| 196 | 228 | public override bool CanConvert(Type t) => t == typeof(string); |
| 197 | 229 | |
| @@ -215,10 +247,37 @@ namespace QuickType | ||
| 215 | 247 | throw new NotSupportedException("Cannot marshal type string"); |
| 216 | 248 | } |
| 217 | 249 | |
| 218 | - public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 250 | + public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 219 | 251 | } |
| 220 | 252 | |
| 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> | |
| 222 | 281 | { |
| 223 | 282 | public override bool CanConvert(Type t) => t == typeof(string); |
| 224 | 283 | |
| @@ -242,10 +301,10 @@ namespace QuickType | ||
| 242 | 301 | throw new NotSupportedException("Cannot marshal type string"); |
| 243 | 302 | } |
| 244 | 303 | |
| 245 | - public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 304 | + public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter(); | |
| 246 | 305 | } |
| 247 | 306 | |
| 248 | - internal class IndigoMinMaxLengthCheckConverter : JsonConverter<string> | |
| 307 | + internal class HilariousMinMaxLengthCheckConverter : JsonConverter<string> | |
| 249 | 308 | { |
| 250 | 309 | public override bool CanConvert(Type t) => t == typeof(string); |
| 251 | 310 | |
| @@ -269,7 +328,7 @@ namespace QuickType | ||
| 269 | 328 | throw new NotSupportedException("Cannot marshal type string"); |
| 270 | 329 | } |
| 271 | 330 | |
| 272 | - public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter(); | |
| 331 | + public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter(); | |
| 273 | 332 | } |
| 274 | 333 | |
| 275 | 334 | public class DateOnlyConverter : JsonConverter<DateOnly> |
Mschema-csharpdefault / QuickType.cs+76 −16
| @@ -25,34 +25,38 @@ namespace QuickType | ||
| 25 | 25 | |
| 26 | 26 | public partial class TopLevel |
| 27 | 27 | { |
| 28 | + [JsonProperty("emptyOnly", Required = Required.Always)] | |
| 29 | + [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 30 | + public string EmptyOnly { get; set; } | |
| 31 | + | |
| 28 | 32 | [JsonProperty("intersection", Required = Required.Always)] |
| 29 | - [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 33 | + [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 30 | 34 | public string Intersection { get; set; } |
| 31 | 35 | |
| 32 | 36 | [JsonProperty("inUnion", Required = Required.Always)] |
| 33 | 37 | public InUnion InUnion { get; set; } |
| 34 | 38 | |
| 35 | 39 | [JsonProperty("maxlength", Required = Required.Always)] |
| 36 | - [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 40 | + [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 37 | 41 | public string Maxlength { get; set; } |
| 38 | 42 | |
| 39 | 43 | [JsonProperty("minlength", Required = Required.Always)] |
| 40 | - [JsonConverter(typeof(StickyMinMaxLengthCheckConverter))] | |
| 44 | + [JsonConverter(typeof(IndecentMinMaxLengthCheckConverter))] | |
| 41 | 45 | public string Minlength { get; set; } |
| 42 | 46 | |
| 43 | 47 | [JsonProperty("minMaxIntersection", Required = Required.Always)] |
| 44 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 48 | + [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 45 | 49 | public string MinMaxIntersection { get; set; } |
| 46 | 50 | |
| 47 | 51 | [JsonProperty("minmaxlength", Required = Required.Always)] |
| 48 | - [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 52 | + [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 49 | 53 | public string Minmaxlength { get; set; } |
| 50 | 54 | |
| 51 | 55 | [JsonProperty("minMaxUnion", Required = Required.Always)] |
| 52 | 56 | public string MinMaxUnion { get; set; } |
| 53 | 57 | |
| 54 | 58 | [JsonProperty("union", Required = Required.Always)] |
| 55 | - [JsonConverter(typeof(IndigoMinMaxLengthCheckConverter))] | |
| 59 | + [JsonConverter(typeof(HilariousMinMaxLengthCheckConverter))] | |
| 56 | 60 | public string Union { get; set; } |
| 57 | 61 | } |
| 58 | 62 | |
| @@ -89,6 +93,34 @@ namespace QuickType | ||
| 89 | 93 | }; |
| 90 | 94 | } |
| 91 | 95 | |
| 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 | + | |
| 92 | 124 | internal class InUnionConverter : JsonConverter |
| 93 | 125 | { |
| 94 | 126 | public override bool CanConvert(Type t) => t == typeof(InUnion) || t == typeof(InUnion?); |
| @@ -135,7 +167,7 @@ namespace QuickType | ||
| 135 | 167 | public static readonly InUnionConverter Singleton = new InUnionConverter(); |
| 136 | 168 | } |
| 137 | 169 | |
| 138 | - internal class PurpleMinMaxLengthCheckConverter : JsonConverter | |
| 170 | + internal class FluffyMinMaxLengthCheckConverter : JsonConverter | |
| 139 | 171 | { |
| 140 | 172 | public override bool CanConvert(Type t) => t == typeof(string); |
| 141 | 173 | |
| @@ -160,10 +192,10 @@ namespace QuickType | ||
| 160 | 192 | throw new Exception("Cannot marshal type string"); |
| 161 | 193 | } |
| 162 | 194 | |
| 163 | - public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter(); | |
| 195 | + public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 164 | 196 | } |
| 165 | 197 | |
| 166 | - internal class FluffyMinMaxLengthCheckConverter : JsonConverter | |
| 198 | + internal class TentacledMinMaxLengthCheckConverter : JsonConverter | |
| 167 | 199 | { |
| 168 | 200 | public override bool CanConvert(Type t) => t == typeof(string); |
| 169 | 201 | |
| @@ -188,10 +220,10 @@ namespace QuickType | ||
| 188 | 220 | throw new Exception("Cannot marshal type string"); |
| 189 | 221 | } |
| 190 | 222 | |
| 191 | - public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 223 | + public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 192 | 224 | } |
| 193 | 225 | |
| 194 | - internal class TentacledMinMaxLengthCheckConverter : JsonConverter | |
| 226 | + internal class StickyMinMaxLengthCheckConverter : JsonConverter | |
| 195 | 227 | { |
| 196 | 228 | public override bool CanConvert(Type t) => t == typeof(string); |
| 197 | 229 | |
| @@ -216,10 +248,38 @@ namespace QuickType | ||
| 216 | 248 | throw new Exception("Cannot marshal type string"); |
| 217 | 249 | } |
| 218 | 250 | |
| 219 | - public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 251 | + public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 220 | 252 | } |
| 221 | 253 | |
| 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 | |
| 223 | 283 | { |
| 224 | 284 | public override bool CanConvert(Type t) => t == typeof(string); |
| 225 | 285 | |
| @@ -244,10 +304,10 @@ namespace QuickType | ||
| 244 | 304 | throw new Exception("Cannot marshal type string"); |
| 245 | 305 | } |
| 246 | 306 | |
| 247 | - public static readonly StickyMinMaxLengthCheckConverter Singleton = new StickyMinMaxLengthCheckConverter(); | |
| 307 | + public static readonly IndecentMinMaxLengthCheckConverter Singleton = new IndecentMinMaxLengthCheckConverter(); | |
| 248 | 308 | } |
| 249 | 309 | |
| 250 | - internal class IndigoMinMaxLengthCheckConverter : JsonConverter | |
| 310 | + internal class HilariousMinMaxLengthCheckConverter : JsonConverter | |
| 251 | 311 | { |
| 252 | 312 | public override bool CanConvert(Type t) => t == typeof(string); |
| 253 | 313 | |
| @@ -272,7 +332,7 @@ namespace QuickType | ||
| 272 | 332 | throw new Exception("Cannot marshal type string"); |
| 273 | 333 | } |
| 274 | 334 | |
| 275 | - public static readonly IndigoMinMaxLengthCheckConverter Singleton = new IndigoMinMaxLengthCheckConverter(); | |
| 335 | + public static readonly HilariousMinMaxLengthCheckConverter Singleton = new HilariousMinMaxLengthCheckConverter(); | |
| 276 | 336 | } |
| 277 | 337 | } |
| 278 | 338 | #pragma warning restore CS8618 |
Mschema-dartdefault / TopLevel.dart+4 −0
| @@ -9,6 +9,7 @@ TopLevel topLevelFromJson(String str) => TopLevel.fromJson(json.decode(str)); | ||
| 9 | 9 | String topLevelToJson(TopLevel data) => json.encode(data.toJson()); |
| 10 | 10 | |
| 11 | 11 | class TopLevel { |
| 12 | + final String emptyOnly; | |
| 12 | 13 | final String intersection; |
| 13 | 14 | final dynamic inUnion; |
| 14 | 15 | final String maxlength; |
| @@ -19,6 +20,7 @@ class TopLevel { | ||
| 19 | 20 | final String union; |
| 20 | 21 | |
| 21 | 22 | TopLevel({ |
| 23 | + required this.emptyOnly, | |
| 22 | 24 | required this.intersection, |
| 23 | 25 | required this.inUnion, |
| 24 | 26 | required this.maxlength, |
| @@ -30,6 +32,7 @@ class TopLevel { | ||
| 30 | 32 | }); |
| 31 | 33 | |
| 32 | 34 | factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel( |
| 35 | + emptyOnly: json["emptyOnly"], | |
| 33 | 36 | intersection: json["intersection"], |
| 34 | 37 | inUnion: json["inUnion"], |
| 35 | 38 | maxlength: json["maxlength"], |
| @@ -41,6 +44,7 @@ class TopLevel { | ||
| 41 | 44 | ); |
| 42 | 45 | |
| 43 | 46 | Map<String, dynamic> toJson() => { |
| 47 | + "emptyOnly": emptyOnly, | |
| 44 | 48 | "intersection": intersection, |
| 45 | 49 | "inUnion": inUnion, |
| 46 | 50 | "maxlength": maxlength, |
Mschema-elixirdefault / QuickType.ex+5 −2
| @@ -6,10 +6,11 @@ | ||
| 6 | 6 | # Encode into a JSON string: TopLevel.to_json(struct) |
| 7 | 7 | |
| 8 | 8 | 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] | |
| 11 | 11 | |
| 12 | 12 | @type t :: %__MODULE__{ |
| 13 | + empty_only: String.t(), | |
| 13 | 14 | intersection: String.t(), |
| 14 | 15 | in_union: float() | String.t(), |
| 15 | 16 | maxlength: String.t(), |
| @@ -22,6 +23,7 @@ defmodule TopLevel do | ||
| 22 | 23 | |
| 23 | 24 | def from_map(m) do |
| 24 | 25 | %TopLevel{ |
| 26 | + empty_only: m["emptyOnly"], | |
| 25 | 27 | intersection: m["intersection"], |
| 26 | 28 | in_union: m["inUnion"], |
| 27 | 29 | maxlength: m["maxlength"], |
| @@ -41,6 +43,7 @@ defmodule TopLevel do | ||
| 41 | 43 | |
| 42 | 44 | def to_map(struct) do |
| 43 | 45 | %{ |
| 46 | + "emptyOnly" => struct.empty_only, | |
| 44 | 47 | "intersection" => struct.intersection, |
| 45 | 48 | "inUnion" => struct.in_union, |
| 46 | 49 | "maxlength" => struct.maxlength, |
Mschema-elmdefault / QuickType.elm+5 −2
| @@ -24,7 +24,8 @@ import Json.Encode as Jenc | ||
| 24 | 24 | import Dict exposing (Dict) |
| 25 | 25 | |
| 26 | 26 | type alias QuickType = |
| 27 | - { intersection : String | |
| 27 | + { emptyOnly : String | |
| 28 | + , intersection : String | |
| 28 | 29 | , inUnion : InUnion |
| 29 | 30 | , maxlength : String |
| 30 | 31 | , minlength : String |
| @@ -46,6 +47,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r) | ||
| 46 | 47 | quickType : Jdec.Decoder QuickType |
| 47 | 48 | quickType = |
| 48 | 49 | Jdec.succeed QuickType |
| 50 | + |> Jpipe.required "emptyOnly" Jdec.string | |
| 49 | 51 | |> Jpipe.required "intersection" Jdec.string |
| 50 | 52 | |> Jpipe.required "inUnion" inUnion |
| 51 | 53 | |> Jpipe.required "maxlength" Jdec.string |
| @@ -58,7 +60,8 @@ quickType = | ||
| 58 | 60 | encodeQuickType : QuickType -> Jenc.Value |
| 59 | 61 | encodeQuickType x = |
| 60 | 62 | Jenc.object |
| 61 | - [ ("intersection", Jenc.string x.intersection) | |
| 63 | + [ ("emptyOnly", Jenc.string x.emptyOnly) | |
| 64 | + , ("intersection", Jenc.string x.intersection) | |
| 62 | 65 | , ("inUnion", encodeInUnion x.inUnion) |
| 63 | 66 | , ("maxlength", Jenc.string x.maxlength) |
| 64 | 67 | , ("minlength", Jenc.string x.minlength) |
Mschema-flowdefault / TopLevel.js+2 −0
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | + emptyOnly: string; | |
| 13 | 14 | intersection: string; |
| 14 | 15 | inUnion: InUnion; |
| 15 | 16 | maxlength: string; |
| @@ -188,6 +189,7 @@ function r(name: string) { | ||
| 188 | 189 | |
| 189 | 190 | const typeMap: any = { |
| 190 | 191 | "TopLevel": o([ |
| 192 | + { json: "emptyOnly", js: "emptyOnly", typ: "" }, | |
| 191 | 193 | { json: "intersection", js: "intersection", typ: "" }, |
| 192 | 194 | { json: "inUnion", js: "inUnion", typ: u(3.14, "") }, |
| 193 | 195 | { json: "maxlength", js: "maxlength", typ: "" }, |
Mschema-golangdefault / quicktype.go+1 −0
| @@ -22,6 +22,7 @@ func (r *TopLevel) Marshal() ([]byte, error) { | ||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | type TopLevel struct { |
| 25 | + EmptyOnly string `json:"emptyOnly"` | |
| 25 | 26 | Intersection string `json:"intersection"` |
| 26 | 27 | InUnion *InUnion `json:"inUnion"` |
| 27 | 28 | Maxlength string `json:"maxlength"` |
Mschema-haskelldefault / QuickType.hs+7 −4
| @@ -14,7 +14,8 @@ import Data.HashMap.Strict (HashMap) | ||
| 14 | 14 | import Data.Text (Text) |
| 15 | 15 | |
| 16 | 16 | data QuickType = QuickType |
| 17 | - { intersectionQuickType :: Text | |
| 17 | + { emptyOnlyQuickType :: Text | |
| 18 | + , intersectionQuickType :: Text | |
| 18 | 19 | , inUnionQuickType :: InUnion |
| 19 | 20 | , maxlengthQuickType :: Text |
| 20 | 21 | , minlengthQuickType :: Text |
| @@ -33,9 +34,10 @@ decodeTopLevel :: ByteString -> Maybe QuickType | ||
| 33 | 34 | decodeTopLevel = decode |
| 34 | 35 | |
| 35 | 36 | 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) = | |
| 37 | 38 | object |
| 38 | - [ "intersection" .= intersectionQuickType | |
| 39 | + [ "emptyOnly" .= emptyOnlyQuickType | |
| 40 | + , "intersection" .= intersectionQuickType | |
| 39 | 41 | , "inUnion" .= inUnionQuickType |
| 40 | 42 | , "maxlength" .= maxlengthQuickType |
| 41 | 43 | , "minlength" .= minlengthQuickType |
| @@ -47,7 +49,8 @@ instance ToJSON QuickType where | ||
| 47 | 49 | |
| 48 | 50 | instance FromJSON QuickType where |
| 49 | 51 | parseJSON (Object v) = QuickType |
| 50 | - <$> v .: "intersection" | |
| 52 | + <$> v .: "emptyOnly" | |
| 53 | + <*> v .: "intersection" | |
| 51 | 54 | <*> v .: "inUnion" |
| 52 | 55 | <*> v .: "maxlength" |
| 53 | 56 | <*> v .: "minlength" |
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,6 +3,7 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String emptyOnly; | |
| 6 | 7 | private String intersection; |
| 7 | 8 | private InUnion inUnion; |
| 8 | 9 | private String maxlength; |
| @@ -12,6 +13,11 @@ public class TopLevel { | ||
| 12 | 13 | private String minMaxUnion; |
| 13 | 14 | private String union; |
| 14 | 15 | |
| 16 | + @JsonProperty("emptyOnly") | |
| 17 | + public String getEmptyOnly() { return emptyOnly; } | |
| 18 | + @JsonProperty("emptyOnly") | |
| 19 | + public void setEmptyOnly(String value) { this.emptyOnly = value; } | |
| 20 | + | |
| 15 | 21 | @JsonProperty("intersection") |
| 16 | 22 | public String getIntersection() { return intersection; } |
| 17 | 23 | @JsonProperty("intersection") |
Mschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,6 +3,7 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String emptyOnly; | |
| 6 | 7 | private String intersection; |
| 7 | 8 | private InUnion inUnion; |
| 8 | 9 | private String maxlength; |
| @@ -12,6 +13,11 @@ public class TopLevel { | ||
| 12 | 13 | private String minMaxUnion; |
| 13 | 14 | private String union; |
| 14 | 15 | |
| 16 | + @JsonProperty("emptyOnly") | |
| 17 | + public String getEmptyOnly() { return emptyOnly; } | |
| 18 | + @JsonProperty("emptyOnly") | |
| 19 | + public void setEmptyOnly(String value) { this.emptyOnly = value; } | |
| 20 | + | |
| 15 | 21 | @JsonProperty("intersection") |
| 16 | 22 | public String getIntersection() { return intersection; } |
| 17 | 23 | @JsonProperty("intersection") |
Mschema-javadefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,6 +3,7 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String emptyOnly; | |
| 6 | 7 | private String intersection; |
| 7 | 8 | private InUnion inUnion; |
| 8 | 9 | private String maxlength; |
| @@ -12,6 +13,11 @@ public class TopLevel { | ||
| 12 | 13 | private String minMaxUnion; |
| 13 | 14 | private String union; |
| 14 | 15 | |
| 16 | + @JsonProperty("emptyOnly") | |
| 17 | + public String getEmptyOnly() { return emptyOnly; } | |
| 18 | + @JsonProperty("emptyOnly") | |
| 19 | + public void setEmptyOnly(String value) { this.emptyOnly = value; } | |
| 20 | + | |
| 15 | 21 | @JsonProperty("intersection") |
| 16 | 22 | public String getIntersection() { return intersection; } |
| 17 | 23 | @JsonProperty("intersection") |
Mschema-javascriptdefault / TopLevel.js+1 −0
| @@ -172,6 +172,7 @@ function r(name) { | ||
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | 174 | "TopLevel": o([ |
| 175 | + { json: "emptyOnly", js: "emptyOnly", typ: "" }, | |
| 175 | 176 | { json: "intersection", js: "intersection", typ: "" }, |
| 176 | 177 | { json: "inUnion", js: "inUnion", typ: u(3.14, "") }, |
| 177 | 178 | { json: "maxlength", js: "maxlength", typ: "" }, |
Mschema-kotlin-jacksondefault / TopLevel.kt+3 −0
| @@ -31,6 +31,9 @@ val mapper = jacksonObjectMapper().apply { | ||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | data class TopLevel ( |
| 34 | + @get:JsonProperty(required=true)@field:JsonProperty(required=true) | |
| 35 | + val emptyOnly: String, | |
| 36 | + | |
| 34 | 37 | @get:JsonProperty(required=true)@field:JsonProperty(required=true) |
| 35 | 38 | val intersection: String, |
Mschema-kotlindefault / TopLevel.kt+1 −0
| @@ -18,6 +18,7 @@ private val klaxon = Klaxon() | ||
| 18 | 18 | .convert(InUnion::class, { InUnion.fromJson(it) }, { it.toJson() }, true) |
| 19 | 19 | |
| 20 | 20 | data class TopLevel ( |
| 21 | + val emptyOnly: String, | |
| 21 | 22 | val intersection: String, |
| 22 | 23 | val inUnion: InUnion, |
| 23 | 24 | val maxlength: String, |
Mschema-phpdefault / TopLevel.php+66 −12
| @@ -4,6 +4,7 @@ declare(strict_types=1); | ||
| 4 | 4 | // This is an autogenerated file:TopLevel |
| 5 | 5 | |
| 6 | 6 | class TopLevel { |
| 7 | + private string $emptyOnly; // json:emptyOnly Required | |
| 7 | 8 | private string $intersection; // json:intersection Required |
| 8 | 9 | private float|string $inUnion; // json:inUnion Required |
| 9 | 10 | private string $maxlength; // json:maxlength Required |
| @@ -14,6 +15,7 @@ class TopLevel { | ||
| 14 | 15 | private string $union; // json:union Required |
| 15 | 16 | |
| 16 | 17 | /** |
| 18 | + * @param string $emptyOnly | |
| 17 | 19 | * @param string $intersection |
| 18 | 20 | * @param float|string $inUnion |
| 19 | 21 | * @param string $maxlength |
| @@ -23,7 +25,8 @@ class TopLevel { | ||
| 23 | 25 | * @param string $minMaxUnion |
| 24 | 26 | * @param string $union |
| 25 | 27 | */ |
| 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; | |
| 27 | 30 | $this->intersection = $intersection; |
| 28 | 31 | $this->inUnion = $inUnion; |
| 29 | 32 | $this->maxlength = $maxlength; |
| @@ -34,6 +37,53 @@ class TopLevel { | ||
| 34 | 37 | $this->union = $union; |
| 35 | 38 | } |
| 36 | 39 | |
| 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 | + | |
| 37 | 87 | /** |
| 38 | 88 | * @param string $value |
| 39 | 89 | * @throws Exception |
| @@ -78,7 +128,7 @@ class TopLevel { | ||
| 78 | 128 | * @return string |
| 79 | 129 | */ |
| 80 | 130 | public static function sampleIntersection(): string { |
| 81 | - return 'TopLevel::intersection::31'; /*31:intersection*/ | |
| 131 | + return 'TopLevel::intersection::32'; /*32:intersection*/ | |
| 82 | 132 | } |
| 83 | 133 | |
| 84 | 134 | /** |
| @@ -148,7 +198,7 @@ class TopLevel { | ||
| 148 | 198 | * @return float|string |
| 149 | 199 | */ |
| 150 | 200 | public static function sampleInUnion(): float|string { |
| 151 | - return 32.032; /*32:inUnion*/ | |
| 201 | + return 33.033; /*33:inUnion*/ | |
| 152 | 202 | } |
| 153 | 203 | |
| 154 | 204 | /** |
| @@ -195,7 +245,7 @@ class TopLevel { | ||
| 195 | 245 | * @return string |
| 196 | 246 | */ |
| 197 | 247 | public static function sampleMaxlength(): string { |
| 198 | - return 'TopLevel::maxlength::33'; /*33:maxlength*/ | |
| 248 | + return 'TopLevel::maxlength::34'; /*34:maxlength*/ | |
| 199 | 249 | } |
| 200 | 250 | |
| 201 | 251 | /** |
| @@ -242,7 +292,7 @@ class TopLevel { | ||
| 242 | 292 | * @return string |
| 243 | 293 | */ |
| 244 | 294 | public static function sampleMinlength(): string { |
| 245 | - return 'TopLevel::minlength::34'; /*34:minlength*/ | |
| 295 | + return 'TopLevel::minlength::35'; /*35:minlength*/ | |
| 246 | 296 | } |
| 247 | 297 | |
| 248 | 298 | /** |
| @@ -289,7 +339,7 @@ class TopLevel { | ||
| 289 | 339 | * @return string |
| 290 | 340 | */ |
| 291 | 341 | public static function sampleMinMaxIntersection(): string { |
| 292 | - return 'TopLevel::minMaxIntersection::35'; /*35:minMaxIntersection*/ | |
| 342 | + return 'TopLevel::minMaxIntersection::36'; /*36:minMaxIntersection*/ | |
| 293 | 343 | } |
| 294 | 344 | |
| 295 | 345 | /** |
| @@ -336,7 +386,7 @@ class TopLevel { | ||
| 336 | 386 | * @return string |
| 337 | 387 | */ |
| 338 | 388 | public static function sampleMinmaxlength(): string { |
| 339 | - return 'TopLevel::minmaxlength::36'; /*36:minmaxlength*/ | |
| 389 | + return 'TopLevel::minmaxlength::37'; /*37:minmaxlength*/ | |
| 340 | 390 | } |
| 341 | 391 | |
| 342 | 392 | /** |
| @@ -383,7 +433,7 @@ class TopLevel { | ||
| 383 | 433 | * @return string |
| 384 | 434 | */ |
| 385 | 435 | public static function sampleMinMaxUnion(): string { |
| 386 | - return 'TopLevel::minMaxUnion::37'; /*37:minMaxUnion*/ | |
| 436 | + return 'TopLevel::minMaxUnion::38'; /*38:minMaxUnion*/ | |
| 387 | 437 | } |
| 388 | 438 | |
| 389 | 439 | /** |
| @@ -430,7 +480,7 @@ class TopLevel { | ||
| 430 | 480 | * @return string |
| 431 | 481 | */ |
| 432 | 482 | public static function sampleUnion(): string { |
| 433 | - return 'TopLevel::union::38'; /*38:union*/ | |
| 483 | + return 'TopLevel::union::39'; /*39:union*/ | |
| 434 | 484 | } |
| 435 | 485 | |
| 436 | 486 | /** |
| @@ -438,7 +488,8 @@ class TopLevel { | ||
| 438 | 488 | * @return bool |
| 439 | 489 | */ |
| 440 | 490 | public function validate(): bool { |
| 441 | - return TopLevel::validateIntersection($this->intersection) | |
| 491 | + return TopLevel::validateEmptyOnly($this->emptyOnly) | |
| 492 | + || TopLevel::validateIntersection($this->intersection) | |
| 442 | 493 | || TopLevel::validateInUnion($this->inUnion) |
| 443 | 494 | || TopLevel::validateMaxlength($this->maxlength) |
| 444 | 495 | || TopLevel::validateMinlength($this->minlength) |
| @@ -454,6 +505,7 @@ class TopLevel { | ||
| 454 | 505 | */ |
| 455 | 506 | public function to(): stdClass { |
| 456 | 507 | $out = new stdClass(); |
| 508 | + $out->{'emptyOnly'} = $this->toEmptyOnly(); | |
| 457 | 509 | $out->{'intersection'} = $this->toIntersection(); |
| 458 | 510 | $out->{'inUnion'} = $this->toInUnion(); |
| 459 | 511 | $out->{'maxlength'} = $this->toMaxlength(); |
| @@ -472,7 +524,8 @@ class TopLevel { | ||
| 472 | 524 | */ |
| 473 | 525 | public static function from(stdClass $obj): TopLevel { |
| 474 | 526 | return new TopLevel( |
| 475 | - TopLevel::fromIntersection($obj->{'intersection'}) | |
| 527 | + TopLevel::fromEmptyOnly($obj->{'emptyOnly'}) | |
| 528 | + ,TopLevel::fromIntersection($obj->{'intersection'}) | |
| 476 | 529 | ,TopLevel::fromInUnion($obj->{'inUnion'}) |
| 477 | 530 | ,TopLevel::fromMaxlength($obj->{'maxlength'}) |
| 478 | 531 | ,TopLevel::fromMinlength($obj->{'minlength'}) |
| @@ -488,7 +541,8 @@ class TopLevel { | ||
| 488 | 541 | */ |
| 489 | 542 | public static function sample(): TopLevel { |
| 490 | 543 | return new TopLevel( |
| 491 | - TopLevel::sampleIntersection() | |
| 544 | + TopLevel::sampleEmptyOnly() | |
| 545 | + ,TopLevel::sampleIntersection() | |
| 492 | 546 | ,TopLevel::sampleInUnion() |
| 493 | 547 | ,TopLevel::sampleMaxlength() |
| 494 | 548 | ,TopLevel::sampleMinlength() |
Mschema-pikedefault / TopLevel.pmod+3 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | // match the expected interface, even if the JSON itself is valid. |
| 14 | 14 | |
| 15 | 15 | class TopLevel { |
| 16 | + string empty_only; // json: "emptyOnly" | |
| 16 | 17 | string intersection; // json: "intersection" |
| 17 | 18 | InUnion in_union; // json: "inUnion" |
| 18 | 19 | string maxlength; // json: "maxlength" |
| @@ -24,6 +25,7 @@ class TopLevel { | ||
| 24 | 25 | |
| 25 | 26 | string encode_json() { |
| 26 | 27 | mapping(string:mixed) json = ([ |
| 28 | + "emptyOnly" : empty_only, | |
| 27 | 29 | "intersection" : intersection, |
| 28 | 30 | "inUnion" : in_union, |
| 29 | 31 | "maxlength" : maxlength, |
| @@ -41,6 +43,7 @@ class TopLevel { | ||
| 41 | 43 | TopLevel TopLevel_from_JSON(mixed json) { |
| 42 | 44 | TopLevel retval = TopLevel(); |
| 43 | 45 | |
| 46 | + retval.empty_only = json["emptyOnly"]; | |
| 44 | 47 | retval.intersection = json["intersection"]; |
| 45 | 48 | retval.in_union = json["inUnion"]; |
| 46 | 49 | retval.maxlength = json["maxlength"]; |
Mschema-pythondefault / quicktype.py+4 −1
| @@ -36,6 +36,7 @@ def to_class(c: Type[T], x: Any) -> dict: | ||
| 36 | 36 | |
| 37 | 37 | @dataclass |
| 38 | 38 | class TopLevel: |
| 39 | + empty_only: str | |
| 39 | 40 | intersection: str |
| 40 | 41 | in_union: float | str |
| 41 | 42 | maxlength: str |
| @@ -48,6 +49,7 @@ class TopLevel: | ||
| 48 | 49 | @staticmethod |
| 49 | 50 | def from_dict(obj: Any) -> 'TopLevel': |
| 50 | 51 | assert isinstance(obj, dict) |
| 52 | + empty_only = from_str(obj.get("emptyOnly")) | |
| 51 | 53 | intersection = from_str(obj.get("intersection")) |
| 52 | 54 | in_union = from_union([from_float, from_str], obj.get("inUnion")) |
| 53 | 55 | maxlength = from_str(obj.get("maxlength")) |
| @@ -56,10 +58,11 @@ class TopLevel: | ||
| 56 | 58 | minmaxlength = from_str(obj.get("minmaxlength")) |
| 57 | 59 | min_max_union = from_str(obj.get("minMaxUnion")) |
| 58 | 60 | 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) | |
| 60 | 62 | |
| 61 | 63 | def to_dict(self) -> dict: |
| 62 | 64 | result: dict = {} |
| 65 | + result["emptyOnly"] = from_str(self.empty_only) | |
| 63 | 66 | result["intersection"] = from_str(self.intersection) |
| 64 | 67 | result["inUnion"] = from_union([to_float, from_str], self.in_union) |
| 65 | 68 | result["maxlength"] = from_str(self.maxlength) |
Mschema-rubydefault / TopLevel.rb+4 −1
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | # To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do: |
| 5 | 5 | # |
| 6 | 6 | # top_level = TopLevel.from_json! "{…}" |
| 7 | -# puts top_level.intersection | |
| 7 | +# puts top_level.empty_only | |
| 8 | 8 | # |
| 9 | 9 | # If from_json! succeeds, the value returned matches the schema. |
| 10 | 10 | |
| @@ -52,6 +52,7 @@ class InUnion < Dry::Struct | ||
| 52 | 52 | end |
| 53 | 53 | |
| 54 | 54 | class TopLevel < Dry::Struct |
| 55 | + attribute :empty_only, Types::String | |
| 55 | 56 | attribute :intersection, Types::String |
| 56 | 57 | attribute :in_union, Types.Instance(InUnion) |
| 57 | 58 | attribute :maxlength, Types::String |
| @@ -64,6 +65,7 @@ class TopLevel < Dry::Struct | ||
| 64 | 65 | def self.from_dynamic!(d) |
| 65 | 66 | d = Types::Hash[d] |
| 66 | 67 | new( |
| 68 | + empty_only: d.fetch("emptyOnly"), | |
| 67 | 69 | intersection: d.fetch("intersection"), |
| 68 | 70 | in_union: InUnion.from_dynamic!(d.fetch("inUnion")), |
| 69 | 71 | maxlength: d.fetch("maxlength"), |
| @@ -81,6 +83,7 @@ class TopLevel < Dry::Struct | ||
| 81 | 83 | |
| 82 | 84 | def to_dynamic |
| 83 | 85 | { |
| 86 | + "emptyOnly" => empty_only, | |
| 84 | 87 | "intersection" => intersection, |
| 85 | 88 | "inUnion" => in_union.to_dynamic, |
| 86 | 89 | "maxlength" => maxlength, |
Mschema-rustdefault / module_under_test.rs+2 −0
| @@ -16,6 +16,8 @@ use serde::{Serialize, Deserialize}; | ||
| 16 | 16 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 17 | 17 | #[serde(rename_all = "camelCase")] |
| 18 | 18 | pub struct TopLevel { |
| 19 | + pub empty_only: String, | |
| 20 | + | |
| 19 | 21 | pub intersection: String, |
| 20 | 22 | |
| 21 | 23 | pub in_union: InUnion, |
Mschema-scala3-upickledefault / TopLevel.scala+1 −0
| @@ -66,6 +66,7 @@ end JsonExt | ||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | case class TopLevel ( |
| 69 | + val emptyOnly : String, | |
| 69 | 70 | val intersection : String, |
| 70 | 71 | val inUnion : InUnion, |
| 71 | 72 | val maxlength : String, |
Mschema-scala3default / TopLevel.scala+1 −0
| @@ -8,6 +8,7 @@ import cats.syntax.functor._ | ||
| 8 | 8 | type NullValue = None.type |
| 9 | 9 | |
| 10 | 10 | case class TopLevel ( |
| 11 | + val emptyOnly : String, | |
| 11 | 12 | val intersection : String, |
| 12 | 13 | val inUnion : InUnion, |
| 13 | 14 | val maxlength : String, |
Mschema-schemadefault / TopLevel.schema+13 −4
| @@ -6,10 +6,15 @@ | ||
| 6 | 6 | "type": "object", |
| 7 | 7 | "additionalProperties": {}, |
| 8 | 8 | "properties": { |
| 9 | + "emptyOnly": { | |
| 10 | + "type": "string", | |
| 11 | + "maxLength": 0 | |
| 12 | + }, | |
| 9 | 13 | "intersection": { |
| 10 | 14 | "type": "string", |
| 11 | 15 | "minLength": 4, |
| 12 | - "maxLength": 5 | |
| 16 | + "maxLength": 5, | |
| 17 | + "pattern": "^[a-z]+$" | |
| 13 | 18 | }, |
| 14 | 19 | "inUnion": { |
| 15 | 20 | "$ref": "#/definitions/InUnion" |
| @@ -30,7 +35,8 @@ | ||
| 30 | 35 | "minmaxlength": { |
| 31 | 36 | "type": "string", |
| 32 | 37 | "minLength": 3, |
| 33 | - "maxLength": 5 | |
| 38 | + "maxLength": 5, | |
| 39 | + "pattern": "^[a-z]+$" | |
| 34 | 40 | }, |
| 35 | 41 | "minMaxUnion": { |
| 36 | 42 | "type": "string" |
| @@ -38,10 +44,12 @@ | ||
| 38 | 44 | "union": { |
| 39 | 45 | "type": "string", |
| 40 | 46 | "minLength": 3, |
| 41 | - "maxLength": 6 | |
| 47 | + "maxLength": 6, | |
| 48 | + "pattern": "^[a-z]+$" | |
| 42 | 49 | } |
| 43 | 50 | }, |
| 44 | 51 | "required": [ |
| 52 | + "emptyOnly", | |
| 45 | 53 | "inUnion", |
| 46 | 54 | "intersection", |
| 47 | 55 | "maxlength", |
| @@ -61,7 +69,8 @@ | ||
| 61 | 69 | { |
| 62 | 70 | "type": "string", |
| 63 | 71 | "minLength": 3, |
| 64 | - "maxLength": 5 | |
| 72 | + "maxLength": 5, | |
| 73 | + "pattern": "^[a-z]+$" | |
| 65 | 74 | } |
| 66 | 75 | ], |
| 67 | 76 | "title": "InUnion" |
Mschema-swiftdefault / quicktype.swift+4 −0
| @@ -7,6 +7,7 @@ import Foundation | ||
| 7 | 7 | |
| 8 | 8 | // MARK: - TopLevel |
| 9 | 9 | struct TopLevel: Codable { |
| 10 | + let emptyOnly: String | |
| 10 | 11 | let intersection: String |
| 11 | 12 | let inUnion: InUnion |
| 12 | 13 | let maxlength: String |
| @@ -17,6 +18,7 @@ struct TopLevel: Codable { | ||
| 17 | 18 | let union: String |
| 18 | 19 | |
| 19 | 20 | enum CodingKeys: String, CodingKey { |
| 21 | + case emptyOnly = "emptyOnly" | |
| 20 | 22 | case intersection = "intersection" |
| 21 | 23 | case inUnion = "inUnion" |
| 22 | 24 | case maxlength = "maxlength" |
| @@ -47,6 +49,7 @@ extension TopLevel { | ||
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | func with( |
| 52 | + emptyOnly: String? = nil, | |
| 50 | 53 | intersection: String? = nil, |
| 51 | 54 | inUnion: InUnion? = nil, |
| 52 | 55 | maxlength: String? = nil, |
| @@ -57,6 +60,7 @@ extension TopLevel { | ||
| 57 | 60 | union: String? = nil |
| 58 | 61 | ) -> TopLevel { |
| 59 | 62 | return TopLevel( |
| 63 | + emptyOnly: emptyOnly ?? self.emptyOnly, | |
| 60 | 64 | intersection: intersection ?? self.intersection, |
| 61 | 65 | inUnion: inUnion ?? self.inUnion, |
| 62 | 66 | maxlength: maxlength ?? self.maxlength, |
Mschema-typescript-zoddefault / TopLevel.ts+8 −7
| @@ -2,13 +2,14 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | 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]+$")), | |
| 11 | 12 | "minMaxUnion": z.string(), |
| 12 | - "union": z.string(), | |
| 13 | + "union": z.string().min(3).max(6).regex(new RegExp("^[a-z]+$")), | |
| 13 | 14 | }); |
| 14 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Mschema-typescriptdefault / TopLevel.ts+2 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | + emptyOnly: string; | |
| 11 | 12 | intersection: string; |
| 12 | 13 | inUnion: InUnion; |
| 13 | 14 | maxlength: string; |
| @@ -188,6 +189,7 @@ function r(name: string) { | ||
| 188 | 189 | |
| 189 | 190 | const typeMap: any = { |
| 190 | 191 | "TopLevel": o([ |
| 192 | + { json: "emptyOnly", js: "emptyOnly", typ: "" }, | |
| 191 | 193 | { json: "intersection", js: "intersection", typ: "" }, |
| 192 | 194 | { json: "inUnion", js: "inUnion", typ: u(3.14, "") }, |
| 193 | 195 | { json: "maxlength", js: "maxlength", typ: "" }, |
Test case
1 generated file · +2 −2test/inputs/schema/optional-const-ref.schema
Mschema-typescript-zoddefault / TopLevel.ts+2 −2
| @@ -10,10 +10,10 @@ export type Coordinate = z.infer<typeof CoordinateSchema>; | ||
| 10 | 10 | export const TopLevelSchema = z.object({ |
| 11 | 11 | "coordinates": z.array(CoordinateSchema).optional(), |
| 12 | 12 | "count": z.number().optional(), |
| 13 | - "label": z.string().optional(), | |
| 13 | + "label": z.string().min(2).max(16).optional(), | |
| 14 | 14 | "requiredCoordinates": z.array(CoordinateSchema), |
| 15 | 15 | "requiredCount": z.number(), |
| 16 | - "requiredLabel": z.string(), | |
| 16 | + "requiredLabel": z.string().min(2).max(16), | |
| 17 | 17 | "weight": z.number().optional(), |
| 18 | 18 | }); |
| 19 | 19 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −2test/inputs/schema/optional-constraints.schema
Mschema-typescript-zoddefault / TopLevel.ts+2 −2
| @@ -4,8 +4,8 @@ import * as z from "zod"; | ||
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "optDouble": z.number().optional(), |
| 6 | 6 | "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(), | |
| 9 | 9 | "reqZeroMin": z.number(), |
| 10 | 10 | }); |
| 11 | 11 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
28 generated files · +158 −20test/inputs/schema/pattern.schema
Mschema-cplusplusdefault / quicktype.hpp+9 −0
| @@ -165,6 +165,7 @@ namespace quicktype { | ||
| 165 | 165 | class TopLevel { |
| 166 | 166 | public: |
| 167 | 167 | TopLevel() : |
| 168 | + escaped_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("^\\d+\\.[a-z]+$")), | |
| 168 | 169 | pattern1_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("a[.]*")), |
| 169 | 170 | pattern2_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("b[.]*")), |
| 170 | 171 | union_constraint(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::string("(b[.]*)|(c[.]*)")) |
| @@ -172,6 +173,8 @@ namespace quicktype { | ||
| 172 | 173 | virtual ~TopLevel() = default; |
| 173 | 174 | |
| 174 | 175 | private: |
| 176 | + std::string escaped; | |
| 177 | + ClassMemberConstraints escaped_constraint; | |
| 175 | 178 | std::string pattern1; |
| 176 | 179 | ClassMemberConstraints pattern1_constraint; |
| 177 | 180 | std::string pattern2; |
| @@ -180,6 +183,10 @@ namespace quicktype { | ||
| 180 | 183 | ClassMemberConstraints union_constraint; |
| 181 | 184 | |
| 182 | 185 | 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 | + | |
| 183 | 190 | const std::string & get_pattern1() const { return pattern1; } |
| 184 | 191 | std::string & get_mutable_pattern1() { return pattern1; } |
| 185 | 192 | void set_pattern1(const std::string & value) { CheckConstraint("pattern1", pattern1_constraint, value); this->pattern1 = value; } |
| @@ -199,6 +206,7 @@ namespace quicktype { | ||
| 199 | 206 | void to_json(json & j, const TopLevel & x); |
| 200 | 207 | |
| 201 | 208 | inline void from_json(const json & j, TopLevel& x) { |
| 209 | + x.set_escaped(j.at("escaped").get<std::string>()); | |
| 202 | 210 | x.set_pattern1(j.at("pattern1").get<std::string>()); |
| 203 | 211 | x.set_pattern2(j.at("pattern2").get<std::string>()); |
| 204 | 212 | x.set_top_level_union(j.at("union").get<std::string>()); |
| @@ -206,6 +214,7 @@ namespace quicktype { | ||
| 206 | 214 | |
| 207 | 215 | inline void to_json(json & j, const TopLevel & x) { |
| 208 | 216 | j = json::object(); |
| 217 | + j["escaped"] = x.get_escaped(); | |
| 209 | 218 | j["pattern1"] = x.get_pattern1(); |
| 210 | 219 | j["pattern2"] = x.get_pattern2(); |
| 211 | 220 | j["union"] = x.get_top_level_union(); |
Mschema-csharp-recordsdefault / QuickType.cs+3 −0
| @@ -25,6 +25,9 @@ namespace QuickType | ||
| 25 | 25 | |
| 26 | 26 | public partial record TopLevel |
| 27 | 27 | { |
| 28 | + [JsonProperty("escaped", Required = Required.Always)] | |
| 29 | + public string Escaped { get; set; } | |
| 30 | + | |
| 28 | 31 | [JsonProperty("pattern1", Required = Required.Always)] |
| 29 | 32 | public string Pattern1 { get; set; } |
Mschema-csharp-SystemTextJsondefault / QuickType.cs+4 −0
| @@ -22,6 +22,10 @@ namespace QuickType | ||
| 22 | 22 | |
| 23 | 23 | public partial class TopLevel |
| 24 | 24 | { |
| 25 | + [JsonRequired] | |
| 26 | + [JsonPropertyName("escaped")] | |
| 27 | + public string Escaped { get; set; } | |
| 28 | + | |
| 25 | 29 | [JsonRequired] |
| 26 | 30 | [JsonPropertyName("pattern1")] |
| 27 | 31 | public string Pattern1 { get; set; } |
Mschema-csharpdefault / QuickType.cs+3 −0
| @@ -25,6 +25,9 @@ namespace QuickType | ||
| 25 | 25 | |
| 26 | 26 | public partial class TopLevel |
| 27 | 27 | { |
| 28 | + [JsonProperty("escaped", Required = Required.Always)] | |
| 29 | + public string Escaped { get; set; } | |
| 30 | + | |
| 28 | 31 | [JsonProperty("pattern1", Required = Required.Always)] |
| 29 | 32 | public string Pattern1 { get; set; } |
Mschema-dartdefault / TopLevel.dart+4 −0
| @@ -9,23 +9,27 @@ TopLevel topLevelFromJson(String str) => TopLevel.fromJson(json.decode(str)); | ||
| 9 | 9 | String topLevelToJson(TopLevel data) => json.encode(data.toJson()); |
| 10 | 10 | |
| 11 | 11 | class TopLevel { |
| 12 | + final String escaped; | |
| 12 | 13 | final String pattern1; |
| 13 | 14 | final String pattern2; |
| 14 | 15 | final String union; |
| 15 | 16 | |
| 16 | 17 | TopLevel({ |
| 18 | + required this.escaped, | |
| 17 | 19 | required this.pattern1, |
| 18 | 20 | required this.pattern2, |
| 19 | 21 | required this.union, |
| 20 | 22 | }); |
| 21 | 23 | |
| 22 | 24 | factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel( |
| 25 | + escaped: json["escaped"], | |
| 23 | 26 | pattern1: json["pattern1"], |
| 24 | 27 | pattern2: json["pattern2"], |
| 25 | 28 | union: json["union"], |
| 26 | 29 | ); |
| 27 | 30 | |
| 28 | 31 | Map<String, dynamic> toJson() => { |
| 32 | + "escaped": escaped, | |
| 29 | 33 | "pattern1": pattern1, |
| 30 | 34 | "pattern2": pattern2, |
| 31 | 35 | "union": union, |
Mschema-elixirdefault / QuickType.ex+5 −2
| @@ -6,10 +6,11 @@ | ||
| 6 | 6 | # Encode into a JSON string: TopLevel.to_json(struct) |
| 7 | 7 | |
| 8 | 8 | 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] | |
| 11 | 11 | |
| 12 | 12 | @type t :: %__MODULE__{ |
| 13 | + escaped: String.t(), | |
| 13 | 14 | pattern1: String.t(), |
| 14 | 15 | pattern2: String.t(), |
| 15 | 16 | union: String.t() |
| @@ -17,6 +18,7 @@ defmodule TopLevel do | ||
| 17 | 18 | |
| 18 | 19 | def from_map(m) do |
| 19 | 20 | %TopLevel{ |
| 21 | + escaped: m["escaped"], | |
| 20 | 22 | pattern1: m["pattern1"], |
| 21 | 23 | pattern2: m["pattern2"], |
| 22 | 24 | union: m["union"], |
| @@ -31,6 +33,7 @@ defmodule TopLevel do | ||
| 31 | 33 | |
| 32 | 34 | def to_map(struct) do |
| 33 | 35 | %{ |
| 36 | + "escaped" => struct.escaped, | |
| 34 | 37 | "pattern1" => struct.pattern1, |
| 35 | 38 | "pattern2" => struct.pattern2, |
| 36 | 39 | "union" => struct.union, |
Mschema-elmdefault / QuickType.elm+5 −2
| @@ -23,7 +23,8 @@ import Json.Encode as Jenc | ||
| 23 | 23 | import Dict exposing (Dict) |
| 24 | 24 | |
| 25 | 25 | type alias QuickType = |
| 26 | - { pattern1 : String | |
| 26 | + { escaped : String | |
| 27 | + , pattern1 : String | |
| 27 | 28 | , pattern2 : String |
| 28 | 29 | , union : String |
| 29 | 30 | } |
| @@ -36,6 +37,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r) | ||
| 36 | 37 | quickType : Jdec.Decoder QuickType |
| 37 | 38 | quickType = |
| 38 | 39 | Jdec.succeed QuickType |
| 40 | + |> Jpipe.required "escaped" Jdec.string | |
| 39 | 41 | |> Jpipe.required "pattern1" Jdec.string |
| 40 | 42 | |> Jpipe.required "pattern2" Jdec.string |
| 41 | 43 | |> Jpipe.required "union" Jdec.string |
| @@ -43,7 +45,8 @@ quickType = | ||
| 43 | 45 | encodeQuickType : QuickType -> Jenc.Value |
| 44 | 46 | encodeQuickType x = |
| 45 | 47 | Jenc.object |
| 46 | - [ ("pattern1", Jenc.string x.pattern1) | |
| 48 | + [ ("escaped", Jenc.string x.escaped) | |
| 49 | + , ("pattern1", Jenc.string x.pattern1) | |
| 47 | 50 | , ("pattern2", Jenc.string x.pattern2) |
| 48 | 51 | , ("union", Jenc.string x.union) |
| 49 | 52 | ] |
Mschema-flowdefault / TopLevel.js+2 −0
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | + escaped: string; | |
| 13 | 14 | pattern1: string; |
| 14 | 15 | pattern2: string; |
| 15 | 16 | union: string; |
| @@ -181,6 +182,7 @@ function r(name: string) { | ||
| 181 | 182 | |
| 182 | 183 | const typeMap: any = { |
| 183 | 184 | "TopLevel": o([ |
| 185 | + { json: "escaped", js: "escaped", typ: "" }, | |
| 184 | 186 | { json: "pattern1", js: "pattern1", typ: "" }, |
| 185 | 187 | { json: "pattern2", js: "pattern2", typ: "" }, |
| 186 | 188 | { json: "union", js: "union", typ: "" }, |
Mschema-golangdefault / quicktype.go+1 −0
| @@ -19,6 +19,7 @@ func (r *TopLevel) Marshal() ([]byte, error) { | ||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | type TopLevel struct { |
| 22 | + Escaped string `json:"escaped"` | |
| 22 | 23 | Pattern1 string `json:"pattern1"` |
| 23 | 24 | Pattern2 string `json:"pattern2"` |
| 24 | 25 | Union string `json:"union"` |
Mschema-haskelldefault / QuickType.hs+7 −4
| @@ -13,7 +13,8 @@ import Data.HashMap.Strict (HashMap) | ||
| 13 | 13 | import Data.Text (Text) |
| 14 | 14 | |
| 15 | 15 | data QuickType = QuickType |
| 16 | - { pattern1QuickType :: Text | |
| 16 | + { escapedQuickType :: Text | |
| 17 | + , pattern1QuickType :: Text | |
| 17 | 18 | , pattern2QuickType :: Text |
| 18 | 19 | , unionQuickType :: Text |
| 19 | 20 | } deriving (Show) |
| @@ -22,15 +23,17 @@ decodeTopLevel :: ByteString -> Maybe QuickType | ||
| 22 | 23 | decodeTopLevel = decode |
| 23 | 24 | |
| 24 | 25 | instance ToJSON QuickType where |
| 25 | - toJSON (QuickType pattern1QuickType pattern2QuickType unionQuickType) = | |
| 26 | + toJSON (QuickType escapedQuickType pattern1QuickType pattern2QuickType unionQuickType) = | |
| 26 | 27 | object |
| 27 | - [ "pattern1" .= pattern1QuickType | |
| 28 | + [ "escaped" .= escapedQuickType | |
| 29 | + , "pattern1" .= pattern1QuickType | |
| 28 | 30 | , "pattern2" .= pattern2QuickType |
| 29 | 31 | , "union" .= unionQuickType |
| 30 | 32 | ] |
| 31 | 33 | |
| 32 | 34 | instance FromJSON QuickType where |
| 33 | 35 | parseJSON (Object v) = QuickType |
| 34 | - <$> v .: "pattern1" | |
| 36 | + <$> v .: "escaped" | |
| 37 | + <*> v .: "pattern1" | |
| 35 | 38 | <*> v .: "pattern2" |
| 36 | 39 | <*> v .: "union" |
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,10 +3,16 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String escaped; | |
| 6 | 7 | private String pattern1; |
| 7 | 8 | private String pattern2; |
| 8 | 9 | private String union; |
| 9 | 10 | |
| 11 | + @JsonProperty("escaped") | |
| 12 | + public String getEscaped() { return escaped; } | |
| 13 | + @JsonProperty("escaped") | |
| 14 | + public void setEscaped(String value) { this.escaped = value; } | |
| 15 | + | |
| 10 | 16 | @JsonProperty("pattern1") |
| 11 | 17 | public String getPattern1() { return pattern1; } |
| 12 | 18 | @JsonProperty("pattern1") |
Mschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,10 +3,16 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String escaped; | |
| 6 | 7 | private String pattern1; |
| 7 | 8 | private String pattern2; |
| 8 | 9 | private String union; |
| 9 | 10 | |
| 11 | + @JsonProperty("escaped") | |
| 12 | + public String getEscaped() { return escaped; } | |
| 13 | + @JsonProperty("escaped") | |
| 14 | + public void setEscaped(String value) { this.escaped = value; } | |
| 15 | + | |
| 10 | 16 | @JsonProperty("pattern1") |
| 11 | 17 | public String getPattern1() { return pattern1; } |
| 12 | 18 | @JsonProperty("pattern1") |
Mschema-javadefault / src / main / java / io / quicktype / TopLevel.java+6 −0
| @@ -3,10 +3,16 @@ package io.quicktype; | ||
| 3 | 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | 4 | |
| 5 | 5 | public class TopLevel { |
| 6 | + private String escaped; | |
| 6 | 7 | private String pattern1; |
| 7 | 8 | private String pattern2; |
| 8 | 9 | private String union; |
| 9 | 10 | |
| 11 | + @JsonProperty("escaped") | |
| 12 | + public String getEscaped() { return escaped; } | |
| 13 | + @JsonProperty("escaped") | |
| 14 | + public void setEscaped(String value) { this.escaped = value; } | |
| 15 | + | |
| 10 | 16 | @JsonProperty("pattern1") |
| 11 | 17 | public String getPattern1() { return pattern1; } |
| 12 | 18 | @JsonProperty("pattern1") |
Mschema-javascriptdefault / TopLevel.js+1 −0
| @@ -172,6 +172,7 @@ function r(name) { | ||
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | 174 | "TopLevel": o([ |
| 175 | + { json: "escaped", js: "escaped", typ: "" }, | |
| 175 | 176 | { json: "pattern1", js: "pattern1", typ: "" }, |
| 176 | 177 | { json: "pattern2", js: "pattern2", typ: "" }, |
| 177 | 178 | { json: "union", js: "union", typ: "" }, |
Mschema-kotlin-jacksondefault / TopLevel.kt+3 −0
| @@ -19,6 +19,9 @@ val mapper = jacksonObjectMapper().apply { | ||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | data class TopLevel ( |
| 22 | + @get:JsonProperty(required=true)@field:JsonProperty(required=true) | |
| 23 | + val escaped: String, | |
| 24 | + | |
| 22 | 25 | @get:JsonProperty(required=true)@field:JsonProperty(required=true) |
| 23 | 26 | val pattern1: String, |
Mschema-kotlindefault / TopLevel.kt+1 −0
| @@ -9,6 +9,7 @@ import com.beust.klaxon.* | ||
| 9 | 9 | private val klaxon = Klaxon() |
| 10 | 10 | |
| 11 | 11 | data class TopLevel ( |
| 12 | + val escaped: String, | |
| 12 | 13 | val pattern1: String, |
| 13 | 14 | val pattern2: String, |
| 14 | 15 | val union: String |
Mschema-kotlinxdefault / TopLevel.kt+1 −0
| @@ -12,6 +12,7 @@ import kotlinx.serialization.encoding.* | ||
| 12 | 12 | |
| 13 | 13 | @Serializable |
| 14 | 14 | data class TopLevel ( |
| 15 | + val escaped: String, | |
| 15 | 16 | val pattern1: String, |
| 16 | 17 | val pattern2: String, |
| 17 | 18 | val union: String |
Mschema-phpdefault / TopLevel.php+61 −7
| @@ -4,21 +4,71 @@ declare(strict_types=1); | ||
| 4 | 4 | // This is an autogenerated file:TopLevel |
| 5 | 5 | |
| 6 | 6 | class TopLevel { |
| 7 | + private string $escaped; // json:escaped Required | |
| 7 | 8 | private string $pattern1; // json:pattern1 Required |
| 8 | 9 | private string $pattern2; // json:pattern2 Required |
| 9 | 10 | private string $union; // json:union Required |
| 10 | 11 | |
| 11 | 12 | /** |
| 13 | + * @param string $escaped | |
| 12 | 14 | * @param string $pattern1 |
| 13 | 15 | * @param string $pattern2 |
| 14 | 16 | * @param string $union |
| 15 | 17 | */ |
| 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; | |
| 17 | 20 | $this->pattern1 = $pattern1; |
| 18 | 21 | $this->pattern2 = $pattern2; |
| 19 | 22 | $this->union = $union; |
| 20 | 23 | } |
| 21 | 24 | |
| 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 | + | |
| 22 | 72 | /** |
| 23 | 73 | * @param string $value |
| 24 | 74 | * @throws Exception |
| @@ -63,7 +113,7 @@ class TopLevel { | ||
| 63 | 113 | * @return string |
| 64 | 114 | */ |
| 65 | 115 | public static function samplePattern1(): string { |
| 66 | - return 'TopLevel::pattern1::31'; /*31:pattern1*/ | |
| 116 | + return 'TopLevel::pattern1::32'; /*32:pattern1*/ | |
| 67 | 117 | } |
| 68 | 118 | |
| 69 | 119 | /** |
| @@ -110,7 +160,7 @@ class TopLevel { | ||
| 110 | 160 | * @return string |
| 111 | 161 | */ |
| 112 | 162 | public static function samplePattern2(): string { |
| 113 | - return 'TopLevel::pattern2::32'; /*32:pattern2*/ | |
| 163 | + return 'TopLevel::pattern2::33'; /*33:pattern2*/ | |
| 114 | 164 | } |
| 115 | 165 | |
| 116 | 166 | /** |
| @@ -157,7 +207,7 @@ class TopLevel { | ||
| 157 | 207 | * @return string |
| 158 | 208 | */ |
| 159 | 209 | public static function sampleUnion(): string { |
| 160 | - return 'TopLevel::union::33'; /*33:union*/ | |
| 210 | + return 'TopLevel::union::34'; /*34:union*/ | |
| 161 | 211 | } |
| 162 | 212 | |
| 163 | 213 | /** |
| @@ -165,7 +215,8 @@ class TopLevel { | ||
| 165 | 215 | * @return bool |
| 166 | 216 | */ |
| 167 | 217 | public function validate(): bool { |
| 168 | - return TopLevel::validatePattern1($this->pattern1) | |
| 218 | + return TopLevel::validateEscaped($this->escaped) | |
| 219 | + || TopLevel::validatePattern1($this->pattern1) | |
| 169 | 220 | || TopLevel::validatePattern2($this->pattern2) |
| 170 | 221 | || TopLevel::validateUnion($this->union); |
| 171 | 222 | } |
| @@ -176,6 +227,7 @@ class TopLevel { | ||
| 176 | 227 | */ |
| 177 | 228 | public function to(): stdClass { |
| 178 | 229 | $out = new stdClass(); |
| 230 | + $out->{'escaped'} = $this->toEscaped(); | |
| 179 | 231 | $out->{'pattern1'} = $this->toPattern1(); |
| 180 | 232 | $out->{'pattern2'} = $this->toPattern2(); |
| 181 | 233 | $out->{'union'} = $this->toUnion(); |
| @@ -189,7 +241,8 @@ class TopLevel { | ||
| 189 | 241 | */ |
| 190 | 242 | public static function from(stdClass $obj): TopLevel { |
| 191 | 243 | return new TopLevel( |
| 192 | - TopLevel::fromPattern1($obj->{'pattern1'}) | |
| 244 | + TopLevel::fromEscaped($obj->{'escaped'}) | |
| 245 | + ,TopLevel::fromPattern1($obj->{'pattern1'}) | |
| 193 | 246 | ,TopLevel::fromPattern2($obj->{'pattern2'}) |
| 194 | 247 | ,TopLevel::fromUnion($obj->{'union'}) |
| 195 | 248 | ); |
| @@ -200,7 +253,8 @@ class TopLevel { | ||
| 200 | 253 | */ |
| 201 | 254 | public static function sample(): TopLevel { |
| 202 | 255 | return new TopLevel( |
| 203 | - TopLevel::samplePattern1() | |
| 256 | + TopLevel::sampleEscaped() | |
| 257 | + ,TopLevel::samplePattern1() | |
| 204 | 258 | ,TopLevel::samplePattern2() |
| 205 | 259 | ,TopLevel::sampleUnion() |
| 206 | 260 | ); |
Mschema-pikedefault / TopLevel.pmod+3 −0
| @@ -13,12 +13,14 @@ | ||
| 13 | 13 | // match the expected interface, even if the JSON itself is valid. |
| 14 | 14 | |
| 15 | 15 | class TopLevel { |
| 16 | + string escaped; // json: "escaped" | |
| 16 | 17 | string pattern1; // json: "pattern1" |
| 17 | 18 | string pattern2; // json: "pattern2" |
| 18 | 19 | string union; // json: "union" |
| 19 | 20 | |
| 20 | 21 | string encode_json() { |
| 21 | 22 | mapping(string:mixed) json = ([ |
| 23 | + "escaped" : escaped, | |
| 22 | 24 | "pattern1" : pattern1, |
| 23 | 25 | "pattern2" : pattern2, |
| 24 | 26 | "union" : union, |
| @@ -31,6 +33,7 @@ class TopLevel { | ||
| 31 | 33 | TopLevel TopLevel_from_JSON(mixed json) { |
| 32 | 34 | TopLevel retval = TopLevel(); |
| 33 | 35 | |
| 36 | + retval.escaped = json["escaped"]; | |
| 34 | 37 | retval.pattern1 = json["pattern1"]; |
| 35 | 38 | retval.pattern2 = json["pattern2"]; |
| 36 | 39 | retval.union = json["union"]; |
Mschema-pythondefault / quicktype.py+4 −1
| @@ -17,6 +17,7 @@ def to_class(c: Type[T], x: Any) -> dict: | ||
| 17 | 17 | |
| 18 | 18 | @dataclass |
| 19 | 19 | class TopLevel: |
| 20 | + escaped: str | |
| 20 | 21 | pattern1: str |
| 21 | 22 | pattern2: str |
| 22 | 23 | union: str |
| @@ -24,13 +25,15 @@ class TopLevel: | ||
| 24 | 25 | @staticmethod |
| 25 | 26 | def from_dict(obj: Any) -> 'TopLevel': |
| 26 | 27 | assert isinstance(obj, dict) |
| 28 | + escaped = from_str(obj.get("escaped")) | |
| 27 | 29 | pattern1 = from_str(obj.get("pattern1")) |
| 28 | 30 | pattern2 = from_str(obj.get("pattern2")) |
| 29 | 31 | union = from_str(obj.get("union")) |
| 30 | - return TopLevel(pattern1, pattern2, union) | |
| 32 | + return TopLevel(escaped, pattern1, pattern2, union) | |
| 31 | 33 | |
| 32 | 34 | def to_dict(self) -> dict: |
| 33 | 35 | result: dict = {} |
| 36 | + result["escaped"] = from_str(self.escaped) | |
| 34 | 37 | result["pattern1"] = from_str(self.pattern1) |
| 35 | 38 | result["pattern2"] = from_str(self.pattern2) |
| 36 | 39 | result["union"] = from_str(self.union) |
Mschema-rubydefault / TopLevel.rb+4 −1
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | # To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do: |
| 5 | 5 | # |
| 6 | 6 | # top_level = TopLevel.from_json! "{…}" |
| 7 | -# puts top_level.pattern1 | |
| 7 | +# puts top_level.escaped | |
| 8 | 8 | # |
| 9 | 9 | # If from_json! succeeds, the value returned matches the schema. |
| 10 | 10 | |
| @@ -20,6 +20,7 @@ module Types | ||
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | class TopLevel < Dry::Struct |
| 23 | + attribute :escaped, Types::String | |
| 23 | 24 | attribute :pattern1, Types::String |
| 24 | 25 | attribute :pattern2, Types::String |
| 25 | 26 | attribute :union, Types::String |
| @@ -27,6 +28,7 @@ class TopLevel < Dry::Struct | ||
| 27 | 28 | def self.from_dynamic!(d) |
| 28 | 29 | d = Types::Hash[d] |
| 29 | 30 | new( |
| 31 | + escaped: d.fetch("escaped"), | |
| 30 | 32 | pattern1: d.fetch("pattern1"), |
| 31 | 33 | pattern2: d.fetch("pattern2"), |
| 32 | 34 | union: d.fetch("union"), |
| @@ -39,6 +41,7 @@ class TopLevel < Dry::Struct | ||
| 39 | 41 | |
| 40 | 42 | def to_dynamic |
| 41 | 43 | { |
| 44 | + "escaped" => escaped, | |
| 42 | 45 | "pattern1" => pattern1, |
| 43 | 46 | "pattern2" => pattern2, |
| 44 | 47 | "union" => union, |
Mschema-rustdefault / module_under_test.rs+2 −0
| @@ -15,6 +15,8 @@ use serde::{Serialize, Deserialize}; | ||
| 15 | 15 | |
| 16 | 16 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 17 | 17 | pub struct TopLevel { |
| 18 | + pub escaped: String, | |
| 19 | + | |
| 18 | 20 | pub pattern1: String, |
| 19 | 21 | |
| 20 | 22 | pub pattern2: String, |
Mschema-scala3-upickledefault / TopLevel.scala+1 −0
| @@ -66,6 +66,7 @@ end JsonExt | ||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | case class TopLevel ( |
| 69 | + val escaped : String, | |
| 69 | 70 | val pattern1 : String, |
| 70 | 71 | val pattern2 : String, |
| 71 | 72 | val union : String |
Mschema-scala3default / TopLevel.scala+1 −0
| @@ -8,6 +8,7 @@ import cats.syntax.functor._ | ||
| 8 | 8 | type NullValue = None.type |
| 9 | 9 | |
| 10 | 10 | case class TopLevel ( |
| 11 | + val escaped : String, | |
| 11 | 12 | val pattern1 : String, |
| 12 | 13 | val pattern2 : String, |
| 13 | 14 | val union : String |
Mschema-schemadefault / TopLevel.schema+5 −0
| @@ -6,6 +6,10 @@ | ||
| 6 | 6 | "type": "object", |
| 7 | 7 | "additionalProperties": {}, |
| 8 | 8 | "properties": { |
| 9 | + "escaped": { | |
| 10 | + "type": "string", | |
| 11 | + "pattern": "^\\d+\\.[a-z]+$" | |
| 12 | + }, | |
| 9 | 13 | "pattern1": { |
| 10 | 14 | "type": "string", |
| 11 | 15 | "pattern": "a[.]*" |
| @@ -20,6 +24,7 @@ | ||
| 20 | 24 | } |
| 21 | 25 | }, |
| 22 | 26 | "required": [ |
| 27 | + "escaped", | |
| 23 | 28 | "pattern1", |
| 24 | 29 | "pattern2", |
| 25 | 30 | "union" |
Mschema-swiftdefault / quicktype.swift+4 −0
| @@ -7,11 +7,13 @@ import Foundation | ||
| 7 | 7 | |
| 8 | 8 | // MARK: - TopLevel |
| 9 | 9 | struct TopLevel: Codable { |
| 10 | + let escaped: String | |
| 10 | 11 | let pattern1: String |
| 11 | 12 | let pattern2: String |
| 12 | 13 | let union: String |
| 13 | 14 | |
| 14 | 15 | enum CodingKeys: String, CodingKey { |
| 16 | + case escaped = "escaped" | |
| 15 | 17 | case pattern1 = "pattern1" |
| 16 | 18 | case pattern2 = "pattern2" |
| 17 | 19 | case union = "union" |
| @@ -37,11 +39,13 @@ extension TopLevel { | ||
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | func with( |
| 42 | + escaped: String? = nil, | |
| 40 | 43 | pattern1: String? = nil, |
| 41 | 44 | pattern2: String? = nil, |
| 42 | 45 | union: String? = nil |
| 43 | 46 | ) -> TopLevel { |
| 44 | 47 | return TopLevel( |
| 48 | + escaped: escaped ?? self.escaped, | |
| 45 | 49 | pattern1: pattern1 ?? self.pattern1, |
| 46 | 50 | pattern2: pattern2 ?? self.pattern2, |
| 47 | 51 | union: union ?? self.union |
Mschema-typescript-zoddefault / TopLevel.ts+4 −3
| @@ -2,8 +2,9 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | 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[.]*)")), | |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Mschema-typescriptdefault / TopLevel.ts+2 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | + escaped: string; | |
| 11 | 12 | pattern1: string; |
| 12 | 13 | pattern2: string; |
| 13 | 14 | union: string; |
| @@ -181,6 +182,7 @@ function r(name: string) { | ||
| 181 | 182 | |
| 182 | 183 | const typeMap: any = { |
| 183 | 184 | "TopLevel": o([ |
| 185 | + { json: "escaped", js: "escaped", typ: "" }, | |
| 184 | 186 | { json: "pattern1", js: "pattern1", typ: "" }, |
| 185 | 187 | { json: "pattern2", js: "pattern2", typ: "" }, |
| 186 | 188 | { json: "union", js: "union", typ: "" }, |
Test case
1 generated file · +3 −3test/inputs/schema/renaming-bug.schema
Mschema-typescript-zoddefault / TopLevel.ts+3 −3
| @@ -78,7 +78,7 @@ export type Geometry = z.infer<typeof GeometrySchema>; | ||
| 78 | 78 | |
| 79 | 79 | export const VehicleSchema = z.object({ |
| 80 | 80 | "brand": z.string().optional(), |
| 81 | - "id": z.string().optional(), | |
| 81 | + "id": z.string().min(1).optional(), | |
| 82 | 82 | "speed": SpeedSchema.optional(), |
| 83 | 83 | "subModule": z.boolean().optional(), |
| 84 | 84 | "type": VehicleTypeSchema.optional(), |
| @@ -94,7 +94,7 @@ export type Shape = z.infer<typeof ShapeSchema>; | ||
| 94 | 94 | |
| 95 | 95 | export const BerrySchema = z.object({ |
| 96 | 96 | "color": ColorSchema.optional(), |
| 97 | - "name": z.string().optional(), | |
| 97 | + "name": z.string().min(1).optional(), | |
| 98 | 98 | "shapes": z.array(ShapeSchema).optional(), |
| 99 | 99 | }); |
| 100 | 100 | export type Berry = z.infer<typeof BerrySchema>; |
| @@ -107,7 +107,7 @@ export const FruitSchema = z.object({ | ||
| 107 | 107 | export type Fruit = z.infer<typeof FruitSchema>; |
| 108 | 108 | |
| 109 | 109 | 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(), | |
| 111 | 111 | "fruits": z.array(FruitSchema).optional(), |
| 112 | 112 | "vehicles": z.array(VehicleSchema).optional(), |
| 113 | 113 | }); |
Test case
1 generated file · +1 −1test/inputs/schema/schema-constraints.schema
Mschema-typescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | - "minMaxLength": z.string(), | |
| 5 | + "minMaxLength": z.string().min(5).max(5), | |
| 6 | 6 | "percent": z.number(), |
| 7 | 7 | }); |
| 8 | 8 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
No generated files match these filters.