Skip to content

[cpp-restsdk] store Object as a shared pointer #21349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aminya
Copy link
Contributor

@aminya aminya commented May 29, 2025

This fixes serialization and usage of Objects by wrapping it in shared_ptr. These methods all rely on the shared_ptr, and without it methods like toJson, fromString, etc. will fail to compile.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@aminya aminya force-pushed the object-sharedptr branch from 2e5c8c1 to 72501a9 Compare June 3, 2025 06:43
@wing328
Copy link
Member

wing328 commented Jun 3, 2025

thanks for the pr

cc @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @MartinDelille (2018/03) @muttleyxd (2019/08) @aminya (2025/05)

@wing328 wing328 added this to the 7.14.0 milestone Jun 3, 2025
@muttleyxd
Copy link
Contributor

The CI pipeline is failing now

[INFO] --- exec:1.2.1:exec (cmake) @ CppRestPetstoreClientTests ---
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- The CXX compiler identification is Clang 17.0.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/llvm-17/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")  
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")  
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0")  
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client
[INFO] 
[INFO] --- exec:1.2.1:exec (make) @ CppRestPetstoreClientTests ---
[  3%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/AnyType.cpp.o
[  7%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/ApiClient.cpp.o
[ 11%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/ApiConfiguration.cpp.o
[ 15%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/ApiException.cpp.o
[ 19%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/HttpContent.cpp.o
[ 23%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/JsonBody.cpp.o
[ 26%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/ModelBase.cpp.o
[ 30%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/MultipartFormData.cpp.o
[ 34%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/Object.cpp.o
[ 38%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/PetApi.cpp.o
[ 42%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/StoreApi.cpp.o
[ 46%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/UserApi.cpp.o
[ 50%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/UserOrPetApi.cpp.o
[ 53%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/ApiResponse.cpp.o
[ 57%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Category.cpp.o
[ 61%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Color.cpp.o
[ 65%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/CreateUserOrPet_request.cpp.o
[ 69%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Order.cpp.o
[ 73%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Page.cpp.o
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:14:
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Page.h:22:
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:222:23: error: no member named 'toJson' in 'std::basic_string<char>'
  222 |         retVal = val->toJson();
      |                  ~~~~~^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:234:24: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::toJson<std::basic_string<char>>' requested here
  234 |         ret.push_back( toJson(x) );
      |                        ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:55:90: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::toJson<std::shared_ptr<std::basic_string<char>>>' requested here
   55 |         val[utility::conversions::to_string_t(_XPLATSTR("reference_test"))] = ModelBase::toJson(m_Reference_test);
      |                                                                                          ^
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:14:
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Page.h:22:
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:353:22: error: no member named 'fromJson' in 'std::basic_string<char>'
  353 |         ok = outVal->fromJson(val);
      |              ~~~~~~~~^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:366:19: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::fromJson<std::basic_string<char>>' requested here
  366 |             ok &= fromJson(jitem, item);
      |                   ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:92:30: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::fromJson<std::shared_ptr<std::basic_string<char>>>' requested here
   92 |             ok &= ModelBase::fromJson(fieldValue, refVal_setReferenceTest);
      |                              ^
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:14:
In file included from /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Page.h:22:
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:287:19: error: no matching function for call to 'fromJson'
  287 |             ok &= fromJson(jitem, item);
      |                   ^~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:482:12: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::fromString<std::shared_ptr<std::basic_string<char>>>' requested here
  482 |     return fromString(str, outVal);
      |            ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp:145:26: note: in instantiation of function template specialization 'org::openapitools::client::model::ModelBase::fromHttpContent<std::shared_ptr<std::basic_string<char>>>' requested here
  145 |         ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("reference_test"))), refVal_setReferenceTest );
      |                          ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:108:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'bool &' for 2nd argument
  108 |     static bool fromJson( const web::json::value& val, bool & );
      |                 ^                                      ~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:109:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'float &' for 2nd argument
  109 |     static bool fromJson( const web::json::value& val, float & );
      |                 ^                                      ~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:110:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'double &' for 2nd argument
  110 |     static bool fromJson( const web::json::value& val, double & );
      |                 ^                                      ~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:111:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'int32_t &' (aka 'int &') for 2nd argument
  111 |     static bool fromJson( const web::json::value& val, int32_t & );
      |                 ^                                      ~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:112:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'int64_t &' (aka 'long &') for 2nd argument
  112 |     static bool fromJson( const web::json::value& val, int64_t & );
      |                 ^                                      ~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:113:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'utility::string_t &' (aka 'basic_string<char> &') for 2nd argument
  113 |     static bool fromJson( const web::json::value& val, utility::string_t & );
      |                 ^                                      ~~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:114:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'utility::datetime &' for 2nd argument
  114 |     static bool fromJson( const web::json::value& val, utility::datetime & );
      |                 ^                                      ~~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:115:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'web::json::value &' for 2nd argument
  115 |     static bool fromJson( const web::json::value& val, web::json::value & );
      |                 ^                                      ~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:116:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'std::shared_ptr<HttpContent> &' for 2nd argument
  116 |     static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
      |                 ^                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:119:17: note: candidate function not viable: no known conversion from 'std::shared_ptr<std::basic_string<char>>' to 'std::shared_ptr<utility::datetime> &' for 2nd argument
  119 |     static bool fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal );
      |                 ^                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:118:17: note: candidate template ignored: substitution failure [with T = std::basic_string<char>]
  118 |     static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
      |                 ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:121:17: note: candidate template ignored: could not match 'vector' against 'shared_ptr'
  121 |     static bool fromJson( const web::json::value& val, std::vector<T> & );
      |                 ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:123:17: note: candidate template ignored: could not match 'set' against 'shared_ptr'
  123 |     static bool fromJson( const web::json::value& val, std::set<T> & );
      |                 ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:125:17: note: candidate template ignored: could not match 'map' against 'shared_ptr'
  125 |     static bool fromJson( const web::json::value& val, std::map<utility::string_t, T> & );
      |                 ^
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:47:18: note: candidate function not viable: requires single argument 'json', but 2 arguments were provided
   47 |     virtual bool fromJson( const web::json::value& json ) = 0;
      |                  ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h:294:14: error: no matching function for call to 'fromJson'
  294 |         ok = fromJson(jsonValue, item);
      |              ^~~~~~~~

@aminya aminya force-pushed the object-sharedptr branch from 72501a9 to a87cb3b Compare June 5, 2025 05:44
@aminya aminya changed the title [cpp-restsdk] store Object as a shared pointer [cpp-restsdk] support exploded and deep object query parameters Jun 5, 2025
@aminya
Copy link
Contributor Author

aminya commented Jun 5, 2025

@muttleyxd I had missed to upstream some of the commits from my main given that #21223 isn't merged yet.

@aminya aminya changed the title [cpp-restsdk] support exploded and deep object query parameters [cpp-restsdk] support exploded, deep object, map, and model parameters Jun 5, 2025
@aminya aminya force-pushed the object-sharedptr branch 2 times, most recently from feb8cfa to 43a3ada Compare June 5, 2025 06:51
@aminya aminya changed the title [cpp-restsdk] support exploded, deep object, map, and model parameters [cpp-restsdk] store Object as a shared pointer Jun 5, 2025
@aminya aminya force-pushed the object-sharedptr branch from 43a3ada to 98c07e7 Compare June 5, 2025 06:59
@aminya
Copy link
Contributor Author

aminya commented Jun 5, 2025

@muttleyxd Fixed the tests. I decided to separate the other improvements for now. Hopefully, we can speed up the review process so that I can upstream all the changes.

@aminya aminya force-pushed the object-sharedptr branch from 98c07e7 to 1c8681e Compare June 5, 2025 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants