Skip to content

[BUG] qt-client missing qHash and operator== for schemes with unique models #11621

@Thaulino

Description

@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

https://app.swaggerhub.com/apis/Pepperl-Fuchs/Sensorik4.0/1.0.0#/common.identification.identification_1

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
  1. 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"
	]
}
  1. Download the mentioned oai specification
  2. Run open-api-generator
  3. 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 ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions