Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
15test cases
17files differ
15modified
2new
0deleted
471changed lines
+434 −37insertions / deletions
Base 0caec23032712f67286ebec6c5773e3265c0e70c · PR merge abf67288e5f83c083d97bb4ef2aae95c32c71708 · Head ada5ca04c9bfbaab10b0b5f2a0e2d49922049cea · raw patch
Test case

test/inputs/json/misc/26c9c.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -235,7 +235,7 @@ struct TopLevel {
235235 struct Meta * meta;
236236 };
237237
238-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
238+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
239239 struct Datum * cJSON_GetDatumValue(const cJSON * j);
240240 cJSON * cJSON_CreateDatum(const struct Datum * x);
241241 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/421d4.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -162,7 +162,7 @@ struct TopLevel {
162162 struct Meta * meta;
163163 };
164164
165-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
165+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
166166 struct Datum * cJSON_GetDatumValue(const cJSON * j);
167167 cJSON * cJSON_CreateDatum(const struct Datum * x);
168168 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/5f7fe.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -240,7 +240,7 @@ struct TopLevel {
240240 enum TypeName cJSON_GetTypeNameValue(const cJSON * j);
241241 cJSON * cJSON_CreateTypeName(const enum TypeName x);
242242
243-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
243+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
244244 struct Datum * cJSON_GetDatumValue(const cJSON * j);
245245 cJSON * cJSON_CreateDatum(const struct Datum * x);
246246 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/617e8.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -239,7 +239,7 @@ struct TopLevel {
239239 enum TypeName cJSON_GetTypeNameValue(const cJSON * j);
240240 cJSON * cJSON_CreateTypeName(const enum TypeName x);
241241
242-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
242+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
243243 struct Datum * cJSON_GetDatumValue(const cJSON * j);
244244 cJSON * cJSON_CreateDatum(const struct Datum * x);
245245 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/a0496.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -69,7 +69,7 @@ struct TopLevel {
6969 char * urlize_name;
7070 };
7171
72-#define cJSON_IsDatum(j) (cJSON_IsNumber(j) || cJSON_IsString(j))
72+#define cJSON_IsDatum(j) (cJSON_IsNumber(j) || cJSON_IsNull(j) || cJSON_IsString(j))
7373 struct Datum * cJSON_GetDatumValue(const cJSON * j);
7474 cJSON * cJSON_CreateDatum(const struct Datum * x);
7575 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/a3d8c.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -168,7 +168,7 @@ struct TopLevel {
168168 enum TypeName cJSON_GetTypeNameValue(const cJSON * j);
169169 cJSON * cJSON_CreateTypeName(const enum TypeName x);
170170
171-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
171+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
172172 struct Datum * cJSON_GetDatumValue(const cJSON * j);
173173 cJSON * cJSON_CreateDatum(const struct Datum * x);
174174 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/misc/fcca3.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -265,7 +265,7 @@ struct TopLevel {
265265 enum TypeName cJSON_GetTypeNameValue(const cJSON * j);
266266 cJSON * cJSON_CreateTypeName(const enum TypeName x);
267267
268-#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
268+#define cJSON_IsDatum(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
269269 struct Datum * cJSON_GetDatumValue(const cJSON * j);
270270 cJSON * cJSON_CreateDatum(const struct Datum * x);
271271 void cJSON_DeleteDatum(struct Datum * x);
Test case

test/inputs/json/priority/combinations4.json

2 generated files · +20 −20
Mcjsondefault / TopLevel.h+10 −10
@@ -847,7 +847,7 @@ void cJSON_DeletePyodermiaElement(struct PyodermiaElement * x);
847847 struct PyodermiaElement * cJSON_ParsePyodermiaElement(const char * s);
848848 char * cJSON_PrintPyodermiaElement(const struct PyodermiaElement * x);
849849
850-#define cJSON_IsQuebrachineElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j))
850+#define cJSON_IsQuebrachineElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
851851 struct QuebrachineElement * cJSON_GetQuebrachineElementValue(const cJSON * j);
852852 cJSON * cJSON_CreateQuebrachineElement(const struct QuebrachineElement * x);
853853 void cJSON_DeleteQuebrachineElement(struct QuebrachineElement * x);
@@ -889,7 +889,7 @@ void cJSON_DeleteRewriteElement(struct RewriteElement * x);
889889 struct RewriteElement * cJSON_ParseRewriteElement(const char * s);
890890 char * cJSON_PrintRewriteElement(const struct RewriteElement * x);
891891
892-#define cJSON_IsSaccoderm(j) (cJSON_IsArray(j) || cJSON_IsString(j))
892+#define cJSON_IsSaccoderm(j) (cJSON_IsArray(j) || cJSON_IsNull(j) || cJSON_IsString(j))
893893 struct Saccoderm * cJSON_GetSaccodermValue(const cJSON * j);
894894 cJSON * cJSON_CreateSaccoderm(const struct Saccoderm * x);
895895 void cJSON_DeleteSaccoderm(struct Saccoderm * x);
@@ -903,7 +903,7 @@ void cJSON_DeleteSantirElement(struct SantirElement * x);
903903 struct SantirElement * cJSON_ParseSantirElement(const char * s);
904904 char * cJSON_PrintSantirElement(const struct SantirElement * x);
905905
906-#define cJSON_IsSaprophilous(j) (cJSON_IsObject(j) || cJSON_IsString(j))
906+#define cJSON_IsSaprophilous(j) (cJSON_IsObject(j) || cJSON_IsNull(j) || cJSON_IsString(j))
907907 struct Saprophilous * cJSON_GetSaprophilousValue(const cJSON * j);
908908 cJSON * cJSON_CreateSaprophilous(const struct Saprophilous * x);
909909 void cJSON_DeleteSaprophilous(struct Saprophilous * x);
@@ -917,14 +917,14 @@ void cJSON_DeleteSaxtenElement(struct SaxtenElement * x);
917917 struct SaxtenElement * cJSON_ParseSaxtenElement(const char * s);
918918 char * cJSON_PrintSaxtenElement(const struct SaxtenElement * x);
919919
920-#define cJSON_IsScoffer(j) (cJSON_IsArray(j) || cJSON_IsObject(j))
920+#define cJSON_IsScoffer(j) (cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
921921 struct Scoffer * cJSON_GetScofferValue(const cJSON * j);
922922 cJSON * cJSON_CreateScoffer(const struct Scoffer * x);
923923 void cJSON_DeleteScoffer(struct Scoffer * x);
924924 struct Scoffer * cJSON_ParseScoffer(const char * s);
925925 char * cJSON_PrintScoffer(const struct Scoffer * x);
926926
927-#define cJSON_IsScrampum(j) (cJSON_IsArray(j) || cJSON_IsBool(j))
927+#define cJSON_IsScrampum(j) (cJSON_IsArray(j) || cJSON_IsBool(j) || cJSON_IsNull(j))
928928 struct Scrampum * cJSON_GetScrampumValue(const cJSON * j);
929929 cJSON * cJSON_CreateScrampum(const struct Scrampum * x);
930930 void cJSON_DeleteScrampum(struct Scrampum * x);
@@ -987,7 +987,7 @@ void cJSON_DeleteTabaxir(struct Tabaxir * x);
987987 struct Tabaxir * cJSON_ParseTabaxir(const char * s);
988988 char * cJSON_PrintTabaxir(const struct Tabaxir * x);
989989
990-#define cJSON_IsTalpiform(j) (cJSON_IsObject(j) || cJSON_IsNumber(j))
990+#define cJSON_IsTalpiform(j) (cJSON_IsObject(j) || cJSON_IsNumber(j) || cJSON_IsNull(j))
991991 struct Talpiform * cJSON_GetTalpiformValue(const cJSON * j);
992992 cJSON * cJSON_CreateTalpiform(const struct Talpiform * x);
993993 void cJSON_DeleteTalpiform(struct Talpiform * x);
@@ -1036,7 +1036,7 @@ void cJSON_DeleteUnerasing(struct Unerasing * x);
10361036 struct Unerasing * cJSON_ParseUnerasing(const char * s);
10371037 char * cJSON_PrintUnerasing(const struct Unerasing * x);
10381038
1039-#define cJSON_IsUnguentarium(j) (cJSON_IsArray(j) || quicktype_cJSON_IsInteger(j))
1039+#define cJSON_IsUnguentarium(j) (cJSON_IsArray(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j))
10401040 struct Unguentarium * cJSON_GetUnguentariumValue(const cJSON * j);
10411041 cJSON * cJSON_CreateUnguentarium(const struct Unguentarium * x);
10421042 void cJSON_DeleteUnguentarium(struct Unguentarium * x);
@@ -1050,14 +1050,14 @@ void cJSON_DeleteUnimpeachablyElement(struct UnimpeachablyElement * x);
10501050 struct UnimpeachablyElement * cJSON_ParseUnimpeachablyElement(const char * s);
10511051 char * cJSON_PrintUnimpeachablyElement(const struct UnimpeachablyElement * x);
10521052
1053-#define cJSON_IsUnmortgaged(j) (cJSON_IsNumber(j) || cJSON_IsObject(j))
1053+#define cJSON_IsUnmortgaged(j) (cJSON_IsNumber(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
10541054 struct Unmortgaged * cJSON_GetUnmortgagedValue(const cJSON * j);
10551055 cJSON * cJSON_CreateUnmortgaged(const struct Unmortgaged * x);
10561056 void cJSON_DeleteUnmortgaged(struct Unmortgaged * x);
10571057 struct Unmortgaged * cJSON_ParseUnmortgaged(const char * s);
10581058 char * cJSON_PrintUnmortgaged(const struct Unmortgaged * x);
10591059
1060-#define cJSON_IsUnobstructed(j) (cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j))
1060+#define cJSON_IsUnobstructed(j) (cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j))
10611061 struct Unobstructed * cJSON_GetUnobstructedValue(const cJSON * j);
10621062 cJSON * cJSON_CreateUnobstructed(const struct Unobstructed * x);
10631063 void cJSON_DeleteUnobstructed(struct Unobstructed * x);
@@ -1099,7 +1099,7 @@ void cJSON_DeleteUnvarying(struct Unvarying * x);
10991099 struct Unvarying * cJSON_ParseUnvarying(const char * s);
11001100 char * cJSON_PrintUnvarying(const struct Unvarying * x);
11011101
1102-#define cJSON_IsVehemently(j) (cJSON_IsArray(j) || cJSON_IsBool(j))
1102+#define cJSON_IsVehemently(j) (cJSON_IsArray(j) || cJSON_IsBool(j) || cJSON_IsNull(j))
11031103 struct Vehemently * cJSON_GetVehementlyValue(const cJSON * j);
11041104 cJSON * cJSON_CreateVehemently(const struct Vehemently * x);
11051105 void cJSON_DeleteVehemently(struct Vehemently * x);
Mcjsonheader-only-false__source-style-single-source--491b617045b9 / TopLevel.h+10 −10
@@ -847,7 +847,7 @@ void cJSON_DeletePyodermiaElement(struct PyodermiaElement * x);
847847 struct PyodermiaElement * cJSON_ParsePyodermiaElement(const char * s);
848848 char * cJSON_PrintPyodermiaElement(const struct PyodermiaElement * x);
849849
850-#define cJSON_IsQuebrachineElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j))
850+#define cJSON_IsQuebrachineElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
851851 struct QuebrachineElement * cJSON_GetQuebrachineElementValue(const cJSON * j);
852852 cJSON * cJSON_CreateQuebrachineElement(const struct QuebrachineElement * x);
853853 void cJSON_DeleteQuebrachineElement(struct QuebrachineElement * x);
@@ -889,7 +889,7 @@ void cJSON_DeleteRewriteElement(struct RewriteElement * x);
889889 struct RewriteElement * cJSON_ParseRewriteElement(const char * s);
890890 char * cJSON_PrintRewriteElement(const struct RewriteElement * x);
891891
892-#define cJSON_IsSaccoderm(j) (cJSON_IsArray(j) || cJSON_IsString(j))
892+#define cJSON_IsSaccoderm(j) (cJSON_IsArray(j) || cJSON_IsNull(j) || cJSON_IsString(j))
893893 struct Saccoderm * cJSON_GetSaccodermValue(const cJSON * j);
894894 cJSON * cJSON_CreateSaccoderm(const struct Saccoderm * x);
895895 void cJSON_DeleteSaccoderm(struct Saccoderm * x);
@@ -903,7 +903,7 @@ void cJSON_DeleteSantirElement(struct SantirElement * x);
903903 struct SantirElement * cJSON_ParseSantirElement(const char * s);
904904 char * cJSON_PrintSantirElement(const struct SantirElement * x);
905905
906-#define cJSON_IsSaprophilous(j) (cJSON_IsObject(j) || cJSON_IsString(j))
906+#define cJSON_IsSaprophilous(j) (cJSON_IsObject(j) || cJSON_IsNull(j) || cJSON_IsString(j))
907907 struct Saprophilous * cJSON_GetSaprophilousValue(const cJSON * j);
908908 cJSON * cJSON_CreateSaprophilous(const struct Saprophilous * x);
909909 void cJSON_DeleteSaprophilous(struct Saprophilous * x);
@@ -917,14 +917,14 @@ void cJSON_DeleteSaxtenElement(struct SaxtenElement * x);
917917 struct SaxtenElement * cJSON_ParseSaxtenElement(const char * s);
918918 char * cJSON_PrintSaxtenElement(const struct SaxtenElement * x);
919919
920-#define cJSON_IsScoffer(j) (cJSON_IsArray(j) || cJSON_IsObject(j))
920+#define cJSON_IsScoffer(j) (cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
921921 struct Scoffer * cJSON_GetScofferValue(const cJSON * j);
922922 cJSON * cJSON_CreateScoffer(const struct Scoffer * x);
923923 void cJSON_DeleteScoffer(struct Scoffer * x);
924924 struct Scoffer * cJSON_ParseScoffer(const char * s);
925925 char * cJSON_PrintScoffer(const struct Scoffer * x);
926926
927-#define cJSON_IsScrampum(j) (cJSON_IsArray(j) || cJSON_IsBool(j))
927+#define cJSON_IsScrampum(j) (cJSON_IsArray(j) || cJSON_IsBool(j) || cJSON_IsNull(j))
928928 struct Scrampum * cJSON_GetScrampumValue(const cJSON * j);
929929 cJSON * cJSON_CreateScrampum(const struct Scrampum * x);
930930 void cJSON_DeleteScrampum(struct Scrampum * x);
@@ -987,7 +987,7 @@ void cJSON_DeleteTabaxir(struct Tabaxir * x);
987987 struct Tabaxir * cJSON_ParseTabaxir(const char * s);
988988 char * cJSON_PrintTabaxir(const struct Tabaxir * x);
989989
990-#define cJSON_IsTalpiform(j) (cJSON_IsObject(j) || cJSON_IsNumber(j))
990+#define cJSON_IsTalpiform(j) (cJSON_IsObject(j) || cJSON_IsNumber(j) || cJSON_IsNull(j))
991991 struct Talpiform * cJSON_GetTalpiformValue(const cJSON * j);
992992 cJSON * cJSON_CreateTalpiform(const struct Talpiform * x);
993993 void cJSON_DeleteTalpiform(struct Talpiform * x);
@@ -1036,7 +1036,7 @@ void cJSON_DeleteUnerasing(struct Unerasing * x);
10361036 struct Unerasing * cJSON_ParseUnerasing(const char * s);
10371037 char * cJSON_PrintUnerasing(const struct Unerasing * x);
10381038
1039-#define cJSON_IsUnguentarium(j) (cJSON_IsArray(j) || quicktype_cJSON_IsInteger(j))
1039+#define cJSON_IsUnguentarium(j) (cJSON_IsArray(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j))
10401040 struct Unguentarium * cJSON_GetUnguentariumValue(const cJSON * j);
10411041 cJSON * cJSON_CreateUnguentarium(const struct Unguentarium * x);
10421042 void cJSON_DeleteUnguentarium(struct Unguentarium * x);
@@ -1050,14 +1050,14 @@ void cJSON_DeleteUnimpeachablyElement(struct UnimpeachablyElement * x);
10501050 struct UnimpeachablyElement * cJSON_ParseUnimpeachablyElement(const char * s);
10511051 char * cJSON_PrintUnimpeachablyElement(const struct UnimpeachablyElement * x);
10521052
1053-#define cJSON_IsUnmortgaged(j) (cJSON_IsNumber(j) || cJSON_IsObject(j))
1053+#define cJSON_IsUnmortgaged(j) (cJSON_IsNumber(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
10541054 struct Unmortgaged * cJSON_GetUnmortgagedValue(const cJSON * j);
10551055 cJSON * cJSON_CreateUnmortgaged(const struct Unmortgaged * x);
10561056 void cJSON_DeleteUnmortgaged(struct Unmortgaged * x);
10571057 struct Unmortgaged * cJSON_ParseUnmortgaged(const char * s);
10581058 char * cJSON_PrintUnmortgaged(const struct Unmortgaged * x);
10591059
1060-#define cJSON_IsUnobstructed(j) (cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j))
1060+#define cJSON_IsUnobstructed(j) (cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j))
10611061 struct Unobstructed * cJSON_GetUnobstructedValue(const cJSON * j);
10621062 cJSON * cJSON_CreateUnobstructed(const struct Unobstructed * x);
10631063 void cJSON_DeleteUnobstructed(struct Unobstructed * x);
@@ -1099,7 +1099,7 @@ void cJSON_DeleteUnvarying(struct Unvarying * x);
10991099 struct Unvarying * cJSON_ParseUnvarying(const char * s);
11001100 char * cJSON_PrintUnvarying(const struct Unvarying * x);
11011101
1102-#define cJSON_IsVehemently(j) (cJSON_IsArray(j) || cJSON_IsBool(j))
1102+#define cJSON_IsVehemently(j) (cJSON_IsArray(j) || cJSON_IsBool(j) || cJSON_IsNull(j))
11031103 struct Vehemently * cJSON_GetVehementlyValue(const cJSON * j);
11041104 cJSON * cJSON_CreateVehemently(const struct Vehemently * x);
11051105 void cJSON_DeleteVehemently(struct Vehemently * x);
Test case

test/inputs/json/priority/php-mixed-union.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -56,7 +56,7 @@ struct TopLevel {
5656 list_t * mixed;
5757 };
5858
59-#define cJSON_IsMixedElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
59+#define cJSON_IsMixedElement(j) (cJSON_IsBool(j) || cJSON_IsObject(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
6060 struct MixedElement * cJSON_GetMixedElementValue(const cJSON * j);
6161 cJSON * cJSON_CreateMixedElement(const struct MixedElement * x);
6262 void cJSON_DeleteMixedElement(struct MixedElement * x);
Test case

test/inputs/json/priority/unions.json

1 generated file · +1 −1
Mcjsondefault / TopLevel.h+1 −1
@@ -65,7 +65,7 @@ struct TopLevel {
6565 list_t * z;
6666 };
6767
68-#define cJSON_IsX(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsString(j))
68+#define cJSON_IsX(j) (quicktype_cJSON_IsInteger(j) || cJSON_IsNull(j) || cJSON_IsString(j))
6969 struct X * cJSON_GetXValue(const cJSON * j);
7070 cJSON * cJSON_CreateX(const struct X * x);
7171 void cJSON_DeleteX(struct X * x);
Test case

test/inputs/schema/direct-union.schema

2 generated files · +397 −0
Aschema-cjsondefault / TopLevel.c+312 −0
@@ -0,0 +1,312 @@
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 Anything * cJSON_GetAnythingValue(const cJSON * j) {
9+ struct Anything * x = cJSON_malloc(sizeof(struct Anything));
10+ if (NULL != x) {
11+ memset(x, 0, sizeof(struct Anything));
12+ if (cJSON_IsNull(j)) {
13+ x->type = cJSON_NULL;
14+ }
15+ else if (cJSON_IsNumber(j)) {
16+ x->type = cJSON_Number;
17+ x->value.number = cJSON_GetNumberValue(j);
18+ }
19+ else if (quicktype_cJSON_IsInteger(j)) {
20+ x->type = cJSON_Integer;
21+ x->value.integer = cJSON_GetNumberValue(j);
22+ }
23+ else if (cJSON_IsBool(j)) {
24+ x->type = cJSON_Bool;
25+ x->value.boolean = cJSON_IsTrue(j);
26+ }
27+ else if (cJSON_IsString(j)) {
28+ x->type = cJSON_String;
29+ x->value.string = strdup(cJSON_GetStringValue(j));
30+ }
31+ else if (cJSON_IsArray(j)) {
32+ x->type = cJSON_Array;
33+ list_t * x1 = list_create(false, NULL);
34+ if (NULL != x1) {
35+ cJSON * e1 = NULL;
36+ cJSON_ArrayForEach(e1, j) {
37+ list_add_tail(x1, quicktype_cJSON_Duplicate(e1), sizeof(cJSON *));
38+ }
39+ x->value.anything_array = x1;
40+ }
41+ }
42+ else if (cJSON_IsObject(j)) {
43+ x->type = cJSON_Map;
44+ hashtable_t * x1 = hashtable_create(64, false);
45+ if (NULL != x1) {
46+ cJSON * e1 = NULL;
47+ cJSON_ArrayForEach(e1, j) {
48+ hashtable_add(x1, e1->string, quicktype_cJSON_Duplicate(e1), sizeof(cJSON *));
49+ }
50+ x->value.anything_map = x1;
51+ }
52+ }
53+ if (0 == x->type) { cJSON_free(x); return NULL; }
54+ }
55+ return x;
56+}
57+struct Anything * cJSON_ParseAnything(const char * s) { cJSON * j = cJSON_Parse(s); struct Anything * x = j ? cJSON_GetAnythingValue(j) : NULL; cJSON_Delete(j); return x; }
58+char * cJSON_PrintAnything(const struct Anything * x) { cJSON * j = cJSON_CreateAnything(x); char * s = j ? cJSON_Print(j) : NULL; cJSON_Delete(j); return s; }
59+
60+cJSON * cJSON_CreateAnything(const struct Anything * x) {
61+ cJSON * j = NULL;
62+ if (NULL != x) {
63+ if (cJSON_NULL == x->type) {
64+ j = cJSON_CreateNull();
65+ }
66+ else if (cJSON_Number == x->type) {
67+ j = cJSON_CreateNumber(x->value.number);
68+ }
69+ else if (cJSON_Integer == x->type) {
70+ j = cJSON_CreateNumber(x->value.integer);
71+ }
72+ else if (cJSON_Bool == x->type) {
73+ j = cJSON_CreateBool(x->value.boolean);
74+ }
75+ else if (cJSON_String == x->type) {
76+ j = cJSON_CreateString(x->value.string);
77+ }
78+ else if (cJSON_Array == x->type) {
79+ cJSON * j1 = cJSON_CreateArray();
80+ if (NULL != j1) {
81+ cJSON * x1 = list_get_head(x->value.anything_array);
82+ while (NULL != x1) {
83+ cJSON_AddItemToArray(j1, quicktype_cJSON_Duplicate(x1));
84+ x1 = list_get_next(x->value.anything_array);
85+ }
86+ j = j1;
87+ }
88+ }
89+ else if (cJSON_Map == x->type) {
90+ cJSON * j1 = cJSON_CreateObject();
91+ if (NULL != j1) {
92+ char **keys1 = NULL;
93+ size_t count1 = hashtable_get_keys(x->value.anything_map, &keys1);
94+ if (NULL != keys1) {
95+ for (size_t index1 = 0; index1 < count1; index1++) {
96+ cJSON *x1 = hashtable_lookup(x->value.anything_map, keys1[index1]);
97+ cJSON_AddItemToObject(j1, keys1[index1], quicktype_cJSON_Duplicate(x1));
98+ }
99+ cJSON_free(keys1);
100+ }
101+ j = j1;
102+ }
103+ }
104+ }
105+ return j;
106+}
107+
108+void cJSON_DeleteAnything(struct Anything * x) {
109+ if (NULL != x) {
110+ if (cJSON_Number == x->type) {
111+ }
112+ else if (cJSON_Integer == x->type) {
113+ }
114+ else if (cJSON_Bool == x->type) {
115+ }
116+ else if (cJSON_String == x->type) {
117+ cJSON_free(x->value.string);
118+ }
119+ else if (cJSON_Array == x->type) {
120+ if (NULL != x->value.anything_array) {
121+ cJSON * x1 = list_get_head(x->value.anything_array);
122+ while (NULL != x1) {
123+ cJSON_Delete(x1);
124+ x1 = list_get_next(x->value.anything_array);
125+ }
126+ list_release(x->value.anything_array);
127+ }
128+ }
129+ else if (cJSON_Map == x->type) {
130+ if (NULL != x->value.anything_map) {
131+ char **keys1 = NULL;
132+ size_t count1 = hashtable_get_keys(x->value.anything_map, &keys1);
133+ if (NULL != keys1) {
134+ for (size_t index1 = 0; index1 < count1; index1++) {
135+ cJSON *x1 = hashtable_lookup(x->value.anything_map, keys1[index1]);
136+ if (NULL != x1) {
137+ cJSON_Delete(x1);
138+ }
139+ }
140+ cJSON_free(keys1);
141+ }
142+ hashtable_release(x->value.anything_map);
143+ }
144+ }
145+ cJSON_free(x);
146+ }
147+}
148+
149+struct Thing * cJSON_ParseThing(const char * s) {
150+ struct Thing * x = NULL;
151+ if (NULL != s) {
152+ cJSON * j = cJSON_Parse(s);
153+ if (NULL != j) {
154+ x = cJSON_GetThingValue(j);
155+ cJSON_Delete(j);
156+ }
157+ }
158+ return x;
159+}
160+
161+struct Thing * cJSON_GetThingValue(const cJSON * j) {
162+ struct Thing * x = NULL;
163+ if (NULL != j) {
164+ if (NULL != (x = cJSON_malloc(sizeof(struct Thing)))) {
165+ memset(x, 0, sizeof(struct Thing));
166+ if (cJSON_HasObjectItem(j, "optional")) {
167+ if (!cJSON_IsAnything(cJSON_GetObjectItemCaseSensitive(j, "optional"))) { cJSON_DeleteThing(x); return NULL; }
168+ x->optional = cJSON_GetAnythingValue(cJSON_GetObjectItemCaseSensitive(j, "optional"));
169+ if (NULL == x->optional) { cJSON_DeleteThing(x); return NULL; }
170+ }
171+ if (!cJSON_HasObjectItem(j, "required")) { cJSON_DeleteThing(x); return NULL; }
172+ if (cJSON_HasObjectItem(j, "required")) {
173+ if (!cJSON_IsAnything(cJSON_GetObjectItemCaseSensitive(j, "required"))) { cJSON_DeleteThing(x); return NULL; }
174+ x->required = cJSON_GetAnythingValue(cJSON_GetObjectItemCaseSensitive(j, "required"));
175+ if (NULL == x->required) { cJSON_DeleteThing(x); return NULL; }
176+ }
177+ }
178+ }
179+ return x;
180+}
181+
182+cJSON * cJSON_CreateThing(const struct Thing * x) {
183+ cJSON * j = NULL;
184+ if (NULL != x) {
185+ if (NULL != (j = cJSON_CreateObject())) {
186+ if (NULL != x->optional) {
187+ cJSON_AddItemToObject(j, "optional", cJSON_CreateAnything(x->optional));
188+ }
189+ cJSON_AddItemToObject(j, "required", cJSON_CreateAnything(x->required));
190+ }
191+ }
192+ return j;
193+}
194+
195+char * cJSON_PrintThing(const struct Thing * x) {
196+ char * s = NULL;
197+ if (NULL != x) {
198+ cJSON * j = cJSON_CreateThing(x);
199+ if (NULL != j) {
200+ s = cJSON_Print(j);
201+ cJSON_Delete(j);
202+ }
203+ }
204+ return s;
205+}
206+
207+void cJSON_DeleteThing(struct Thing * x) {
208+ if (NULL != x) {
209+ if (NULL != x->optional) {
210+ cJSON_DeleteAnything(x->optional);
211+ }
212+ if (NULL != x->required) {
213+ cJSON_DeleteAnything(x->required);
214+ }
215+ cJSON_free(x);
216+ }
217+}
218+
219+struct TopLevel * cJSON_ParseTopLevel(const char * s) {
220+ struct TopLevel * x = NULL;
221+ if (NULL != s) {
222+ cJSON * j = cJSON_Parse(s);
223+ if (NULL != j) {
224+ x = cJSON_GetTopLevelValue(j);
225+ cJSON_Delete(j);
226+ }
227+ }
228+ return x;
229+}
230+
231+struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) {
232+ struct TopLevel * x = NULL;
233+ if (NULL != j) {
234+ if (NULL != (x = cJSON_malloc(sizeof(struct TopLevel)))) {
235+ memset(x, 0, sizeof(struct TopLevel));
236+ if (!cJSON_HasObjectItem(j, "stuff")) { cJSON_DeleteTopLevel(x); return NULL; }
237+ if (cJSON_HasObjectItem(j, "stuff")) {
238+ if (!cJSON_IsObject(cJSON_GetObjectItemCaseSensitive(j, "stuff"))) { cJSON_DeleteTopLevel(x); return NULL; }
239+ hashtable_t * x1 = hashtable_create(64, false);
240+ if (NULL != x1) {
241+ cJSON * e1 = NULL;
242+ cJSON * j1 = cJSON_GetObjectItemCaseSensitive(j, "stuff");
243+ cJSON_ArrayForEach(e1, j1) {
244+ if (!cJSON_IsObject(e1)) { cJSON_DeleteTopLevel(x); return NULL; }
245+ hashtable_add(x1, e1->string, cJSON_GetThingValue(e1), sizeof(struct Thing *));
246+ }
247+ x->stuff = x1;
248+ }
249+ }
250+ else {
251+ x->stuff = hashtable_create(64, false);
252+ }
253+ }
254+ }
255+ return x;
256+}
257+
258+cJSON * cJSON_CreateTopLevel(const struct TopLevel * x) {
259+ cJSON * j = NULL;
260+ if (NULL != x) {
261+ if (NULL != (j = cJSON_CreateObject())) {
262+ if (NULL != x->stuff) {
263+ cJSON * j1 = cJSON_CreateObject();
264+ if (NULL != j1) {
265+ char **keys1 = NULL;
266+ size_t count1 = hashtable_get_keys(x->stuff, &keys1);
267+ if (NULL != keys1) {
268+ for (size_t index1 = 0; index1 < count1; index1++) {
269+ struct Thing *x1 = hashtable_lookup(x->stuff, keys1[index1]);
270+ cJSON_AddItemToObject(j1, keys1[index1], cJSON_CreateThing(x1));
271+ }
272+ cJSON_free(keys1);
273+ }
274+ cJSON_AddItemToObject(j, "stuff", j1);
275+ }
276+ }
277+ }
278+ }
279+ return j;
280+}
281+
282+char * cJSON_PrintTopLevel(const struct TopLevel * x) {
283+ char * s = NULL;
284+ if (NULL != x) {
285+ cJSON * j = cJSON_CreateTopLevel(x);
286+ if (NULL != j) {
287+ s = cJSON_Print(j);
288+ cJSON_Delete(j);
289+ }
290+ }
291+ return s;
292+}
293+
294+void cJSON_DeleteTopLevel(struct TopLevel * x) {
295+ if (NULL != x) {
296+ if (NULL != x->stuff) {
297+ char **keys1 = NULL;
298+ size_t count1 = hashtable_get_keys(x->stuff, &keys1);
299+ if (NULL != keys1) {
300+ for (size_t index1 = 0; index1 < count1; index1++) {
301+ struct Thing *x1 = hashtable_lookup(x->stuff, keys1[index1]);
302+ if (NULL != x1) {
303+ cJSON_DeleteThing(x1);
304+ }
305+ }
306+ cJSON_free(keys1);
307+ }
308+ hashtable_release(x->stuff);
309+ }
310+ cJSON_free(x);
311+ }
312+}
Aschema-cjsondefault / TopLevel.h+85 −0
@@ -0,0 +1,85 @@
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+#define quicktype_cJSON_Duplicate(j) cJSON_Duplicate(j, true)
29+#define cJSON_Integer (1 << 18)
30+#define quicktype_cJSON_IsInteger(j) (cJSON_IsNumber(j) && (j)->valuedouble == (int64_t)(j)->valuedouble)
31+#ifndef cJSON_Bool
32+#define cJSON_Bool (cJSON_True | cJSON_False)
33+#endif
34+#ifndef cJSON_Map
35+#define cJSON_Map (1 << 16)
36+#endif
37+#ifndef cJSON_Enum
38+#define cJSON_Enum (1 << 17)
39+#endif
40+
41+struct Anything {
42+ int type;
43+ union {
44+ double number;
45+ int64_t integer;
46+ bool boolean;
47+ char * string;
48+ list_t * anything_array;
49+ hashtable_t * anything_map;
50+ } value;
51+};
52+
53+struct Thing {
54+ struct Anything * optional;
55+ struct Anything * required;
56+};
57+
58+struct TopLevel {
59+ hashtable_t * stuff;
60+};
61+
62+#define cJSON_IsAnything(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsString(j) || cJSON_IsArray(j) || cJSON_IsObject(j))
63+struct Anything * cJSON_GetAnythingValue(const cJSON * j);
64+cJSON * cJSON_CreateAnything(const struct Anything * x);
65+void cJSON_DeleteAnything(struct Anything * x);
66+struct Anything * cJSON_ParseAnything(const char * s);
67+char * cJSON_PrintAnything(const struct Anything * x);
68+
69+struct Thing * cJSON_ParseThing(const char * s);
70+struct Thing * cJSON_GetThingValue(const cJSON * j);
71+cJSON * cJSON_CreateThing(const struct Thing * x);
72+char * cJSON_PrintThing(const struct Thing * x);
73+void cJSON_DeleteThing(struct Thing * x);
74+
75+struct TopLevel * cJSON_ParseTopLevel(const char * s);
76+struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j);
77+cJSON * cJSON_CreateTopLevel(const struct TopLevel * x);
78+char * cJSON_PrintTopLevel(const struct TopLevel * x);
79+void cJSON_DeleteTopLevel(struct TopLevel * x);
80+
81+#ifdef __cplusplus
82+}
83+#endif
84+
85+#endif /* __TOPLEVEL_H__ */
Test case

test/inputs/schema/recursive-union-flattening.schema

1 generated file · +4 −4
Mschema-cjsondefault / TopLevel.h+4 −4
@@ -96,28 +96,28 @@ struct TopLevel {
9696 } value;
9797 };
9898
99-#define cJSON_IsX(j) (cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
99+#define cJSON_IsX(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
100100 struct X * cJSON_GetXValue(const cJSON * j);
101101 cJSON * cJSON_CreateX(const struct X * x);
102102 void cJSON_DeleteX(struct X * x);
103103 struct X * cJSON_ParseX(const char * s);
104104 char * cJSON_PrintX(const struct X * x);
105105
106-#define cJSON_IsXElement(j) (cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
106+#define cJSON_IsXElement(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
107107 struct XElement * cJSON_GetXElementValue(const cJSON * j);
108108 cJSON * cJSON_CreateXElement(const struct XElement * x);
109109 void cJSON_DeleteXElement(struct XElement * x);
110110 struct XElement * cJSON_ParseXElement(const char * s);
111111 char * cJSON_PrintXElement(const struct XElement * x);
112112
113-#define cJSON_IsTopLevelElement(j) (cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
113+#define cJSON_IsTopLevelElement(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsArray(j) || cJSON_IsObject(j) || cJSON_IsString(j))
114114 struct TopLevelElement * cJSON_GetTopLevelElementValue(const cJSON * j);
115115 cJSON * cJSON_CreateTopLevelElement(const struct TopLevelElement * x);
116116 void cJSON_DeleteTopLevelElement(struct TopLevelElement * x);
117117 struct TopLevelElement * cJSON_ParseTopLevelElement(const char * s);
118118 char * cJSON_PrintTopLevelElement(const struct TopLevelElement * x);
119119
120-#define cJSON_IsTopLevel(j) (cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsString(j) || cJSON_IsArray(j) || cJSON_IsObject(j))
120+#define cJSON_IsTopLevel(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsString(j) || cJSON_IsArray(j) || cJSON_IsObject(j))
121121 struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j);
122122 cJSON * cJSON_CreateTopLevel(const struct TopLevel * x);
123123 void cJSON_DeleteTopLevel(struct TopLevel * x);
Test case

