Skip to content

Commit 7520308

Browse files
dan-drlwing328
authored andcommitted
Fix issue deserializing to nullptr (#3572)
* Fix issue deserializing to nullptr * Update codegen files
1 parent 36dd848 commit 7520308

40 files changed

+109
-47
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ public String toDefaultValue(Schema p) {
359359
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
360360
} else if (ModelUtils.isStringSchema(p)) {
361361
return "utility::conversions::to_string_t(\"\")";
362+
} else if (ModelUtils.isFreeFormObject(p)) {
363+
return "new Object()";
362364
}
365+
363366
return "nullptr";
364367
}
365368

modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-source.mustache

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,32 +265,35 @@ std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& en
265265

266266
int64_t ModelBase::int64_tFromJson(const web::json::value& val)
267267
{
268-
return val.as_number().to_int64();
268+
return val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
269269
}
270+
270271
int32_t ModelBase::int32_tFromJson(const web::json::value& val)
271272
{
272-
return val.as_integer();
273+
return val.is_null() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
273274
}
275+
274276
float ModelBase::floatFromJson(const web::json::value& val)
275277
{
276-
return static_cast<float>(val.as_double());
278+
return val.is_null() ? std::numeric_limits<float>::quiet_NaN() : static_cast<float>(val.as_double());
277279
}
280+
278281
utility::string_t ModelBase::stringFromJson(const web::json::value& val)
279282
{
280283
return val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
281284
}
282285

283286
utility::datetime ModelBase::dateFromJson(const web::json::value& val)
284287
{
285-
return utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
288+
return val.is_null() ? utility::datetime::from_string(L"NULL", utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
286289
}
287290
bool ModelBase::boolFromJson(const web::json::value& val)
288291
{
289-
return val.as_bool();
292+
return val.is_null() ? false : val.as_bool();
290293
}
291294
double ModelBase::doubleFromJson(const web::json::value& val)
292295
{
293-
return val.as_double();
296+
return val.is_null() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
294297
}
295298

296299
int64_t ModelBase::int64_tFromHttpContent(std::shared_ptr<HttpContent> val)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Compiled Object files
2+
*.slo
3+
*.lo
4+
*.o
5+
*.obj
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Compiled Dynamic libraries
12+
*.so
13+
*.dylib
14+
*.dll
15+
16+
# Fortran module files
17+
*.mod
18+
*.smod
19+
20+
# Compiled Static libraries
21+
*.lai
22+
*.la
23+
*.a
24+
*.lib
25+
26+
# Executables
27+
*.exe
28+
*.out
29+
*.app
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.1.0-SNAPSHOT

samples/client/petstore/cpp-restsdk/client/ApiClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The version of the OpenAPI document: 1.0.0
66
*
7-
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.2-SNAPSHOT.
7+
* NOTE: This class is auto generated by OpenAPI-Generator 4.1.0-SNAPSHOT.
88
* https://openapi-generator.tech
99
* Do not edit the class manually.
1010
*/

samples/client/petstore/cpp-restsdk/client/ApiClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The version of the OpenAPI document: 1.0.0
66
*
7-
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.2-SNAPSHOT.
7+
* NOTE: This class is auto generated by OpenAPI-Generator 4.1.0-SNAPSHOT.
88
* https://openapi-generator.tech
99
* Do not edit the class manually.
1010
*/

samples/client/petstore/cpp-restsdk/client/ApiConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The version of the OpenAPI document: 1.0.0
66
*
7-
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.2-SNAPSHOT.
7+
* NOTE: This class is auto generated by OpenAPI-Generator 4.1.0-SNAPSHOT.
88
* https://openapi-generator.tech
99
* Do not edit the class manually.
1010
*/

samples/client/petstore/cpp-restsdk/client/ApiConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The version of the OpenAPI document: 1.0.0
66
*
7-
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.2-SNAPSHOT.
7+
* NOTE: This class is auto generated by OpenAPI-Generator 4.1.0-SNAPSHOT.
88
* https://openapi-generator.tech
99
* Do not edit the class manually.
1010
*/

samples/client/petstore/cpp-restsdk/client/ApiException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The version of the OpenAPI document: 1.0.0
66
*
7-
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.2-SNAPSHOT.
7+
* NOTE: This class is auto generated by OpenAPI-Generator 4.1.0-SNAPSHOT.
88
* https://openapi-generator.tech
99
* Do not edit the class manually.
1010
*/

0 commit comments

Comments
 (0)