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 65685b8c6787..11dcb74c884c 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 @@ -635,7 +635,7 @@ fail: {{^isEnum}} {{#isString}} {{^required}}if ({{{name}}}) { {{/required}} - if(!cJSON_IsString({{{name}}})) + if(!cJSON_IsString({{{name}}}){{^required}} && !cJSON_IsNull({{{name}}}){{/required}}) { goto end; //String } @@ -880,7 +880,7 @@ fail: {{/isEnum}} {{^isEnum}} {{#isString}} - {{^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}} {{/isString}} {{/isEnum}} {{#isByteArray}} diff --git a/samples/client/petstore/c/model/api_response.c b/samples/client/petstore/c/model/api_response.c index 117be5cb40d5..a1636e35b49b 100644 --- a/samples/client/petstore/c/model/api_response.c +++ b/samples/client/petstore/c/model/api_response.c @@ -88,7 +88,7 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){ // api_response->type cJSON *type = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "type"); if (type) { - if(!cJSON_IsString(type)) + if(!cJSON_IsString(type) && !cJSON_IsNull(type)) { goto end; //String } @@ -97,7 +97,7 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){ // api_response->message cJSON *message = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "message"); if (message) { - if(!cJSON_IsString(message)) + if(!cJSON_IsString(message) && !cJSON_IsNull(message)) { goto end; //String } @@ -106,8 +106,8 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){ api_response_local_var = api_response_create ( code ? code->valuedouble : 0, - type ? strdup(type->valuestring) : NULL, - message ? strdup(message->valuestring) : NULL + type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL, + message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL ); return api_response_local_var; diff --git a/samples/client/petstore/c/model/category.c b/samples/client/petstore/c/model/category.c index 34f5a804bdb2..3f6c32da5278 100644 --- a/samples/client/petstore/c/model/category.c +++ b/samples/client/petstore/c/model/category.c @@ -74,7 +74,7 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){ // category->name cJSON *name = cJSON_GetObjectItemCaseSensitive(categoryJSON, "name"); if (name) { - if(!cJSON_IsString(name)) + if(!cJSON_IsString(name) && !cJSON_IsNull(name)) { goto end; //String } @@ -83,7 +83,7 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){ category_local_var = category_create ( id ? id->valuedouble : 0, - name ? strdup(name->valuestring) : NULL + name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL ); return category_local_var; diff --git a/samples/client/petstore/c/model/tag.c b/samples/client/petstore/c/model/tag.c index ab3f4cce1fc6..00d73b2d2473 100644 --- a/samples/client/petstore/c/model/tag.c +++ b/samples/client/petstore/c/model/tag.c @@ -74,7 +74,7 @@ tag_t *tag_parseFromJSON(cJSON *tagJSON){ // tag->name cJSON *name = cJSON_GetObjectItemCaseSensitive(tagJSON, "name"); if (name) { - if(!cJSON_IsString(name)) + if(!cJSON_IsString(name) && !cJSON_IsNull(name)) { goto end; //String } @@ -83,7 +83,7 @@ tag_t *tag_parseFromJSON(cJSON *tagJSON){ tag_local_var = tag_create ( id ? id->valuedouble : 0, - name ? strdup(name->valuestring) : NULL + name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL ); return tag_local_var; diff --git a/samples/client/petstore/c/model/user.c b/samples/client/petstore/c/model/user.c index 5e5b9b39b03f..eb188153ccf0 100644 --- a/samples/client/petstore/c/model/user.c +++ b/samples/client/petstore/c/model/user.c @@ -154,7 +154,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->username cJSON *username = cJSON_GetObjectItemCaseSensitive(userJSON, "username"); if (username) { - if(!cJSON_IsString(username)) + if(!cJSON_IsString(username) && !cJSON_IsNull(username)) { goto end; //String } @@ -163,7 +163,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->first_name cJSON *first_name = cJSON_GetObjectItemCaseSensitive(userJSON, "firstName"); if (first_name) { - if(!cJSON_IsString(first_name)) + if(!cJSON_IsString(first_name) && !cJSON_IsNull(first_name)) { goto end; //String } @@ -172,7 +172,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->last_name cJSON *last_name = cJSON_GetObjectItemCaseSensitive(userJSON, "lastName"); if (last_name) { - if(!cJSON_IsString(last_name)) + if(!cJSON_IsString(last_name) && !cJSON_IsNull(last_name)) { goto end; //String } @@ -181,7 +181,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->email cJSON *email = cJSON_GetObjectItemCaseSensitive(userJSON, "email"); if (email) { - if(!cJSON_IsString(email)) + if(!cJSON_IsString(email) && !cJSON_IsNull(email)) { goto end; //String } @@ -190,7 +190,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->password cJSON *password = cJSON_GetObjectItemCaseSensitive(userJSON, "password"); if (password) { - if(!cJSON_IsString(password)) + if(!cJSON_IsString(password) && !cJSON_IsNull(password)) { goto end; //String } @@ -199,7 +199,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){ // user->phone cJSON *phone = cJSON_GetObjectItemCaseSensitive(userJSON, "phone"); if (phone) { - if(!cJSON_IsString(phone)) + if(!cJSON_IsString(phone) && !cJSON_IsNull(phone)) { goto end; //String } @@ -217,12 +217,12 @@ user_t *user_parseFromJSON(cJSON *userJSON){ user_local_var = user_create ( id ? id->valuedouble : 0, - username ? strdup(username->valuestring) : NULL, - first_name ? strdup(first_name->valuestring) : NULL, - last_name ? strdup(last_name->valuestring) : NULL, - email ? strdup(email->valuestring) : NULL, - password ? strdup(password->valuestring) : NULL, - phone ? strdup(phone->valuestring) : NULL, + username && !cJSON_IsNull(username) ? strdup(username->valuestring) : NULL, + first_name && !cJSON_IsNull(first_name) ? strdup(first_name->valuestring) : NULL, + last_name && !cJSON_IsNull(last_name) ? strdup(last_name->valuestring) : NULL, + email && !cJSON_IsNull(email) ? strdup(email->valuestring) : NULL, + password && !cJSON_IsNull(password) ? strdup(password->valuestring) : NULL, + phone && !cJSON_IsNull(phone) ? strdup(phone->valuestring) : NULL, user_status ? user_status->valuedouble : 0 );