test/inputs/schema/rust-cycle-breaker-union.schema

1 generated file · +1 −1
Mschema-cjsondefault / TopLevel.h+1 −1
@@ -58,7 +58,7 @@ struct TopLevel {
5858 char * value;
5959 };
6060
61-#define cJSON_IsNext(j) (cJSON_IsObject(j) || cJSON_IsString(j))
61+#define cJSON_IsNext(j) (cJSON_IsObject(j) || cJSON_IsNull(j) || cJSON_IsString(j))
6262 struct Next * cJSON_GetNextValue(const cJSON * j);
6363 cJSON * cJSON_CreateNext(const struct Next * x);
6464 void cJSON_DeleteNext(struct Next * x);
Test case

test/inputs/schema/unevaluated-properties.schema

1 generated file · +1 −1
Mschema-cjsondefault / TopLevel.h+1 −1
@@ -68,7 +68,7 @@ struct TopLevel {
6868 struct Config * config;
6969 };
7070
71-#define cJSON_IsClosed(j) (cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsString(j) || cJSON_IsArray(j) || cJSON_IsObject(j))
71+#define cJSON_IsClosed(j) (cJSON_IsNull(j) || cJSON_IsNumber(j) || quicktype_cJSON_IsInteger(j) || cJSON_IsBool(j) || cJSON_IsString(j) || cJSON_IsArray(j) || cJSON_IsObject(j))
7272 struct Closed * cJSON_GetClosedValue(const cJSON * j);
7373 cJSON * cJSON_CreateClosed(const struct Closed * x);
7474 void cJSON_DeleteClosed(struct Closed * x);
Test case

