Test case
34 generated files · +464 −108test/inputs/schema/minmaxlength.schema
Mschema-cjsondefault / TopLevel.c+23 −0
| @@ -62,9 +62,21 @@ struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | ||
| 62 | 62 | if (NULL != j) { |
| 63 | 63 | if (NULL != (x = cJSON_malloc(sizeof(struct TopLevel)))) { |
| 64 | 64 | memset(x, 0, sizeof(struct TopLevel)); |
| 65 | + if (!cJSON_HasObjectItem(j, "emptyOnly")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 66 | + if (cJSON_HasObjectItem(j, "emptyOnly")) { | |
| 67 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "emptyOnly"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 68 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "emptyOnly")->valuestring) > 0) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 69 | + x->empty_only = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "emptyOnly"))); | |
| 70 | + } | |
| 71 | + else { | |
| 72 | + if (NULL != (x->empty_only = cJSON_malloc(sizeof(char)))) { | |
| 73 | + x->empty_only[0] = '\0'; | |
| 74 | + } | |
| 75 | + } | |
| 65 | 76 | if (!cJSON_HasObjectItem(j, "intersection")) { cJSON_DeleteTopLevel(x); return NULL; } |
| 66 | 77 | if (cJSON_HasObjectItem(j, "intersection")) { |
| 67 | 78 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "intersection"))) { cJSON_DeleteTopLevel(x); return NULL; } |
| 79 | + regex_t regex; regcomp(®ex, "^[a-z]+$", REG_EXTENDED); if (regexec(®ex, cJSON_GetObjectItemCaseSensitive(j, "intersection")->valuestring, 0, NULL, 0)) { regfree(®ex); cJSON_DeleteTopLevel(x); return NULL; } regfree(®ex); | |
| 68 | 80 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "intersection")->valuestring) < 4) { cJSON_DeleteTopLevel(x); return NULL; } |
| 69 | 81 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "intersection")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } |
| 70 | 82 | x->intersection = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "intersection"))); |
| @@ -117,6 +129,7 @@ struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | ||
| 117 | 129 | if (!cJSON_HasObjectItem(j, "minmaxlength")) { cJSON_DeleteTopLevel(x); return NULL; } |
| 118 | 130 | if (cJSON_HasObjectItem(j, "minmaxlength")) { |
| 119 | 131 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength"))) { cJSON_DeleteTopLevel(x); return NULL; } |
| 132 | + regex_t regex; regcomp(®ex, "^[a-z]+$", REG_EXTENDED); if (regexec(®ex, cJSON_GetObjectItemCaseSensitive(j, "minmaxlength")->valuestring, 0, NULL, 0)) { regfree(®ex); cJSON_DeleteTopLevel(x); return NULL; } regfree(®ex); | |
| 120 | 133 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } |
| 121 | 134 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } |
| 122 | 135 | x->minmaxlength = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength"))); |
| @@ -139,6 +152,7 @@ struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | ||
| 139 | 152 | if (!cJSON_HasObjectItem(j, "union")) { cJSON_DeleteTopLevel(x); return NULL; } |
| 140 | 153 | if (cJSON_HasObjectItem(j, "union")) { |
| 141 | 154 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "union"))) { cJSON_DeleteTopLevel(x); return NULL; } |
| 155 | + regex_t regex; regcomp(®ex, "^[a-z]+$", REG_EXTENDED); if (regexec(®ex, cJSON_GetObjectItemCaseSensitive(j, "union")->valuestring, 0, NULL, 0)) { regfree(®ex); cJSON_DeleteTopLevel(x); return NULL; } regfree(®ex); | |
| 142 | 156 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "union")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } |
| 143 | 157 | if (strlen(cJSON_GetObjectItemCaseSensitive(j, "union")->valuestring) > 6) { cJSON_DeleteTopLevel(x); return NULL; } |
| 144 | 158 | x->top_level_union = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "union"))); |
| @@ -157,6 +171,12 @@ cJSON * cJSON_CreateTopLevel(const struct TopLevel * x) { | ||
| 157 | 171 | cJSON * j = NULL; |
| 158 | 172 | if (NULL != x) { |
| 159 | 173 | if (NULL != (j = cJSON_CreateObject())) { |
| 174 | + if (NULL != x->empty_only) { | |
| 175 | + cJSON_AddStringToObject(j, "emptyOnly", x->empty_only); | |
| 176 | + } | |
| 177 | + else { | |
| 178 | + cJSON_AddStringToObject(j, "emptyOnly", ""); | |
| 179 | + } | |
| 160 | 180 | if (NULL != x->intersection) { |
| 161 | 181 | cJSON_AddStringToObject(j, "intersection", x->intersection); |
| 162 | 182 | } |
| @@ -219,6 +239,9 @@ char * cJSON_PrintTopLevel(const struct TopLevel * x) { | ||
| 219 | 239 | |
| 220 | 240 | void cJSON_DeleteTopLevel(struct TopLevel * x) { |
| 221 | 241 | if (NULL != x) { |
| 242 | + if (NULL != x->empty_only) { | |
| 243 | + cJSON_free(x->empty_only); | |
| 244 | + } | |
| 222 | 245 | if (NULL != x->intersection) { |
| 223 | 246 | cJSON_free(x->intersection); |
| 224 | 247 | } |
Mschema-cjsondefault / TopLevel.h+1 −0
| @@ -44,6 +44,7 @@ struct InUnion { | ||
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | 46 | struct TopLevel { |
| 47 | + char * empty_only; | |
| 47 | 48 | char * intersection; |
| 48 | 49 | struct InUnion * in_union; |
| 49 | 50 | char * maxlength; |
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; } |
| @@ -298,6 +305,7 @@ struct adl_serializer<std::variant<double, std::string>> { | ||
| 298 | 305 | namespace quicktype { |
| 299 | 306 | inline void from_json(const json & j, TopLevel& x) { |
| 300 | 307 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 308 | + x.set_empty_only(j.at("emptyOnly").get<std::string>()); | |
| 301 | 309 | x.set_intersection(j.at("intersection").get<std::string>()); |
| 302 | 310 | x.set_in_union(j.at("inUnion").get<InUnion>()); |
| 303 | 311 | x.set_maxlength(j.at("maxlength").get<std::string>()); |
| @@ -310,6 +318,7 @@ namespace quicktype { | ||
| 310 | 318 | |
| 311 | 319 | inline void to_json(json & j, const TopLevel & x) { |
| 312 | 320 | j = json::object(); |
| 321 | + j["emptyOnly"] = x.get_empty_only(); | |
| 313 | 322 | j["intersection"] = x.get_intersection(); |
| 314 | 323 | j["inUnion"] = x.get_in_union(); |
| 315 | 324 | j["maxlength"] = x.get_maxlength(); |
Mschema-crystaldefault / TopLevel.cr+3 −0
| @@ -3,6 +3,9 @@ require "json" | ||
| 3 | 3 | class TopLevel |
| 4 | 4 | include JSON::Serializable |
| 5 | 5 | |
| 6 | + @[JSON::Field(key: "emptyOnly")] | |
| 7 | + property empty_only : String | |
| 8 | + | |
| 6 | 9 | property intersection : String |
| 7 | 10 | |
| 8 | 11 | @[JSON::Field(key: "inUnion")] |
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+7 −3
| @@ -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,17 +32,19 @@ class TopLevel { | ||
| 30 | 32 | }); |
| 31 | 33 | |
| 32 | 34 | factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel( |
| 33 | - intersection: ((x) => x.length >= 4 && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["intersection"]), | |
| 35 | + emptyOnly: ((x) => true && x.length <= 0 ? x : throw FormatException("Expected bounded string"))(json["emptyOnly"]), | |
| 36 | + intersection: ((x) => RegExp("^[a-z]+\u0024").hasMatch(x) ? x : throw FormatException("Expected matching string"))(((x) => x.length >= 4 && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["intersection"])), | |
| 34 | 37 | inUnion: json["inUnion"], |
| 35 | 38 | maxlength: ((x) => true && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["maxlength"]), |
| 36 | 39 | minlength: ((x) => x.length >= 3 && true ? x : throw FormatException("Expected bounded string"))(json["minlength"]), |
| 37 | 40 | minMaxIntersection: ((x) => x.length >= 3 && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["minMaxIntersection"]), |
| 38 | - minmaxlength: ((x) => x.length >= 3 && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["minmaxlength"]), | |
| 41 | + minmaxlength: ((x) => RegExp("^[a-z]+\u0024").hasMatch(x) ? x : throw FormatException("Expected matching string"))(((x) => x.length >= 3 && x.length <= 5 ? x : throw FormatException("Expected bounded string"))(json["minmaxlength"])), | |
| 39 | 42 | minMaxUnion: json["minMaxUnion"], |
| 40 | - union: ((x) => x.length >= 3 && x.length <= 6 ? x : throw FormatException("Expected bounded string"))(json["union"]), | |
| 43 | + union: ((x) => RegExp("^[a-z]+\u0024").hasMatch(x) ? x : throw FormatException("Expected matching string"))(((x) => x.length >= 3 && x.length <= 6 ? x : throw FormatException("Expected bounded string"))(json["union"])), | |
| 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+11 −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(), |
| @@ -20,6 +21,12 @@ defmodule TopLevel do | ||
| 20 | 21 | union: String.t() |
| 21 | 22 | } |
| 22 | 23 | |
| 24 | + def decode_empty_only(value) when is_binary(value), do: value | |
| 25 | + def decode_empty_only(_), do: {:error, "Unexpected type when decoding TopLevel.empty_only"} | |
| 26 | + | |
| 27 | + def encode_empty_only(value) when is_binary(value), do: value | |
| 28 | + def encode_empty_only(_), do: {:error, "Unexpected type when encoding TopLevel.empty_only"} | |
| 29 | + | |
| 23 | 30 | def decode_intersection(value) when is_binary(value), do: value |
| 24 | 31 | def decode_intersection(_), do: {:error, "Unexpected type when decoding TopLevel.intersection"} |
| 25 | 32 | |
| @@ -64,6 +71,7 @@ defmodule TopLevel do | ||
| 64 | 71 | |
| 65 | 72 | def from_map(m) do |
| 66 | 73 | %TopLevel{ |
| 74 | + empty_only: decode_empty_only(m["emptyOnly"]), | |
| 67 | 75 | intersection: decode_intersection(m["intersection"]), |
| 68 | 76 | in_union: Map.fetch!(m, "inUnion"), |
| 69 | 77 | maxlength: decode_maxlength(m["maxlength"]), |
| @@ -83,6 +91,7 @@ defmodule TopLevel do | ||
| 83 | 91 | |
| 84 | 92 | def to_map(struct) do |
| 85 | 93 | %{ |
| 94 | + "emptyOnly" => struct.empty_only, | |
| 86 | 95 | "intersection" => struct.intersection, |
| 87 | 96 | "inUnion" => struct.in_union, |
| 88 | 97 | "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 |
| @@ -52,6 +53,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r) | ||
| 52 | 53 | quickType : Jdec.Decoder QuickType |
| 53 | 54 | quickType = |
| 54 | 55 | Jdec.succeed QuickType |
| 56 | + |> Jpipe.required "emptyOnly" Jdec.string | |
| 55 | 57 | |> Jpipe.required "intersection" Jdec.string |
| 56 | 58 | |> Jpipe.required "inUnion" inUnion |
| 57 | 59 | |> Jpipe.required "maxlength" Jdec.string |
| @@ -64,7 +66,8 @@ quickType = | ||
| 64 | 66 | encodeQuickType : QuickType -> Jenc.Value |
| 65 | 67 | encodeQuickType x = |
| 66 | 68 | Jenc.object |
| 67 | - [ ("intersection", Jenc.string x.intersection) | |
| 69 | + [ ("emptyOnly", Jenc.string x.emptyOnly) | |
| 70 | + , ("intersection", Jenc.string x.intersection) | |
| 68 | 71 | , ("inUnion", encodeInUnion x.inUnion) |
| 69 | 72 | , ("maxlength", Jenc.string x.maxlength) |
| 70 | 73 | , ("minlength", Jenc.string x.minlength) |
Mschema-flowdefault / TopLevel.js+6 −4
| @@ -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; |
| @@ -209,14 +210,15 @@ function r(name: string) { | ||
| 209 | 210 | |
| 210 | 211 | const typeMap: any = { |
| 211 | 212 | "TopLevel": o([ |
| 212 | - { json: "intersection", js: "intersection", typ: s("", 4, 5) }, | |
| 213 | - { json: "inUnion", js: "inUnion", typ: u(3.14, s("", 3, 5)) }, | |
| 213 | + { json: "emptyOnly", js: "emptyOnly", typ: s("", undefined, 0) }, | |
| 214 | + { json: "intersection", js: "intersection", typ: s(p("^[a-z]+$"), 4, 5) }, | |
| 215 | + { json: "inUnion", js: "inUnion", typ: u(3.14, s(p("^[a-z]+$"), 3, 5)) }, | |
| 214 | 216 | { json: "maxlength", js: "maxlength", typ: s("", undefined, 5) }, |
| 215 | 217 | { json: "minlength", js: "minlength", typ: s("", 3, undefined) }, |
| 216 | 218 | { json: "minMaxIntersection", js: "minMaxIntersection", typ: s("", 3, 5) }, |
| 217 | - { json: "minmaxlength", js: "minmaxlength", typ: s("", 3, 5) }, | |
| 219 | + { json: "minmaxlength", js: "minmaxlength", typ: s(p("^[a-z]+$"), 3, 5) }, | |
| 218 | 220 | { json: "minMaxUnion", js: "minMaxUnion", typ: "" }, |
| 219 | - { json: "union", js: "union", typ: s("", 3, 6) }, | |
| 221 | + { json: "union", js: "union", typ: s(p("^[a-z]+$"), 3, 6) }, | |
| 220 | 222 | ], "any"), |
| 221 | 223 | }; |
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-javascript-prop-typesdefault / toplevel.js+5 −4
| @@ -14,14 +14,15 @@ import PropTypes from "prop-types"; | ||
| 14 | 14 | |
| 15 | 15 | let _TopLevel; |
| 16 | 16 | _TopLevel = PropTypes.shape({ |
| 17 | - "intersection": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 4 && value.length <= 5) ? null : new Error("Expected bounded string"); }, | |
| 18 | - "inUnion": PropTypes.oneOfType([PropTypes.number, (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 5) ? null : new Error("Expected bounded string"); }]), | |
| 17 | + "emptyOnly": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length <= 0) ? null : new Error("Expected bounded string"); }, | |
| 18 | + "intersection": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 4 && value.length <= 5 && new RegExp("^[a-z]+$").test(value)) ? null : new Error("Expected bounded string"); }, | |
| 19 | + "inUnion": PropTypes.oneOfType([PropTypes.number, (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 5 && new RegExp("^[a-z]+$").test(value)) ? null : new Error("Expected bounded string"); }]), | |
| 19 | 20 | "maxlength": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length <= 5) ? null : new Error("Expected bounded string"); }, |
| 20 | 21 | "minlength": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3) ? null : new Error("Expected bounded string"); }, |
| 21 | 22 | "minMaxIntersection": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 5) ? null : new Error("Expected bounded string"); }, |
| 22 | - "minmaxlength": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 5) ? null : new Error("Expected bounded string"); }, | |
| 23 | + "minmaxlength": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 5 && new RegExp("^[a-z]+$").test(value)) ? null : new Error("Expected bounded string"); }, | |
| 23 | 24 | "minMaxUnion": PropTypes.string, |
| 24 | - "union": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 6) ? null : new Error("Expected bounded string"); }, | |
| 25 | + "union": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && value.length >= 3 && value.length <= 6 && new RegExp("^[a-z]+$").test(value)) ? null : new Error("Expected bounded string"); }, | |
| 25 | 26 | }); |
| 26 | 27 | |
| 27 | 28 | export const TopLevel = _TopLevel; |
Mschema-javascriptdefault / TopLevel.js+5 −4
| @@ -193,14 +193,15 @@ function r(name) { | ||
| 193 | 193 | |
| 194 | 194 | const typeMap = { |
| 195 | 195 | "TopLevel": o([ |
| 196 | - { json: "intersection", js: "intersection", typ: s("", 4, 5) }, | |
| 197 | - { json: "inUnion", js: "inUnion", typ: u(3.14, s("", 3, 5)) }, | |
| 196 | + { json: "emptyOnly", js: "emptyOnly", typ: s("", undefined, 0) }, | |
| 197 | + { json: "intersection", js: "intersection", typ: s(p("^[a-z]+$"), 4, 5) }, | |
| 198 | + { json: "inUnion", js: "inUnion", typ: u(3.14, s(p("^[a-z]+$"), 3, 5)) }, | |
| 198 | 199 | { json: "maxlength", js: "maxlength", typ: s("", undefined, 5) }, |
| 199 | 200 | { json: "minlength", js: "minlength", typ: s("", 3, undefined) }, |
| 200 | 201 | { json: "minMaxIntersection", js: "minMaxIntersection", typ: s("", 3, 5) }, |
| 201 | - { json: "minmaxlength", js: "minmaxlength", typ: s("", 3, 5) }, | |
| 202 | + { json: "minmaxlength", js: "minmaxlength", typ: s(p("^[a-z]+$"), 3, 5) }, | |
| 202 | 203 | { json: "minMaxUnion", js: "minMaxUnion", typ: "" }, |
| 203 | - { json: "union", js: "union", typ: s("", 3, 6) }, | |
| 204 | + { json: "union", js: "union", typ: s(p("^[a-z]+$"), 3, 6) }, | |
| 204 | 205 | ], "any"), |
| 205 | 206 | }; |
Mschema-kotlin-jacksondefault / TopLevel.kt+7 −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, |
| 36 | 39 | |
| @@ -56,16 +59,20 @@ data class TopLevel ( | ||
| 56 | 59 | val union: String |
| 57 | 60 | ) { |
| 58 | 61 | init { |
| 62 | + require(emptyOnly.length <= 0) | |
| 59 | 63 | require(intersection.length >= 4) |
| 60 | 64 | require(intersection.length <= 5) |
| 65 | + require(Regex("^[a-z]+\$").containsMatchIn(intersection)) | |
| 61 | 66 | require(maxlength.length <= 5) |
| 62 | 67 | require(minlength.length >= 3) |
| 63 | 68 | require(minMaxIntersection.length >= 3) |
| 64 | 69 | require(minMaxIntersection.length <= 5) |
| 65 | 70 | require(minmaxlength.length >= 3) |
| 66 | 71 | require(minmaxlength.length <= 5) |
| 72 | + require(Regex("^[a-z]+\$").containsMatchIn(minmaxlength)) | |
| 67 | 73 | require(union.length >= 3) |
| 68 | 74 | require(union.length <= 6) |
| 75 | + require(Regex("^[a-z]+\$").containsMatchIn(union)) | |
| 69 | 76 | } |
| 70 | 77 | fun toJson() = mapper.writeValueAsString(this) |
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-objective-cdefault / QTTopLevel.h+1 −0
| @@ -19,6 +19,7 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding en | ||
| 19 | 19 | #pragma mark - Object interfaces |
| 20 | 20 | |
| 21 | 21 | @interface QTTopLevel : NSObject |
| 22 | +@property (nonatomic, copy) NSString *emptyOnly; | |
| 22 | 23 | @property (nonatomic, copy) NSString *intersection; |
| 23 | 24 | @property (nonatomic, copy) id inUnion; |
| 24 | 25 | @property (nonatomic, copy) NSString *maxlength; |
Mschema-objective-cdefault / QTTopLevel.m+6 −0
| @@ -54,6 +54,7 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 54 | 54 | { |
| 55 | 55 | static NSDictionary<NSString *, NSString *> *properties; |
| 56 | 56 | return properties = properties ? properties : @{ |
| 57 | + @"emptyOnly": @"emptyOnly", | |
| 57 | 58 | @"intersection": @"intersection", |
| 58 | 59 | @"inUnion": @"inUnion", |
| 59 | 60 | @"maxlength": @"maxlength", |
| @@ -83,6 +84,9 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 83 | 84 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 84 | 85 | { |
| 85 | 86 | if (self = [super init]) { |
| 87 | + if ([dict[@"emptyOnly"] length] > 0) return nil; | |
| 88 | + if (![dict[@"emptyOnly"] isKindOfClass:NSString.class]) return nil; | |
| 89 | + if (dict[@"intersection"] && [dict[@"intersection"] rangeOfString:@"^[a-z]+$" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 86 | 90 | if (dict[@"intersection"] && [dict[@"intersection"] length] < 4) return nil; |
| 87 | 91 | if ([dict[@"intersection"] length] > 5) return nil; |
| 88 | 92 | if (![dict[@"intersection"] isKindOfClass:NSString.class]) return nil; |
| @@ -93,10 +97,12 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 93 | 97 | if (dict[@"minMaxIntersection"] && [dict[@"minMaxIntersection"] length] < 3) return nil; |
| 94 | 98 | if ([dict[@"minMaxIntersection"] length] > 5) return nil; |
| 95 | 99 | if (![dict[@"minMaxIntersection"] isKindOfClass:NSString.class]) return nil; |
| 100 | + if (dict[@"minmaxlength"] && [dict[@"minmaxlength"] rangeOfString:@"^[a-z]+$" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 96 | 101 | if (dict[@"minmaxlength"] && [dict[@"minmaxlength"] length] < 3) return nil; |
| 97 | 102 | if ([dict[@"minmaxlength"] length] > 5) return nil; |
| 98 | 103 | if (![dict[@"minmaxlength"] isKindOfClass:NSString.class]) return nil; |
| 99 | 104 | if (![dict[@"minMaxUnion"] isKindOfClass:NSString.class]) return nil; |
| 105 | + if (dict[@"union"] && [dict[@"union"] rangeOfString:@"^[a-z]+$" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 100 | 106 | if (dict[@"union"] && [dict[@"union"] length] < 3) return nil; |
| 101 | 107 | if ([dict[@"union"] length] > 6) return nil; |
| 102 | 108 | if (![dict[@"union"] isKindOfClass:NSString.class]) return nil; |
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+8 −5
| @@ -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 | |
| @@ -22,7 +22,7 @@ end | ||
| 22 | 22 | |
| 23 | 23 | class InUnion < Dry::Struct |
| 24 | 24 | attribute :double, Types::Double.optional |
| 25 | - attribute :string, Types::String.constrained(min_size: 3, max_size: 5).optional | |
| 25 | + attribute :string, Types::String.constrained(min_size: 3, max_size: 5).constrained(format: Regexp.new("^[a-z]+$")).optional | |
| 26 | 26 | |
| 27 | 27 | def self.from_dynamic!(d) |
| 28 | 28 | if schema.key(:double).type.right.valid? d |
| @@ -52,18 +52,20 @@ class InUnion < Dry::Struct | ||
| 52 | 52 | end |
| 53 | 53 | |
| 54 | 54 | class TopLevel < Dry::Struct |
| 55 | - attribute :intersection, Types::String.constrained(min_size: 4, max_size: 5) | |
| 55 | + attribute :empty_only, Types::String.constrained(max_size: 0) | |
| 56 | + attribute :intersection, Types::String.constrained(min_size: 4, max_size: 5).constrained(format: Regexp.new("^[a-z]+$")) | |
| 56 | 57 | attribute :in_union, Types.Instance(InUnion) |
| 57 | 58 | attribute :maxlength, Types::String.constrained(max_size: 5) |
| 58 | 59 | attribute :minlength, Types::String.constrained(min_size: 3) |
| 59 | 60 | attribute :min_max_intersection, Types::String.constrained(min_size: 3, max_size: 5) |
| 60 | - attribute :minmaxlength, Types::String.constrained(min_size: 3, max_size: 5) | |
| 61 | + attribute :minmaxlength, Types::String.constrained(min_size: 3, max_size: 5).constrained(format: Regexp.new("^[a-z]+$")) | |
| 61 | 62 | attribute :min_max_union, Types::String |
| 62 | - attribute :union, Types::String.constrained(min_size: 3, max_size: 6) | |
| 63 | + attribute :union, Types::String.constrained(min_size: 3, max_size: 6).constrained(format: Regexp.new("^[a-z]+$")) | |
| 63 | 64 | |
| 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-effect-schemadefault / TopLevel.ts+5 −4
| @@ -2,12 +2,13 @@ import * as S from "effect/Schema"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | - "intersection": S.String.pipe(S.minLength(4)).pipe(S.maxLength(5)), | |
| 6 | - "inUnion": S.Union(S.Number, S.String.pipe(S.minLength(3)).pipe(S.maxLength(5))), | |
| 5 | + "emptyOnly": S.String.pipe(S.maxLength(0)), | |
| 6 | + "intersection": S.String.pipe(S.minLength(4)).pipe(S.maxLength(5)).pipe(S.pattern(new RegExp("^[a-z]+$"))), | |
| 7 | + "inUnion": S.Union(S.Number, S.String.pipe(S.minLength(3)).pipe(S.maxLength(5)).pipe(S.pattern(new RegExp("^[a-z]+$")))), | |
| 7 | 8 | "maxlength": S.String.pipe(S.maxLength(5)), |
| 8 | 9 | "minlength": S.String.pipe(S.minLength(3)), |
| 9 | 10 | "minMaxIntersection": S.String.pipe(S.minLength(3)).pipe(S.maxLength(5)), |
| 10 | - "minmaxlength": S.String.pipe(S.minLength(3)).pipe(S.maxLength(5)), | |
| 11 | + "minmaxlength": S.String.pipe(S.minLength(3)).pipe(S.maxLength(5)).pipe(S.pattern(new RegExp("^[a-z]+$"))), | |
| 11 | 12 | "minMaxUnion": S.String, |
| 12 | - "union": S.String.pipe(S.minLength(3)).pipe(S.maxLength(6)), | |
| 13 | + "union": S.String.pipe(S.minLength(3)).pipe(S.maxLength(6)).pipe(S.pattern(new RegExp("^[a-z]+$"))), | |
| 13 | 14 | }) {} |
Mschema-typescript-zoddefault / TopLevel.ts+5 −4
| @@ -2,13 +2,14 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | - "intersection": z.string().min(4).max(5), | |
| 6 | - "inUnion": z.union([z.number(), z.string().min(3).max(5)]), | |
| 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]+$"))]), | |
| 7 | 8 | "maxlength": z.string().max(5), |
| 8 | 9 | "minlength": z.string().min(3), |
| 9 | 10 | "minMaxIntersection": z.string().min(3).max(5), |
| 10 | - "minmaxlength": 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().min(3).max(6), | |
| 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+6 −4
| @@ -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; |
| @@ -209,13 +210,14 @@ function r(name: string) { | ||
| 209 | 210 | |
| 210 | 211 | const typeMap: any = { |
| 211 | 212 | "TopLevel": o([ |
| 212 | - { json: "intersection", js: "intersection", typ: s("", 4, 5) }, | |
| 213 | - { json: "inUnion", js: "inUnion", typ: u(3.14, s("", 3, 5)) }, | |
| 213 | + { json: "emptyOnly", js: "emptyOnly", typ: s("", undefined, 0) }, | |
| 214 | + { json: "intersection", js: "intersection", typ: s(p("^[a-z]+$"), 4, 5) }, | |
| 215 | + { json: "inUnion", js: "inUnion", typ: u(3.14, s(p("^[a-z]+$"), 3, 5)) }, | |
| 214 | 216 | { json: "maxlength", js: "maxlength", typ: s("", undefined, 5) }, |
| 215 | 217 | { json: "minlength", js: "minlength", typ: s("", 3, undefined) }, |
| 216 | 218 | { json: "minMaxIntersection", js: "minMaxIntersection", typ: s("", 3, 5) }, |
| 217 | - { json: "minmaxlength", js: "minmaxlength", typ: s("", 3, 5) }, | |
| 219 | + { json: "minmaxlength", js: "minmaxlength", typ: s(p("^[a-z]+$"), 3, 5) }, | |
| 218 | 220 | { json: "minMaxUnion", js: "minMaxUnion", typ: "" }, |
| 219 | - { json: "union", js: "union", typ: s("", 3, 6) }, | |
| 221 | + { json: "union", js: "union", typ: s(p("^[a-z]+$"), 3, 6) }, | |
| 220 | 222 | ], "any"), |
| 221 | 223 | }; |
Test case
35 generated files · +191 −17test/inputs/schema/pattern.schema
Mschema-cjsondefault / TopLevel.c+20 −0
| @@ -22,6 +22,17 @@ struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | ||
| 22 | 22 | if (NULL != j) { |
| 23 | 23 | if (NULL != (x = cJSON_malloc(sizeof(struct TopLevel)))) { |
| 24 | 24 | memset(x, 0, sizeof(struct TopLevel)); |
| 25 | + if (!cJSON_HasObjectItem(j, "escaped")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 26 | + if (cJSON_HasObjectItem(j, "escaped")) { | |
| 27 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "escaped"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 28 | + regex_t regex; regcomp(®ex, "^\\d+\\.[a-z]+$", REG_EXTENDED); if (regexec(®ex, cJSON_GetObjectItemCaseSensitive(j, "escaped")->valuestring, 0, NULL, 0)) { regfree(®ex); cJSON_DeleteTopLevel(x); return NULL; } regfree(®ex); | |
| 29 | + x->escaped = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "escaped"))); | |
| 30 | + } | |
| 31 | + else { | |
| 32 | + if (NULL != (x->escaped = cJSON_malloc(sizeof(char)))) { | |
| 33 | + x->escaped[0] = '\0'; | |
| 34 | + } | |
| 35 | + } | |
| 25 | 36 | if (!cJSON_HasObjectItem(j, "pattern1")) { cJSON_DeleteTopLevel(x); return NULL; } |
| 26 | 37 | if (cJSON_HasObjectItem(j, "pattern1")) { |
| 27 | 38 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "pattern1"))) { cJSON_DeleteTopLevel(x); return NULL; } |
| @@ -64,6 +75,12 @@ cJSON * cJSON_CreateTopLevel(const struct TopLevel * x) { | ||
| 64 | 75 | cJSON * j = NULL; |
| 65 | 76 | if (NULL != x) { |
| 66 | 77 | if (NULL != (j = cJSON_CreateObject())) { |
| 78 | + if (NULL != x->escaped) { | |
| 79 | + cJSON_AddStringToObject(j, "escaped", x->escaped); | |
| 80 | + } | |
| 81 | + else { | |
| 82 | + cJSON_AddStringToObject(j, "escaped", ""); | |
| 83 | + } | |
| 67 | 84 | if (NULL != x->pattern1) { |
| 68 | 85 | cJSON_AddStringToObject(j, "pattern1", x->pattern1); |
| 69 | 86 | } |
| @@ -101,6 +118,9 @@ char * cJSON_PrintTopLevel(const struct TopLevel * x) { | ||
| 101 | 118 | |
| 102 | 119 | void cJSON_DeleteTopLevel(struct TopLevel * x) { |
| 103 | 120 | if (NULL != x) { |
| 121 | + if (NULL != x->escaped) { | |
| 122 | + cJSON_free(x->escaped); | |
| 123 | + } | |
| 104 | 124 | if (NULL != x->pattern1) { |
| 105 | 125 | cJSON_free(x->pattern1); |
| 106 | 126 | } |
Mschema-cjsondefault / TopLevel.h+1 −0
| @@ -36,6 +36,7 @@ extern "C" { | ||
| 36 | 36 | #endif |
| 37 | 37 | |
| 38 | 38 | struct TopLevel { |
| 39 | + char * escaped; | |
| 39 | 40 | char * pattern1; |
| 40 | 41 | char * pattern2; |
| 41 | 42 | char * top_level_union; |
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; } |
| @@ -200,6 +207,7 @@ namespace quicktype { | ||
| 200 | 207 | |
| 201 | 208 | inline void from_json(const json & j, TopLevel& x) { |
| 202 | 209 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 210 | + x.set_escaped(j.at("escaped").get<std::string>()); | |
| 203 | 211 | x.set_pattern1(j.at("pattern1").get<std::string>()); |
| 204 | 212 | x.set_pattern2(j.at("pattern2").get<std::string>()); |
| 205 | 213 | x.set_top_level_union(j.at("union").get<std::string>()); |
| @@ -207,6 +215,7 @@ namespace quicktype { | ||
| 207 | 215 | |
| 208 | 216 | inline void to_json(json & j, const TopLevel & x) { |
| 209 | 217 | j = json::object(); |
| 218 | + j["escaped"] = x.get_escaped(); | |
| 210 | 219 | j["pattern1"] = x.get_pattern1(); |
| 211 | 220 | j["pattern2"] = x.get_pattern2(); |
| 212 | 221 | j["union"] = x.get_top_level_union(); |
Mschema-crystaldefault / TopLevel.cr+2 −0
| @@ -3,6 +3,8 @@ require "json" | ||
| 3 | 3 | class TopLevel |
| 4 | 4 | include JSON::Serializable |
| 5 | 5 | |
| 6 | + property escaped : String | |
| 7 | + | |
| 6 | 8 | property pattern1 : String |
| 7 | 9 | |
| 8 | 10 | property pattern2 : String |
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: ((x) => RegExp("^\\d+\\.[a-z]+\u0024").hasMatch(x) ? x : throw FormatException("Expected matching string"))(json["escaped"]), | |
| 23 | 26 | pattern1: ((x) => RegExp("a[.]*").hasMatch(x) ? x : throw FormatException("Expected matching string"))(json["pattern1"]), |
| 24 | 27 | pattern2: ((x) => RegExp("b[.]*").hasMatch(x) ? x : throw FormatException("Expected matching string"))(json["pattern2"]), |
| 25 | 28 | union: ((x) => RegExp("(b[.]*)|(c[.]*)").hasMatch(x) ? x : throw FormatException("Expected matching string"))(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+11 −2
| @@ -6,15 +6,22 @@ | ||
| 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() |
| 16 | 17 | } |
| 17 | 18 | |
| 19 | + def decode_escaped(value) when is_binary(value), do: value | |
| 20 | + def decode_escaped(_), do: {:error, "Unexpected type when decoding TopLevel.escaped"} | |
| 21 | + | |
| 22 | + def encode_escaped(value) when is_binary(value), do: value | |
| 23 | + def encode_escaped(_), do: {:error, "Unexpected type when encoding TopLevel.escaped"} | |
| 24 | + | |
| 18 | 25 | def decode_pattern1(value) when is_binary(value), do: value |
| 19 | 26 | def decode_pattern1(_), do: {:error, "Unexpected type when decoding TopLevel.pattern1"} |
| 20 | 27 | |
| @@ -35,6 +42,7 @@ defmodule TopLevel do | ||
| 35 | 42 | |
| 36 | 43 | def from_map(m) do |
| 37 | 44 | %TopLevel{ |
| 45 | + escaped: decode_escaped(m["escaped"]), | |
| 38 | 46 | pattern1: decode_pattern1(m["pattern1"]), |
| 39 | 47 | pattern2: decode_pattern2(m["pattern2"]), |
| 40 | 48 | union: decode_union(m["union"]), |
| @@ -49,6 +57,7 @@ defmodule TopLevel do | ||
| 49 | 57 | |
| 50 | 58 | def to_map(struct) do |
| 51 | 59 | %{ |
| 60 | + "escaped" => struct.escaped, | |
| 52 | 61 | "pattern1" => struct.pattern1, |
| 53 | 62 | "pattern2" => struct.pattern2, |
| 54 | 63 | "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 | } |
| @@ -42,6 +43,7 @@ quickTypeToString r = Jenc.encode 0 (encodeQuickType r) | ||
| 42 | 43 | quickType : Jdec.Decoder QuickType |
| 43 | 44 | quickType = |
| 44 | 45 | Jdec.succeed QuickType |
| 46 | + |> Jpipe.required "escaped" Jdec.string | |
| 45 | 47 | |> Jpipe.required "pattern1" Jdec.string |
| 46 | 48 | |> Jpipe.required "pattern2" Jdec.string |
| 47 | 49 | |> Jpipe.required "union" Jdec.string |
| @@ -49,7 +51,8 @@ quickType = | ||
| 49 | 51 | encodeQuickType : QuickType -> Jenc.Value |
| 50 | 52 | encodeQuickType x = |
| 51 | 53 | Jenc.object |
| 52 | - [ ("pattern1", Jenc.string x.pattern1) | |
| 54 | + [ ("escaped", Jenc.string x.escaped) | |
| 55 | + , ("pattern1", Jenc.string x.pattern1) | |
| 53 | 56 | , ("pattern2", Jenc.string x.pattern2) |
| 54 | 57 | , ("union", Jenc.string x.union) |
| 55 | 58 | ] |
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; |
| @@ -202,6 +203,7 @@ function r(name: string) { | ||
| 202 | 203 | |
| 203 | 204 | const typeMap: any = { |
| 204 | 205 | "TopLevel": o([ |
| 206 | + { json: "escaped", js: "escaped", typ: p("^\\d+\\.[a-z]+$") }, | |
| 205 | 207 | { json: "pattern1", js: "pattern1", typ: p("a[.]*") }, |
| 206 | 208 | { json: "pattern2", js: "pattern2", typ: p("b[.]*") }, |
| 207 | 209 | { json: "union", js: "union", typ: p("(b[.]*)|(c[.]*)") }, |
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-javascript-prop-typesdefault / toplevel.js+1 −0
| @@ -14,6 +14,7 @@ import PropTypes from "prop-types"; | ||
| 14 | 14 | |
| 15 | 15 | let _TopLevel; |
| 16 | 16 | _TopLevel = PropTypes.shape({ |
| 17 | + "escaped": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && new RegExp("^\\d+\\.[a-z]+$").test(value)) ? null : new Error("Expected bounded string"); }, | |
| 17 | 18 | "pattern1": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && new RegExp("a[.]*").test(value)) ? null : new Error("Expected bounded string"); }, |
| 18 | 19 | "pattern2": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && new RegExp("b[.]*").test(value)) ? null : new Error("Expected bounded string"); }, |
| 19 | 20 | "union": (props, name) => { const value = props[name]; return value == null || (typeof value === 'string' && new RegExp("(b[.]*)|(c[.]*)").test(value)) ? null : new Error("Expected bounded string"); }, |
Mschema-javascriptdefault / TopLevel.js+1 −0
| @@ -193,6 +193,7 @@ function r(name) { | ||
| 193 | 193 | |
| 194 | 194 | const typeMap = { |
| 195 | 195 | "TopLevel": o([ |
| 196 | + { json: "escaped", js: "escaped", typ: p("^\\d+\\.[a-z]+$") }, | |
| 196 | 197 | { json: "pattern1", js: "pattern1", typ: p("a[.]*") }, |
| 197 | 198 | { json: "pattern2", js: "pattern2", typ: p("b[.]*") }, |
| 198 | 199 | { json: "union", js: "union", typ: p("(b[.]*)|(c[.]*)") }, |
Mschema-kotlin-jacksondefault / TopLevel.kt+4 −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, |
| 24 | 27 | |
| @@ -29,6 +32,7 @@ data class TopLevel ( | ||
| 29 | 32 | val union: String |
| 30 | 33 | ) { |
| 31 | 34 | init { |
| 35 | + require(Regex("^\\d+\\.[a-z]+\$").containsMatchIn(escaped)) | |
| 32 | 36 | require(Regex("a[.]*").containsMatchIn(pattern1)) |
| 33 | 37 | require(Regex("b[.]*").containsMatchIn(pattern2)) |
| 34 | 38 | require(Regex("(b[.]*)|(c[.]*)").containsMatchIn(union)) |
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-objective-cdefault / QTTopLevel.h+1 −0
| @@ -19,6 +19,7 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding en | ||
| 19 | 19 | #pragma mark - Object interfaces |
| 20 | 20 | |
| 21 | 21 | @interface QTTopLevel : NSObject |
| 22 | +@property (nonatomic, copy) NSString *escaped; | |
| 22 | 23 | @property (nonatomic, copy) NSString *pattern1; |
| 23 | 24 | @property (nonatomic, copy) NSString *pattern2; |
| 24 | 25 | @property (nonatomic, copy) NSString *qtTopLevelUnion; |
Mschema-objective-cdefault / QTTopLevel.m+3 −0
| @@ -54,6 +54,7 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 54 | 54 | { |
| 55 | 55 | static NSDictionary<NSString *, NSString *> *properties; |
| 56 | 56 | return properties = properties ? properties : @{ |
| 57 | + @"escaped": @"escaped", | |
| 57 | 58 | @"pattern1": @"pattern1", |
| 58 | 59 | @"pattern2": @"pattern2", |
| 59 | 60 | @"union": @"qtTopLevelUnion", |
| @@ -78,6 +79,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 78 | 79 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 79 | 80 | { |
| 80 | 81 | if (self = [super init]) { |
| 82 | + if (dict[@"escaped"] && [dict[@"escaped"] rangeOfString:@"^\\d+\\.[a-z]+$" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 83 | + if (![dict[@"escaped"] isKindOfClass:NSString.class]) return nil; | |
| 81 | 84 | if (dict[@"pattern1"] && [dict[@"pattern1"] rangeOfString:@"a[.]*" options:NSRegularExpressionSearch].location == NSNotFound) return nil; |
| 82 | 85 | if (![dict[@"pattern1"] isKindOfClass:NSString.class]) return nil; |
| 83 | 86 | if (dict[@"pattern2"] && [dict[@"pattern2"] rangeOfString:@"b[.]*" options:NSRegularExpressionSearch].location == NSNotFound) return nil; |
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.constrained(format: Regexp.new("^\\d+\\.[a-z]+$")) | |
| 23 | 24 | attribute :pattern1, Types::String.constrained(format: Regexp.new("a[.]*")) |
| 24 | 25 | attribute :pattern2, Types::String.constrained(format: Regexp.new("b[.]*")) |
| 25 | 26 | attribute :union, Types::String.constrained(format: Regexp.new("(b[.]*)|(c[.]*)")) |
| @@ -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-effect-schemadefault / TopLevel.ts+1 −0
| @@ -2,6 +2,7 @@ import * as S from "effect/Schema"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | + "escaped": S.String.pipe(S.pattern(new RegExp("^\\d+\\.[a-z]+$"))), | |
| 5 | 6 | "pattern1": S.String.pipe(S.pattern(new RegExp("a[.]*"))), |
| 6 | 7 | "pattern2": S.String.pipe(S.pattern(new RegExp("b[.]*"))), |
| 7 | 8 | "union": S.String.pipe(S.pattern(new RegExp("(b[.]*)|(c[.]*)"))), |
Mschema-typescript-zoddefault / TopLevel.ts+1 −0
| @@ -2,6 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | + "escaped": z.string().regex(new RegExp("^\\d+\\.[a-z]+$")), | |
| 5 | 6 | "pattern1": z.string().regex(new RegExp("a[.]*")), |
| 6 | 7 | "pattern2": z.string().regex(new RegExp("b[.]*")), |
| 7 | 8 | "union": z.string().regex(new RegExp("(b[.]*)|(c[.]*)")), |
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; |
| @@ -202,6 +203,7 @@ function r(name: string) { | ||
| 202 | 203 | |
| 203 | 204 | const typeMap: any = { |
| 204 | 205 | "TopLevel": o([ |
| 206 | + { json: "escaped", js: "escaped", typ: p("^\\d+\\.[a-z]+$") }, | |
| 205 | 207 | { json: "pattern1", js: "pattern1", typ: p("a[.]*") }, |
| 206 | 208 | { json: "pattern2", js: "pattern2", typ: p("b[.]*") }, |
| 207 | 209 | { json: "union", js: "union", typ: p("(b[.]*)|(c[.]*)") }, |
No generated files match these filters.