Skip to content

Commit c3abdb6

Browse files
authored
Check cJSON_IsNull when the data type is datetime (OpenAPITools#13884)
1 parent c71ec55 commit c3abdb6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ fail:
669669
{{/isDate}}
670670
{{#isDateTime}}
671671
{{^required}}if ({{{name}}}) { {{/required}}
672-
if(!cJSON_IsString({{{name}}}))
672+
if(!cJSON_IsString({{{name}}}) && !cJSON_IsNull({{{name}}}))
673673
{
674674
goto end; //DateTime
675675
}
@@ -893,7 +893,7 @@ fail:
893893
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
894894
{{/isDate}}
895895
{{#isDateTime}}
896-
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
896+
{{^required}}{{{name}}} && !cJSON_IsNull({{{name}}}) ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
897897
{{/isDateTime}}
898898
{{/isPrimitiveType}}
899899
{{/isContainer}}

samples/client/petstore/c/model/order.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
150150
// order->ship_date
151151
cJSON *ship_date = cJSON_GetObjectItemCaseSensitive(orderJSON, "shipDate");
152152
if (ship_date) {
153-
if(!cJSON_IsString(ship_date))
153+
if(!cJSON_IsString(ship_date) && !cJSON_IsNull(ship_date))
154154
{
155155
goto end; //DateTime
156156
}
@@ -181,7 +181,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
181181
id ? id->valuedouble : 0,
182182
pet_id ? pet_id->valuedouble : 0,
183183
quantity ? quantity->valuedouble : 0,
184-
ship_date ? strdup(ship_date->valuestring) : NULL,
184+
ship_date && !cJSON_IsNull(ship_date) ? strdup(ship_date->valuestring) : NULL,
185185
status ? statusVariable : -1,
186186
complete ? complete->valueint : 0
187187
);

0 commit comments

Comments
 (0)