diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache index 1df70b483916..65685b8c6787 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache @@ -669,7 +669,7 @@ fail: {{/isDate}} {{#isDateTime}} {{^required}}if ({{{name}}}) { {{/required}} - if(!cJSON_IsString({{{name}}})) + if(!cJSON_IsString({{{name}}}) && !cJSON_IsNull({{{name}}})) { goto end; //DateTime } @@ -893,7 +893,7 @@ fail: {{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}} {{/isDate}} {{#isDateTime}} - {{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}} + {{^required}}{{{name}}} && !cJSON_IsNull({{{name}}}) ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}} {{/isDateTime}} {{/isPrimitiveType}} {{/isContainer}} diff --git a/samples/client/petstore/c/model/order.c b/samples/client/petstore/c/model/order.c index 132aa09405cd..ec8688127116 100644 --- a/samples/client/petstore/c/model/order.c +++ b/samples/client/petstore/c/model/order.c @@ -150,7 +150,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){ // order->ship_date cJSON *ship_date = cJSON_GetObjectItemCaseSensitive(orderJSON, "shipDate"); if (ship_date) { - if(!cJSON_IsString(ship_date)) + if(!cJSON_IsString(ship_date) && !cJSON_IsNull(ship_date)) { goto end; //DateTime } @@ -181,7 +181,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){ id ? id->valuedouble : 0, pet_id ? pet_id->valuedouble : 0, quantity ? quantity->valuedouble : 0, - ship_date ? strdup(ship_date->valuestring) : NULL, + ship_date && !cJSON_IsNull(ship_date) ? strdup(ship_date->valuestring) : NULL, status ? statusVariable : -1, complete ? complete->valueint : 0 );