Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix c-libcurl generator for int and boolean values #15782

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,13 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
// {{{classname}}}->{{{name}}}
{{#required}}
{{^isEnum}}
{{^isNumeric}}
{{^isBoolean}}
if (!{{{classname}}}->{{{name}}}) {
goto fail;
}
{{/isBoolean}}
{{/isNumeric}}
{{/isEnum}}
{{#isEnum}}
if ({{projectName}}_{{classVarName}}_{{enumName}}_NULL == {{{classname}}}->{{{name}}}) {
Expand All @@ -344,7 +348,11 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{/required}}
{{^required}}
{{^isEnum}}
{{^isNumeric}}
{{^isBoolean}}
if({{{classname}}}->{{{name}}}) {
{{/isBoolean}}
{{/isNumeric}}
{{/isEnum}}
{{#isEnum}}
if({{{classname}}}->{{{name}}} != {{projectName}}_{{classVarName}}_{{enumName}}_NULL) {
Expand Down Expand Up @@ -548,7 +556,11 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{/isMap}}
{{/isContainer}}
{{^required}}
{{^isNumeric}}
{{^isBoolean}}
}
{{/isBoolean}}
{{/isNumeric}}
{{/required}}

{{/vars}}
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/c/model/api_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ cJSON *api_response_convertToJSON(api_response_t *api_response) {
cJSON *item = cJSON_CreateObject();

// api_response->code
if(api_response->code) {
if(cJSON_AddNumberToObject(item, "code", api_response->code) == NULL) {
goto fail; //Numeric
}
}


// api_response->type
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/c/model/category.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ cJSON *category_convertToJSON(category_t *category) {
cJSON *item = cJSON_CreateObject();

// category->id
if(category->id) {
if(cJSON_AddNumberToObject(item, "id", category->id) == NULL) {
goto fail; //Numeric
}
}


// category->name
Expand Down
8 changes: 0 additions & 8 deletions samples/client/petstore/c/model/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,21 @@ cJSON *order_convertToJSON(order_t *order) {
cJSON *item = cJSON_CreateObject();

// order->id
if(order->id) {
if(cJSON_AddNumberToObject(item, "id", order->id) == NULL) {
goto fail; //Numeric
}
}


// order->pet_id
if(order->pet_id) {
if(cJSON_AddNumberToObject(item, "petId", order->pet_id) == NULL) {
goto fail; //Numeric
}
}


// order->quantity
if(order->quantity) {
if(cJSON_AddNumberToObject(item, "quantity", order->quantity) == NULL) {
goto fail; //Numeric
}
}


// order->ship_date
Expand All @@ -102,11 +96,9 @@ cJSON *order_convertToJSON(order_t *order) {


// order->complete
if(order->complete) {
if(cJSON_AddBoolToObject(item, "complete", order->complete) == NULL) {
goto fail; //Bool
}
}

return item;
fail:
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/c/model/pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ cJSON *pet_convertToJSON(pet_t *pet) {
cJSON *item = cJSON_CreateObject();

// pet->id
if(pet->id) {
if(cJSON_AddNumberToObject(item, "id", pet->id) == NULL) {
goto fail; //Numeric
}
}


// pet->category
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/c/model/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ cJSON *tag_convertToJSON(tag_t *tag) {
cJSON *item = cJSON_CreateObject();

// tag->id
if(tag->id) {
if(cJSON_AddNumberToObject(item, "id", tag->id) == NULL) {
goto fail; //Numeric
}
}


// tag->name
Expand Down
4 changes: 0 additions & 4 deletions samples/client/petstore/c/model/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ cJSON *user_convertToJSON(user_t *user) {
cJSON *item = cJSON_CreateObject();

// user->id
if(user->id) {
if(cJSON_AddNumberToObject(item, "id", user->id) == NULL) {
goto fail; //Numeric
}
}


// user->username
Expand Down Expand Up @@ -124,11 +122,9 @@ cJSON *user_convertToJSON(user_t *user) {


// user->user_status
if(user->user_status) {
if(cJSON_AddNumberToObject(item, "userStatus", user->user_status) == NULL) {
goto fail; //Numeric
}
}

return item;
fail:
Expand Down