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;
|
goto fail;
|
||||||
}
|
}
|
||||||
{{/isEnum}}
|
{{/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}}
|
||||||
{{^required}}{{^isEnum}}if({{{classname}}}->{{{name}}}) { {{/isEnum}}{{/required}}
|
|
||||||
{{^isContainer}}
|
{{^isContainer}}
|
||||||
{{#isPrimitiveType}}
|
{{#isPrimitiveType}}
|
||||||
{{#isNumeric}}
|
{{#isNumeric}}
|
||||||
@ -536,7 +548,7 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
|||||||
{{/isMap}}
|
{{/isMap}}
|
||||||
{{/isContainer}}
|
{{/isContainer}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
{{^isEnum}} } {{/isEnum}}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
@ -93,12 +93,12 @@ cJSON *order_convertToJSON(order_t *order) {
|
|||||||
|
|
||||||
|
|
||||||
// order->status
|
// order->status
|
||||||
|
if(order->status != openapi_petstore_order_STATUS_NULL) {
|
||||||
if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
|
if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
|
||||||
{
|
{
|
||||||
goto fail; //Enum
|
goto fail; //Enum
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// order->complete
|
// order->complete
|
||||||
|
@ -103,7 +103,6 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
|||||||
if (!pet->name) {
|
if (!pet->name) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cJSON_AddStringToObject(item, "name", pet->name) == NULL) {
|
if(cJSON_AddStringToObject(item, "name", pet->name) == NULL) {
|
||||||
goto fail; //String
|
goto fail; //String
|
||||||
}
|
}
|
||||||
@ -113,7 +112,6 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
|||||||
if (!pet->photo_urls) {
|
if (!pet->photo_urls) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *photo_urls = cJSON_AddArrayToObject(item, "photoUrls");
|
cJSON *photo_urls = cJSON_AddArrayToObject(item, "photoUrls");
|
||||||
if(photo_urls == NULL) {
|
if(photo_urls == NULL) {
|
||||||
goto fail; //primitive container
|
goto fail; //primitive container
|
||||||
@ -149,12 +147,12 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
|||||||
|
|
||||||
|
|
||||||
// pet->status
|
// pet->status
|
||||||
|
if(pet->status != openapi_petstore_pet_STATUS_NULL) {
|
||||||
if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
|
if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
|
||||||
{
|
{
|
||||||
goto fail; //Enum
|
goto fail; //Enum
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
fail:
|
fail:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user