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

[Cpp][Qt][client] Fixed issue with unique items in OpenAPI schema #11954

Merged

Conversation

Thaulino
Copy link
Contributor

Details of change

object.mustache
Added equal operator
Added qhash Operator

This way, the schema can be stored in a QSet
in api template
depending on unique items
output.insert(val) -- QSet (unique items)
or
ouput.append(val) -- QList (not unique items)

Test done

  • does the latest openapi-generator generate valid code ?
    I used the same openapi as attached to this issue [BUG] [Qt5][Cpp] Unique items in schema lead to error #11951
    java -jar openapi-generator-cli-5.4.0.jar generate -t cpp-qt-templates -i unique_petstore.json -g cpp-qt-client -o unique_petstore
    Build the library with cmake

related issues

resolves #11621
resolves #11951

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/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
  • [ ]

technical committee

@muttleyxd
@etherealjoy
@wing328

Changed: Always add Qt5::Gui to build
Added: find_package for OpenSSL (if not Apple)
Added equal operator for schema objects
Added qhash Operator

in api template
depending on unique items
output.insert(val) -- QSet (unique items)
or
ouput.appen(val) -- QList (not unique items)
@wing328
Copy link
Member

wing328 commented Mar 24, 2022

@canadaduane thanks for the PR. Please update the samples (step 3 in the PR checklist)

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

@canadaduane
Copy link
Contributor

I think you mis-tagged me.

@Thaulino
Copy link
Contributor Author

Thaulino commented Mar 25, 2022

Okay now i have added a schema for the petstore with unique items plus a config to run the generator on that.
I see some testcode within openapi-generator/samples/client/petstore/cpp-qt/PetStore which seem to run against a server.
Unfortunately i don't know how all this is setup and tear down can someone advice ?
Even if it is not needed, i would like to understand how it works

@wing328
Copy link
Member

wing328 commented Mar 26, 2022

@canadaduane sorry

Copy link
Contributor

@MartinDelille MartinDelille left a comment

Choose a reason for hiding this comment

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

Little typo: unqiue => unique

bin/configs/cpp-qt-client-petstore-unique.yaml Outdated Show resolved Hide resolved
bin/configs/cpp-qt-client-petstore-unique.yaml Outdated Show resolved Hide resolved
@wing328 wing328 changed the title [Cpp][Qt][client] Fixed iisue with unique items in OpenAPI schema [Cpp][Qt][client] Fixed issue with unique items in OpenAPI schema Mar 27, 2022
@wing328 wing328 added this to the 6.0.0 milestone Mar 27, 2022
@wing328
Copy link
Member

wing328 commented Mar 27, 2022

Can you please add the file modules/openapi-generator/src/test/resources/2_0/petstore_plus_unique.json to the PR?

@Thaulino
Copy link
Contributor Author

Somehow Node 0 failed ☹
https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/16507/workflows/f2b5272d-e91c-4f0e-b272-bea97a0ac288/jobs/34844?invite=true#step-114-871
Unfortunately i don't understand what is meant by the error output,
Need help/ Please help, thank you

@wing328
Copy link
Member

wing328 commented Mar 28, 2022

For circleci failure, please ignore that for the time being.

@Thaulino
Copy link
Contributor Author

Thaulino commented Apr 8, 2022

@wing328 Is there anything left to do for me ?

@wing328
Copy link
Member

wing328 commented Apr 13, 2022

@Thaulino thanks for the PR. I've merged #12124 into master to use a different spec for C++ qt 5 petstore client.

Can you please rebase/merge latest master into your branch and add those tests in modules/openapi-generator/src/test/resources/3_0/petstore_plus_unique.json to modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml instead?

@wing328
Copy link
Member

wing328 commented Apr 13, 2022

For CircleCI node 0 failure, please ignore it as it's not related to this change.

@Thaulino
Copy link
Contributor Author

Thaulino commented May 1, 2022

@wing328 I had some spare time and rebased like you requested.
I deleted the obsolete stuff (refer to 79053b0)
and updated the samples.
Please give me some feedback if it is fine or not - thank you

@wing328
Copy link
Member

wing328 commented May 3, 2022

I tested it in the CI but got the following errors:

make -f client/CMakeFiles/client.dir/build.make client/CMakeFiles/client.dir/depend
make[2]: Entering directory '/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build'
cd /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build && /usr/local/cmake-3.12.4/bin/cmake -E cmake_depends "Unix Makefiles" /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build/client /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build/client/CMakeFiles/client.dir/DependInfo.cmake --color=
Scanning dependencies of target client
make[2]: Leaving directory '/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build'
make -f client/CMakeFiles/client.dir/build.make client/CMakeFiles/client.dir/build
make[2]: Entering directory '/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build'
[  8%] Building CXX object client/CMakeFiles/client.dir/PFXApiResponse.cpp.o
cd /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build/client && /usr/bin/g++-5  -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -I/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build/client -I/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client -I/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build/client/client_autogen/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -isystem /usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui  -fPIC -Wall -Wno-unused-variable -fPIC -Wall -Wno-unused-variable   -fPIC -std=c++14 -o CMakeFiles/client.dir/PFXApiResponse.cpp.o -c /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXApiResponse.cpp
In file included from /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXApiResponse.h:26:0,
                 from /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXApiResponse.cpp:12:
/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXObject.h: In function ‘uint test_namespace::qHash(const test_namespace::PFXObject&, uint)’:
/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXObject.h:66:34: error: invalid initialization of reference of type ‘const test_namespace::PFXObject&’ from expression of type ‘QJsonObject’
     return qHash(obj.asJsonObject(), seed);
                                  ^
/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/client/PFXObject.h:65:13: note: in passing argument 1 of ‘uint test_namespace::qHash(const test_namespace::PFXObject&, uint)’
 inline uint qHash(const PFXObject& obj, uint seed = 0) noexcept{
             ^
client/CMakeFiles/client.dir/build.make:65: recipe for target 'client/CMakeFiles/client.dir/PFXApiResponse.cpp.o' failed
make[2]: Leaving directory '/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build'
make[2]: *** [client/CMakeFiles/client.dir/PFXApiResponse.cpp.o] Error 1
CMakeFiles/Makefile2:164: recipe for target 'client/CMakeFiles/client.dir/all' failed
make[1]: Leaving directory '/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/cpp-qt/build'
make[1]: *** [client/CMakeFiles/client.dir/all] Error 2
make: *** [all] Error 2
Makefile:132: recipe for target 'all' failed
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (pet-test) on project CppQt5PetstoreClientTests: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (pet-test) on project CppQt5PetstoreClientTests: Command execution failed.

Can you please take a look when you've time?

Ref: https://app.travis-ci.com/github/OpenAPITools/openapi-generator/builds/250142967

@Thaulino
Copy link
Contributor Author

Thaulino commented May 3, 2022

@wing328 : Thanks for testing and reviewing

Hi,

My interpretation of the error: Somehow the compiler doesn't find an overloaded version of qhash with the signature
qhash(QJsonObject, uint) so it tries to implicit cast the types which does not work.

Disclaimer: I am not that deep into travis ci, containerization and so on

Educated guess:
As far as i understand the configuration, it is running on ubuntu xenial with g++-5, it would be interesting to know which qt version is running.
I guess this one: https://launchpad.net/ubuntu/xenial/+package/qtbase5-dev
so version qt5.5, which is pretty old
Maybe this version had not implemented a qhash function for QJsonObjects.

Next steps:
i will try to run a docker container with the xenial image, install the qt base stuff and try to compile a minimal test in cpp (call qhash with a QjsonObjetc).
It it fails, == the qt version really does not implement a qhash function, the ubuntu version should be updated (travis ci)

it does not fail: my educated guess is wrong

@Thaulino
Copy link
Contributor Author

Thaulino commented May 4, 2022

Hi,

I have created some minimal test setup based on docker
https://github.com/Thaulino/qt5-ubuntu-docker-qhash-qjsonobj
Well the build passes on focal and fails on xenial with

/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:104:16: note:   'const QJsonObject' is not derived from 'const QSharedDataPointer<T>'
 { return (qHash(t) ^ seed); }
                ^
/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:144:49: note: candidate: template<class T1, class T2> uint qHash(const QPair<T1, T2>&, uint)
 template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key,
                                                 ^
/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:144:49: note:   template argument deduction/substitution failed:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:104:16: note:   'const QJsonObject' is not derived from 'const QPair<T1, T2>'
 { return (qHash(t) ^ seed); }

Looks similiar to the issue in travis ci, so it seems like the needed qhash function isn't implemented

root@d50123fb3380:/home# qmake -v
QMake version 3.0
Using Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu

My suggestion is to update the ubuntu version used in travis ci
@wing328 : is that possible ? do you agree with the conclusion ?

@wing328
Copy link
Member

wing328 commented May 8, 2022

Tested locally with a Linux box instead and the result is good:

Totals: 5 passed, 0 failed, 0 skipped, 0 blacklisted, 29ms
********* Finished testing of StoreApiTests *********
********* Start testing of UserApiTests *********
Config: Using QtTest library 5.12.8, Qt 5.12.8 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 9.3.0)
PASS   : UserApiTests::initTestCase()
QDEBUG : UserApiTests::createUserTest() got a request body
PASS   : UserApiTests::createUserTest()
QDEBUG : UserApiTests::createUsersWithArrayInputTest() got a request body
PASS   : UserApiTests::createUsersWithArrayInputTest()
QDEBUG : UserApiTests::createUsersWithListInputTest() got a request body
PASS   : UserApiTests::createUsersWithListInputTest()
QDEBUG : UserApiTests::deleteUserTest() Error happened while issuing request :  "Error transferring http://petstore.swagger.io/v2/user/rambo - server replied: Not Found, "
PASS   : UserApiTests::deleteUserTest()
QDEBUG : UserApiTests::getUserByNameTest() "johndoe"
PASS   : UserApiTests::getUserByNameTest()
QDEBUG : UserApiTests::loginUserTest() "{\"code\":200,\"type\":\"unknown\",\"message\":\"logged in user session:1651994014470\"}"
PASS   : UserApiTests::loginUserTest()
PASS   : UserApiTests::logoutUserTest()
QDEBUG : UserApiTests::updateUserTest() got a request body
PASS   : UserApiTests::updateUserTest()
PASS   : UserApiTests::cleanupTestCase()
Totals: 10 passed, 0 failed, 0 skipped, 0 blacklisted, 81ms
********* Finished testing of UserApiTests *********
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:36 min
[INFO] Finished at: 2022-05-08T15:13:34+08:00
[INFO] ------------------------------------------------------------------------

We will test locally instead of using Travis for the time being.

Thanks for the PR.

@wing328 wing328 merged commit b7d079b into OpenAPITools:master May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants