[C++] [cpp-rest-sdk] Check for null values (#990)

* Check whether a value is present but null

* Update Petstore sample
This commit is contained in:
Juan Eugenio Abadie 2018-09-10 13:15:44 -03:00 committed by William Cheng
parent 6a1e560540
commit 2d99836e90
37 changed files with 177 additions and 79 deletions

View File

@ -140,7 +140,11 @@ void {{classname}}::fromJson(web::json::value& val)
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
{{setter}}(ModelBase::{{baseType}}FromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("{{baseName}}")];
if(!fieldValue.is_null())
{
{{setter}}(ModelBase::{{baseType}}FromJson(fieldValue));
}
}
{{/required}}
{{#required}}
@ -241,29 +245,30 @@ void {{classname}}::fromJson(web::json::value& val)
{{^isPrimitiveType}}
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
web::json::value& fieldValue = val[utility::conversions::to_string_t("{{baseName}}")];
if(!fieldValue.is_null())
{
{{#isString}}
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{setter}}(ModelBase::dateFromJson(fieldValue));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}
if(!val[utility::conversions::to_string_t("{{baseName}}")].is_null())
{
{{{dataType}}} newItem({{{defaultValue}}});
newItem->fromJson(val[utility::conversions::to_string_t("{{baseName}}")]);
newItem->fromJson(fieldValue);
{{setter}}( newItem );
}
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
}
}
{{/required}}
{{#required}}
{{#isString}}

View File

@ -1 +1 @@
3.2.2-SNAPSHOT
3.3.0-SNAPSHOT

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -61,15 +61,27 @@ void ApiResponse::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("code")))
{
setCode(ModelBase::int32_tFromJson(val[utility::conversions::to_string_t("code")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("code")];
if(!fieldValue.is_null())
{
setCode(ModelBase::int32_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("type")))
{
setType(ModelBase::stringFromJson(val[utility::conversions::to_string_t("type")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("type")];
if(!fieldValue.is_null())
{
setType(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("message")))
{
setMessage(ModelBase::stringFromJson(val[utility::conversions::to_string_t("message")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("message")];
if(!fieldValue.is_null())
{
setMessage(ModelBase::stringFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -55,11 +55,19 @@ void Category::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("name")))
{
setName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("name")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("name")];
if(!fieldValue.is_null())
{
setName(ModelBase::stringFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -79,27 +79,51 @@ void Order::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("petId")))
{
setPetId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("petId")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("petId")];
if(!fieldValue.is_null())
{
setPetId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("quantity")))
{
setQuantity(ModelBase::int32_tFromJson(val[utility::conversions::to_string_t("quantity")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("quantity")];
if(!fieldValue.is_null())
{
setQuantity(ModelBase::int32_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("shipDate")))
{
setShipDate(ModelBase::dateFromJson(val[utility::conversions::to_string_t("shipDate")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("shipDate")];
if(!fieldValue.is_null())
{
setShipDate(ModelBase::dateFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("status")))
{
setStatus(ModelBase::stringFromJson(val[utility::conversions::to_string_t("status")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("status")];
if(!fieldValue.is_null())
{
setStatus(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("complete")))
{
setComplete(ModelBase::boolFromJson(val[utility::conversions::to_string_t("complete")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("complete")];
if(!fieldValue.is_null())
{
setComplete(ModelBase::boolFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -82,14 +82,19 @@ void Pet::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("category")))
{
if(!val[utility::conversions::to_string_t("category")].is_null())
web::json::value& fieldValue = val[utility::conversions::to_string_t("category")];
if(!fieldValue.is_null())
{
std::shared_ptr<Category> newItem(new Category());
newItem->fromJson(val[utility::conversions::to_string_t("category")]);
newItem->fromJson(fieldValue);
setCategory( newItem );
}
}
@ -124,7 +129,11 @@ void Pet::fromJson(web::json::value& val)
}
if(val.has_field(utility::conversions::to_string_t("status")))
{
setStatus(ModelBase::stringFromJson(val[utility::conversions::to_string_t("status")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("status")];
if(!fieldValue.is_null())
{
setStatus(ModelBase::stringFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -55,11 +55,19 @@ void Tag::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("name")))
{
setName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("name")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("name")];
if(!fieldValue.is_null())
{
setName(ModelBase::stringFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@ -91,35 +91,67 @@ void User::fromJson(web::json::value& val)
{
if(val.has_field(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("username")))
{
setUsername(ModelBase::stringFromJson(val[utility::conversions::to_string_t("username")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("username")];
if(!fieldValue.is_null())
{
setUsername(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("firstName")))
{
setFirstName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("firstName")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("firstName")];
if(!fieldValue.is_null())
{
setFirstName(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("lastName")))
{
setLastName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("lastName")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("lastName")];
if(!fieldValue.is_null())
{
setLastName(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("email")))
{
setEmail(ModelBase::stringFromJson(val[utility::conversions::to_string_t("email")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("email")];
if(!fieldValue.is_null())
{
setEmail(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("password")))
{
setPassword(ModelBase::stringFromJson(val[utility::conversions::to_string_t("password")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("password")];
if(!fieldValue.is_null())
{
setPassword(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("phone")))
{
setPhone(ModelBase::stringFromJson(val[utility::conversions::to_string_t("phone")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("phone")];
if(!fieldValue.is_null())
{
setPhone(ModelBase::stringFromJson(fieldValue));
}
}
if(val.has_field(utility::conversions::to_string_t("userStatus")))
{
setUserStatus(ModelBase::int32_tFromJson(val[utility::conversions::to_string_t("userStatus")]));
web::json::value& fieldValue = val[utility::conversions::to_string_t("userStatus")];
if(!fieldValue.is_null())
{
setUserStatus(ModelBase::int32_tFromJson(fieldValue));
}
}
}

View File

@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/