test/inputs/schema/vega-lite.schema

1 generated file · +2 −2
Mschema-cjsondefault / TopLevel.h+2 −2
@@ -6542,7 +6542,7 @@ void cJSON_DeleteEqual(struct Equal * x);
65426542 struct Equal * cJSON_ParseEqual(const char * s);
65436543 char * cJSON_PrintEqual(const struct Equal * x);
65446544
6545-#define cJSON_IsRangeElement(j) (cJSON_IsNumber(j) || cJSON_IsObject(j))
6545+#define cJSON_IsRangeElement(j) (cJSON_IsNumber(j) || cJSON_IsObject(j) || cJSON_IsNull(j))
65466546 struct RangeElement * cJSON_GetRangeElementValue(const cJSON * j);
65476547 cJSON * cJSON_CreateRangeElement(const struct RangeElement * x);
65486548 void cJSON_DeleteRangeElement(struct RangeElement * x);
@@ -6612,7 +6612,7 @@ void cJSON_DeleteScheme(struct Scheme * x);
66126612 struct Scheme * cJSON_ParseScheme(const char * s);
66136613 char * cJSON_PrintScheme(const struct Scheme * x);
66146614
6615-#define cJSON_IsSortUnion(j) (cJSON_IsObject(j) || cJSON_IsString(j))
6615+#define cJSON_IsSortUnion(j) (cJSON_IsNull(j) || cJSON_IsObject(j) || cJSON_IsString(j))
66166616 struct SortUnion * cJSON_GetSortUnionValue(const cJSON * j);
66176617 cJSON * cJSON_CreateSortUnion(const struct SortUnion * x);
66186618 void cJSON_DeleteSortUnion(struct SortUnion * x);
No generated files match these filters.