forked from loafle/openapi-generator-original
do not put the invalid value of the enum to a JSON structure (#12133)
This commit is contained in:
parent
4485ba27c6
commit
16ab5feeb9
@ -336,8 +336,20 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
if ({{projectName}}_{{classVarName}}_{{enumName}}_NULL == {{{classname}}}->{{{name}}}) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
{{^isEnum}}
|
||||
if({{{classname}}}->{{{name}}}) {
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
if({{{classname}}}->{{{name}}} != {{projectName}}_{{classVarName}}_{{enumName}}_NULL) {
|
||||
{{/isEnum}}
|
||||
{{/required}}
|
||||
{{^required}}{{^isEnum}}if({{{classname}}}->{{{name}}}) { {{/isEnum}}{{/required}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
@ -536,7 +548,7 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
{{/isMap}}
|
||||
{{/isContainer}}
|
||||
{{^required}}
|
||||
{{^isEnum}} } {{/isEnum}}
|
||||
}
|
||||
{{/required}}
|
||||
|
||||
{{/vars}}
|
||||
|
@ -93,12 +93,12 @@ cJSON *order_convertToJSON(order_t *order) {
|
||||
|
||||
|
||||
// order->status
|
||||
|
||||
if(order->status != openapi_petstore_order_STATUS_NULL) {
|
||||
if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
|
||||
{
|
||||
goto fail; //Enum
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// order->complete
|
||||
|
@ -103,7 +103,6 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
||||
if (!pet->name) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(cJSON_AddStringToObject(item, "name", pet->name) == NULL) {
|
||||
goto fail; //String
|
||||
}
|
||||
@ -113,7 +112,6 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
||||
if (!pet->photo_urls) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON *photo_urls = cJSON_AddArrayToObject(item, "photoUrls");
|
||||
if(photo_urls == NULL) {
|
||||
goto fail; //primitive container
|
||||
@ -149,12 +147,12 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
||||
|
||||
|
||||
// pet->status
|
||||
|
||||
if(pet->status != openapi_petstore_pet_STATUS_NULL) {
|
||||
if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
|
||||
{
|
||||
goto fail; //Enum
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
|
Loading…
x
Reference in New Issue
Block a user