[BUG] qt-client missing qHash and operator== for schemes with unique models
Created by: Thaulino
Bug Report Checklist
-
How to reproduce ? -
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
😃
First of all: Props to all contributors and thanks for the openapi-generator Description
The generated code produced by the qt-client generator does not compile, if a scheme is included which includes lists of unique items.
openapi-generator version
- 5.2.0
- openapi-generator-cli-6.0.0-20211025.061654-22.jar (newest ?)
OpenAPI declaration file content or url
alternative: www.pepperl-fuchs.com/openapi -> click on Pepperl+Fuchs Sensorik4.0® will be redirected
The issue is rooted in the SCHEMAS:
- common.identification.identification
- common.identification.identification_1
which include sets of unique objects.
Generation Details
Unsure what i should enter here:
i am using vcpkg, c++, CMake and qt,
platform: win10
ide: vs2019
Steps to reproduce
- Install dependencies
If you are using vcpkg: My vcpkg.json
{
"name": "openapisensorik40",
"version-string" : "1.0",
"description": "project to implement the openapisensorik40",
"dependencies": [
"qt5-base",
"openssl"
]
}
- Download the mentioned oai specification
- Run open-api-generator
- Run Cmake to configure and build the library
An error is thrown, something like:
qHash: none of the 37 overloads could convert argument types for OAICommon_identification_identification_1 OAICommon_identification_identification
Related issues/PRs
None?
Suggest a fix
From my point of view the issue is cause in some missing definition in order to make qhash(needed by QSet ) with a custom class work:
Refer: https://doc.qt.io/qt-5/qhash.html#qhash
I fixxed the issue by adding an operator== and a hash function to the classes.
Wihtin OAICommon_identification_identification_1.h: Add following function/ properties: to OAICommon_identification_identification_1 Within class definition (public)
bool operator==(const OAICommon_identification_identification_1& other) const {
return (this->asJsonObject() == other.asJsonObject());
}
End of file prior #endif
inline uint qHash(const OpenAPI::OAICommon_identification_identification_1& obj, uint seed = 0)
{
return qHash(obj.asJsonObject(), seed);
}
Wihtin OAICommon_identification_identification_2.h: Add following function/ properties: to OAICommon_identification_identification_2 Within class definition (public)
bool operator==(const OAICommon_identification_identification_2& other) const {
return (this->asJsonObject() == other.asJsonObject());
}
End of file prior #endif
inline uint qHash(const OpenAPI::OAICommon_identification_identification_2& obj, uint seed = 0)
{
return qHash(obj.asJsonObject(), seed);
}
Well i think it is possible to add this to the corresponding mustache file, but right now i am pretty unsure where to start and if it is enough or need some additional coding.
Can someone advice ?