Test case
2 generated files · +320 −0test/inputs/schema/minmaxlength.schema
Aschema-cjsondefault / TopLevel.c+248 −0
| @@ -0,0 +1,248 @@ | ||
| 1 | +/** | |
| 2 | + * TopLevel.c | |
| 3 | + * This file has been autogenerated using quicktype https://github.com/quicktype/quicktype - DO NOT EDIT | |
| 4 | + */ | |
| 5 | + | |
| 6 | +#include "TopLevel.h" | |
| 7 | + | |
| 8 | +struct InUnion * cJSON_GetInUnionValue(const cJSON * j) { | |
| 9 | + struct InUnion * x = cJSON_malloc(sizeof(struct InUnion)); | |
| 10 | + if (NULL != x) { | |
| 11 | + memset(x, 0, sizeof(struct InUnion)); | |
| 12 | + if (cJSON_IsNumber(j)) { | |
| 13 | + x->type = cJSON_Number; | |
| 14 | + x->value.number = cJSON_GetNumberValue(j); | |
| 15 | + } | |
| 16 | + else if (cJSON_IsString(j)) { | |
| 17 | + x->type = cJSON_String; | |
| 18 | + x->value.string = strdup(cJSON_GetStringValue(j)); | |
| 19 | + } | |
| 20 | + } | |
| 21 | + return x; | |
| 22 | +} | |
| 23 | + | |
| 24 | +cJSON * cJSON_CreateInUnion(const struct InUnion * x) { | |
| 25 | + cJSON * j = NULL; | |
| 26 | + if (NULL != x) { | |
| 27 | + if (cJSON_Number == x->type) { | |
| 28 | + j = cJSON_CreateNumber(x->value.number); | |
| 29 | + } | |
| 30 | + else if (cJSON_String == x->type) { | |
| 31 | + j = cJSON_CreateString(x->value.string); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + return j; | |
| 35 | +} | |
| 36 | + | |
| 37 | +void cJSON_DeleteInUnion(struct InUnion * x) { | |
| 38 | + if (NULL != x) { | |
| 39 | + if (cJSON_Number == x->type) { | |
| 40 | + } | |
| 41 | + else if (cJSON_String == x->type) { | |
| 42 | + cJSON_free(x->value.string); | |
| 43 | + } | |
| 44 | + cJSON_free(x); | |
| 45 | + } | |
| 46 | +} | |
| 47 | + | |
| 48 | +struct TopLevel * cJSON_ParseTopLevel(const char * s) { | |
| 49 | + struct TopLevel * x = NULL; | |
| 50 | + if (NULL != s) { | |
| 51 | + cJSON * j = cJSON_Parse(s); | |
| 52 | + if (NULL != j) { | |
| 53 | + x = cJSON_GetTopLevelValue(j); | |
| 54 | + cJSON_Delete(j); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + return x; | |
| 58 | +} | |
| 59 | + | |
| 60 | +struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | |
| 61 | + struct TopLevel * x = NULL; | |
| 62 | + if (NULL != j) { | |
| 63 | + if (NULL != (x = cJSON_malloc(sizeof(struct TopLevel)))) { | |
| 64 | + memset(x, 0, sizeof(struct TopLevel)); | |
| 65 | + if (!cJSON_HasObjectItem(j, "intersection")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 66 | + if (cJSON_HasObjectItem(j, "intersection")) { | |
| 67 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "intersection"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 68 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "intersection")->valuestring) < 4) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 69 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "intersection")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 70 | + x->intersection = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "intersection"))); | |
| 71 | + } | |
| 72 | + else { | |
| 73 | + if (NULL != (x->intersection = cJSON_malloc(sizeof(char)))) { | |
| 74 | + x->intersection[0] = '\0'; | |
| 75 | + } | |
| 76 | + } | |
| 77 | + if (!cJSON_HasObjectItem(j, "inUnion")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 78 | + if (cJSON_HasObjectItem(j, "inUnion")) { | |
| 79 | + if (!cJSON_IsInUnion(cJSON_GetObjectItemCaseSensitive(j, "inUnion"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 80 | + x->in_union = cJSON_GetInUnionValue(cJSON_GetObjectItemCaseSensitive(j, "inUnion")); | |
| 81 | + if (NULL == x->in_union) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 82 | + } | |
| 83 | + if (!cJSON_HasObjectItem(j, "maxlength")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 84 | + if (cJSON_HasObjectItem(j, "maxlength")) { | |
| 85 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "maxlength"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 86 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "maxlength")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 87 | + x->maxlength = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "maxlength"))); | |
| 88 | + } | |
| 89 | + else { | |
| 90 | + if (NULL != (x->maxlength = cJSON_malloc(sizeof(char)))) { | |
| 91 | + x->maxlength[0] = '\0'; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + if (!cJSON_HasObjectItem(j, "minlength")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 95 | + if (cJSON_HasObjectItem(j, "minlength")) { | |
| 96 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "minlength"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 97 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minlength")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 98 | + x->minlength = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "minlength"))); | |
| 99 | + } | |
| 100 | + else { | |
| 101 | + if (NULL != (x->minlength = cJSON_malloc(sizeof(char)))) { | |
| 102 | + x->minlength[0] = '\0'; | |
| 103 | + } | |
| 104 | + } | |
| 105 | + if (!cJSON_HasObjectItem(j, "minMaxIntersection")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 106 | + if (cJSON_HasObjectItem(j, "minMaxIntersection")) { | |
| 107 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "minMaxIntersection"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 108 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minMaxIntersection")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 109 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minMaxIntersection")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 110 | + x->min_max_intersection = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "minMaxIntersection"))); | |
| 111 | + } | |
| 112 | + else { | |
| 113 | + if (NULL != (x->min_max_intersection = cJSON_malloc(sizeof(char)))) { | |
| 114 | + x->min_max_intersection[0] = '\0'; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + if (!cJSON_HasObjectItem(j, "minmaxlength")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 118 | + if (cJSON_HasObjectItem(j, "minmaxlength")) { | |
| 119 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 120 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 121 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength")->valuestring) > 5) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 122 | + x->minmaxlength = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "minmaxlength"))); | |
| 123 | + } | |
| 124 | + else { | |
| 125 | + if (NULL != (x->minmaxlength = cJSON_malloc(sizeof(char)))) { | |
| 126 | + x->minmaxlength[0] = '\0'; | |
| 127 | + } | |
| 128 | + } | |
| 129 | + if (!cJSON_HasObjectItem(j, "minMaxUnion")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 130 | + if (cJSON_HasObjectItem(j, "minMaxUnion")) { | |
| 131 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "minMaxUnion"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 132 | + x->min_max_union = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "minMaxUnion"))); | |
| 133 | + } | |
| 134 | + else { | |
| 135 | + if (NULL != (x->min_max_union = cJSON_malloc(sizeof(char)))) { | |
| 136 | + x->min_max_union[0] = '\0'; | |
| 137 | + } | |
| 138 | + } | |
| 139 | + if (!cJSON_HasObjectItem(j, "union")) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 140 | + if (cJSON_HasObjectItem(j, "union")) { | |
| 141 | + if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "union"))) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 142 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "union")->valuestring) < 3) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 143 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "union")->valuestring) > 6) { cJSON_DeleteTopLevel(x); return NULL; } | |
| 144 | + x->top_level_union = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "union"))); | |
| 145 | + } | |
| 146 | + else { | |
| 147 | + if (NULL != (x->top_level_union = cJSON_malloc(sizeof(char)))) { | |
| 148 | + x->top_level_union[0] = '\0'; | |
| 149 | + } | |
| 150 | + } | |
| 151 | + } | |
| 152 | + } | |
| 153 | + return x; | |
| 154 | +} | |
| 155 | + | |
| 156 | +cJSON * cJSON_CreateTopLevel(const struct TopLevel * x) { | |
| 157 | + cJSON * j = NULL; | |
| 158 | + if (NULL != x) { | |
| 159 | + if (NULL != (j = cJSON_CreateObject())) { | |
| 160 | + if (NULL != x->intersection) { | |
| 161 | + cJSON_AddStringToObject(j, "intersection", x->intersection); | |
| 162 | + } | |
| 163 | + else { | |
| 164 | + cJSON_AddStringToObject(j, "intersection", ""); | |
| 165 | + } | |
| 166 | + cJSON_AddItemToObject(j, "inUnion", cJSON_CreateInUnion(x->in_union)); | |
| 167 | + if (NULL != x->maxlength) { | |
| 168 | + cJSON_AddStringToObject(j, "maxlength", x->maxlength); | |
| 169 | + } | |
| 170 | + else { | |
| 171 | + cJSON_AddStringToObject(j, "maxlength", ""); | |
| 172 | + } | |
| 173 | + if (NULL != x->minlength) { | |
| 174 | + cJSON_AddStringToObject(j, "minlength", x->minlength); | |
| 175 | + } | |
| 176 | + else { | |
| 177 | + cJSON_AddStringToObject(j, "minlength", ""); | |
| 178 | + } | |
| 179 | + if (NULL != x->min_max_intersection) { | |
| 180 | + cJSON_AddStringToObject(j, "minMaxIntersection", x->min_max_intersection); | |
| 181 | + } | |
| 182 | + else { | |
| 183 | + cJSON_AddStringToObject(j, "minMaxIntersection", ""); | |
| 184 | + } | |
| 185 | + if (NULL != x->minmaxlength) { | |
| 186 | + cJSON_AddStringToObject(j, "minmaxlength", x->minmaxlength); | |
| 187 | + } | |
| 188 | + else { | |
| 189 | + cJSON_AddStringToObject(j, "minmaxlength", ""); | |
| 190 | + } | |
| 191 | + if (NULL != x->min_max_union) { | |
| 192 | + cJSON_AddStringToObject(j, "minMaxUnion", x->min_max_union); | |
| 193 | + } | |
| 194 | + else { | |
| 195 | + cJSON_AddStringToObject(j, "minMaxUnion", ""); | |
| 196 | + } | |
| 197 | + if (NULL != x->top_level_union) { | |
| 198 | + cJSON_AddStringToObject(j, "union", x->top_level_union); | |
| 199 | + } | |
| 200 | + else { | |
| 201 | + cJSON_AddStringToObject(j, "union", ""); | |
| 202 | + } | |
| 203 | + } | |
| 204 | + } | |
| 205 | + return j; | |
| 206 | +} | |
| 207 | + | |
| 208 | +char * cJSON_PrintTopLevel(const struct TopLevel * x) { | |
| 209 | + char * s = NULL; | |
| 210 | + if (NULL != x) { | |
| 211 | + cJSON * j = cJSON_CreateTopLevel(x); | |
| 212 | + if (NULL != j) { | |
| 213 | + s = cJSON_Print(j); | |
| 214 | + cJSON_Delete(j); | |
| 215 | + } | |
| 216 | + } | |
| 217 | + return s; | |
| 218 | +} | |
| 219 | + | |
| 220 | +void cJSON_DeleteTopLevel(struct TopLevel * x) { | |
| 221 | + if (NULL != x) { | |
| 222 | + if (NULL != x->intersection) { | |
| 223 | + cJSON_free(x->intersection); | |
| 224 | + } | |
| 225 | + if (NULL != x->in_union) { | |
| 226 | + cJSON_DeleteInUnion(x->in_union); | |
| 227 | + } | |
| 228 | + if (NULL != x->maxlength) { | |
| 229 | + cJSON_free(x->maxlength); | |
| 230 | + } | |
| 231 | + if (NULL != x->minlength) { | |
| 232 | + cJSON_free(x->minlength); | |
| 233 | + } | |
| 234 | + if (NULL != x->min_max_intersection) { | |
| 235 | + cJSON_free(x->min_max_intersection); | |
| 236 | + } | |
| 237 | + if (NULL != x->minmaxlength) { | |
| 238 | + cJSON_free(x->minmaxlength); | |
| 239 | + } | |
| 240 | + if (NULL != x->min_max_union) { | |
| 241 | + cJSON_free(x->min_max_union); | |
| 242 | + } | |
| 243 | + if (NULL != x->top_level_union) { | |
| 244 | + cJSON_free(x->top_level_union); | |
| 245 | + } | |
| 246 | + cJSON_free(x); | |
| 247 | + } | |
| 248 | +} |
Aschema-cjsondefault / TopLevel.h+72 −0
| @@ -0,0 +1,72 @@ | ||
| 1 | +/** | |
| 2 | + * TopLevel.h | |
| 3 | + * This file has been autogenerated using quicktype https://github.com/quicktype/quicktype - DO NOT EDIT | |
| 4 | + * This file depends of https://github.com/DaveGamble/cJSON, https://github.com/joelguittet/c-list and https://github.com/joelguittet/c-hashtable | |
| 5 | + * To parse json data from json string use the following: struct <type> * data = cJSON_Parse<type>(<string>); | |
| 6 | + * To get json data from cJSON object use the following: struct <type> * data = cJSON_Get<type>Value(<cjson>); | |
| 7 | + * To get cJSON object from json data use the following: cJSON * cjson = cJSON_Create<type>(<data>); | |
| 8 | + * To print json string from json data use the following: char * string = cJSON_Print<type>(<data>); | |
| 9 | + * To delete json data use the following: cJSON_Delete<type>(<data>); | |
| 10 | + */ | |
| 11 | + | |
| 12 | +#ifndef __TOPLEVEL_H__ | |
| 13 | +#define __TOPLEVEL_H__ | |
| 14 | + | |
| 15 | +#ifdef __cplusplus | |
| 16 | +extern "C" { | |
| 17 | +#endif | |
| 18 | + | |
| 19 | +#include <stdint.h> | |
| 20 | +#include <stdbool.h> | |
| 21 | +#include <stdlib.h> | |
| 22 | +#include <string.h> | |
| 23 | +#include <regex.h> | |
| 24 | +#include <cJSON.h> | |
| 25 | +#include <hashtable.h> | |
| 26 | +#include <list.h> | |
| 27 | + | |
| 28 | +#ifndef cJSON_Bool | |
| 29 | +#define cJSON_Bool (cJSON_True | cJSON_False) | |
| 30 | +#endif | |
| 31 | +#ifndef cJSON_Map | |
| 32 | +#define cJSON_Map (1 << 16) | |
| 33 | +#endif | |
| 34 | +#ifndef cJSON_Enum | |
| 35 | +#define cJSON_Enum (1 << 17) | |
| 36 | +#endif | |
| 37 | + | |
| 38 | +struct InUnion { | |
| 39 | + int type; | |
| 40 | + union { | |
| 41 | + double number; | |
| 42 | + char * string; | |
| 43 | + } value; | |
| 44 | +}; | |
| 45 | + | |
| 46 | +struct TopLevel { | |
| 47 | + char * intersection; | |
| 48 | + struct InUnion * in_union; | |
| 49 | + char * maxlength; | |
| 50 | + char * minlength; | |
| 51 | + char * min_max_intersection; | |
| 52 | + char * minmaxlength; | |
| 53 | + char * min_max_union; | |
| 54 | + char * top_level_union; | |
| 55 | +}; | |
| 56 | + | |
| 57 | +#define cJSON_IsInUnion(j) (cJSON_IsNumber(j) || cJSON_IsString(j)) | |
| 58 | +struct InUnion * cJSON_GetInUnionValue(const cJSON * j); | |
| 59 | +cJSON * cJSON_CreateInUnion(const struct InUnion * x); | |
| 60 | +void cJSON_DeleteInUnion(struct InUnion * x); | |
| 61 | + | |
| 62 | +struct TopLevel * cJSON_ParseTopLevel(const char * s); | |
| 63 | +struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j); | |
| 64 | +cJSON * cJSON_CreateTopLevel(const struct TopLevel * x); | |
| 65 | +char * cJSON_PrintTopLevel(const struct TopLevel * x); | |
| 66 | +void cJSON_DeleteTopLevel(struct TopLevel * x); | |
| 67 | + | |
| 68 | +#ifdef __cplusplus | |
| 69 | +} | |
| 70 | +#endif | |
| 71 | + | |
| 72 | +#endif /* __TOPLEVEL_H__ */ |
Test case
1 generated file · +2 −0test/inputs/schema/renaming-bug.schema
Mschema-cjsondefault / TopLevel.c+2 −0
| @@ -591,6 +591,7 @@ struct Berry * cJSON_GetBerryValue(const cJSON * j) { | ||
| 591 | 591 | } |
| 592 | 592 | if (cJSON_HasObjectItem(j, "name")) { |
| 593 | 593 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "name"))) { cJSON_DeleteBerry(x); return NULL; } |
| 594 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "name")->valuestring) < 1) { cJSON_DeleteBerry(x); return NULL; } | |
| 594 | 595 | x->name = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "name"))); |
| 595 | 596 | } |
| 596 | 597 | if (cJSON_HasObjectItem(j, "shapes")) { |
| @@ -1020,6 +1021,7 @@ struct Vehicle * cJSON_GetVehicleValue(const cJSON * j) { | ||
| 1020 | 1021 | } |
| 1021 | 1022 | if (cJSON_HasObjectItem(j, "id")) { |
| 1022 | 1023 | if (!cJSON_IsString(cJSON_GetObjectItemCaseSensitive(j, "id"))) { cJSON_DeleteVehicle(x); return NULL; } |
| 1024 | + if (strlen(cJSON_GetObjectItemCaseSensitive(j, "id")->valuestring) < 1) { cJSON_DeleteVehicle(x); return NULL; } | |
| 1023 | 1025 | x->id = strdup(cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(j, "id"))); |
| 1024 | 1026 | } |
| 1025 | 1027 | if (cJSON_HasObjectItem(j, "speed")) { |
No generated files match these filters.