Skip to content
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

Implemented missing definitions of declared methods inside modelbase-header.mustache, added two missing body of methods definitions #19569

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

Conversation

SaverioCode
Copy link

Fix #19566 implemented missing definitions of declared methods inside modelbase-header.mustache for the cpp-rest-sdk-client
I have also added two missing body of methods definitions

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 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    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.6.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.
    @ravinikam @stkrwork @etherealjoy @MartinDelille @muttleyxd

… methods inside openapi-generator/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache, have also be added two missing body of methods definitions
Copy link
Contributor

@muttleyxd muttleyxd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it'd be good to fix shared_ptr creation

@muttleyxd
Copy link
Contributor

Looks good now!

if( val != nullptr )
{
val->toJson().serialize(ss);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaverioCode thanks for the PR

quick question if you don't mind. why remove the null check here and below (line 208)?

Copy link
Author

@SaverioCode SaverioCode Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaverioCode thanks for the PR

quick question if you don't mind. why remove the null check here and below (line 208)?

Hi!

I removed them in several places because they are reference and in c++ they can't be nullptr for definition. There is a compile error if a reference is nullptr. A reference is an alias to an already-existing object or function. So in this scenario the shared_ptr can't be nullptr, what could actually be invalid is the pointer inside the shared_ptr, the content of the referred object, but not the object itself
As it's done for any object that contains pointers, I suppose it would make sense to check the content of the shared_ptr (it's not what was happening), but being a shared_ptr I would assume that the pointer inside it's valid or I would think more of a program logic error. But this last consideration can be different from team to team

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation

cc @etherealjoy who added the nullptr check to see if he's further comment/question on this

@wing328 wing328 changed the title Fix #19566 implemented missing definitions of declared methods inside openapi-generator/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache, I have also added two missing body of methods definitions Implemented missing definitions of declared methods inside modelbase-header.mustache, added two missing body of methods definitions Sep 16, 2024
@wing328
Copy link
Member

wing328 commented Sep 16, 2024

thanks again for the PR

seems like I couldn't repeat the issue. I got the following (tests ok) when running mvn integration-test -f samples/client/petstore/cpp-restsdk/client/pom.xml

[ 52%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/UserOrPetApi.cpp.o
[ 56%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/ApiResponse.cpp.o
[ 60%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Category.cpp.o
[ 64%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/CreateUserOrPet_request.cpp.o
[ 68%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Order.cpp.o
[ 72%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Pet.cpp.o
[ 76%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Pet_vaccinationBook.cpp.o
[ 80%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/SchemaWithSet.cpp.o
[ 84%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/SchemaWithSet_vaccinationBook.cpp.o
[ 88%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Tag.cpp.o
[ 92%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/User.cpp.o
[ 96%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Vaccine.cpp.o
[100%] Linking CXX static library libCppRestPetstoreClient.a
[100%] Built target CppRestPetstoreClient
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:26 min
[INFO] Finished at: 2024-09-16T17:32:30+08:00
[INFO] ------------------------------------------------------------------------

does it work for you locally?

how can we repeat the issue?

@wing328 wing328 added this to the 7.9.0 milestone Sep 16, 2024
@SaverioCode
Copy link
Author

thanks again for the PR

seems like I couldn't repeat the issue. I got the following (tests ok) when running mvn integration-test -f samples/client/petstore/cpp-restsdk/client/pom.xml

[ 52%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/api/UserOrPetApi.cpp.o
[ 56%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/ApiResponse.cpp.o
[ 60%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Category.cpp.o
[ 64%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/CreateUserOrPet_request.cpp.o
[ 68%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Order.cpp.o
[ 72%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Pet.cpp.o
[ 76%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Pet_vaccinationBook.cpp.o
[ 80%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/SchemaWithSet.cpp.o
[ 84%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/SchemaWithSet_vaccinationBook.cpp.o
[ 88%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Tag.cpp.o
[ 92%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/User.cpp.o
[ 96%] Building CXX object CMakeFiles/CppRestPetstoreClient.dir/src/model/Vaccine.cpp.o
[100%] Linking CXX static library libCppRestPetstoreClient.a
[100%] Built target CppRestPetstoreClient
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:26 min
[INFO] Finished at: 2024-09-16T17:32:30+08:00
[INFO] ------------------------------------------------------------------------

does it work for you locally?

how can we repeat the issue?

The first time I got the error I was on Windows, and I created a visual studio solution to test it and I got the Linking problem.

On Linux is compiling perfectly, with both gnu and clang. From those test is not possible to caught the error.
The Linking error appear only when one of the methods (without the definition) is actually called in a program. If you create a small main.cpp just to invoke one of the missing methods your are going to have it.

On Windows running mvn integration-test -f samples/client/petstore/cpp-restsdk/client/pom.xml I got:

[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.


-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The CXX compiler identification is MSVC 19.41.34120.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building client library for Windows
-- Configuring done (3.4s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/<username>/openapi-generator/samples/client/petstore/cpp-restsdk/client
[INFO]
[INFO] --- exec:1.2.1:exec (make) @ CppRestPetstoreClientTests ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.916 s
[INFO] Finished at: 2024-09-18T00:11:53+02:00
[INFO] ------------------------------------------------------------------------
[INFO] 3 goals, 3 executed

@SaverioCode
Copy link
Author

@muttleyxd @wing328 I changed only the missing methods implementation and the shared_ptr creation. I found out that the == operator for shared_ptr actually compare the pointers. I suppose this is why @etherealjoy introduced those checks

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.

[BUG][CPP-RESTSDK] Linking errors due to missing definition of declared methods in ModelBase.h
3 participants