Skip to content

Commit

Permalink
[C++] [cpp-rest-sdk] Check for null values (#990)
Browse files Browse the repository at this point in the history
* Check whether a value is present but null

* Update Petstore sample
  • Loading branch information
whoan authored and wing328 committed Sep 10, 2018
1 parent 6a1e560 commit 2d99836
Show file tree
Hide file tree
Showing 37 changed files with 177 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -242,27 +246,28 @@ void {{classname}}::fromJson(web::json::value& val)
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
{{#isString}}
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}
if(!val[utility::conversions::to_string_t("{{baseName}}")].is_null())
web::json::value& fieldValue = val[utility::conversions::to_string_t("{{baseName}}")];
if(!fieldValue.is_null())
{
{{#isString}}
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromJson(fieldValue));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}
{{{dataType}}} newItem({{{defaultValue}}});
newItem->fromJson(val[utility::conversions::to_string_t("{{baseName}}")]);
newItem->fromJson(fieldValue);
{{setter}}( newItem );
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
}
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
}
{{/required}}
{{#required}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2-SNAPSHOT
3.3.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
20 changes: 16 additions & 4 deletions samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
14 changes: 11 additions & 3 deletions samples/client/petstore/cpp-restsdk/model/Category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Category.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Loading

0 comments on commit 2d99836

Please sign in to comment.