You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Cpp Code with OneOfs on the property level within another schema can be generated with cpp-restsdk, but building with GCC produces the following errors:
------
> [build 1/1] RUN cmake -DCMAKE_CXX_COMPILER=g++-13 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install /tmp/source && cmake --build . --target install -j$(nproc):
0.593 -- The CXX compiler identification is GNU 13.1.0
0.636 -- Detecting CXX compiler ABI info
1.215 -- Detecting CXX compiler ABI info - done
1.255 -- Check for working CXX compiler: /usr/bin/g++-13 - skipped
1.256 -- Detecting CXX compile features
1.257 -- Detecting CXX compile features - done
1.275 -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
1.282 -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
1.283 CMake Warning (dev) at /usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.30/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
1.283 Policy CMP0167 is not set: The FindBoost module is removed. Run "cmake
1.283 --help-policy CMP0167" for policy details. Use the cmake_policy command to
1.283 set the policy and suppress this warning.
1.283
1.283 Call Stack (most recent call first):
1.283 /usr/lib/x86_64-linux-gnu/cmake/cpprestsdk/cpprestsdk-config.cmake:20 (find_dependency)
1.283 CMakeLists.txt:38 (find_package)
1.283 This warning is for project developers. Use -Wno-dev to suppress it.
1.283
1.827 -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0") found components: random system thread filesystem chrono atomic date_time regex
1.830 CMake Warning (dev) at CMakeLists.txt:39 (find_package):
1.830 Policy CMP0167 is not set: The FindBoost module is removed. Run "cmake
1.830 --help-policy CMP0167" for policy details. Use the cmake_policy command to
1.830 set the policy and suppress this warning.
1.830
1.830 This warning is for project developers. Use -Wno-dev to suppress it.
1.830
1.835 -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0")
1.840 -- Building client library for Linux/Unix
1.846 -- Configuring done (1.6s)
1.870 -- Generating done (0.0s)
1.871 -- Build files have been written to: /tmp/build
2.370 [ 7%] Building CXX object CMakeFiles/example_client.dir/src/ApiException.cpp.o
2.377 [ 14%] Building CXX object CMakeFiles/example_client.dir/src/AnyType.cpp.o
2.378 [ 28%] Building CXX object CMakeFiles/example_client.dir/src/JsonBody.cpp.o
2.379 [ 35%] Building CXX object CMakeFiles/example_client.dir/src/HttpContent.cpp.o
2.379 [ 42%] Building CXX object CMakeFiles/example_client.dir/src/ApiClient.cpp.o
2.379 [ 42%] Building CXX object CMakeFiles/example_client.dir/src/ApiConfiguration.cpp.o
2.388 [ 50%] Building CXX object CMakeFiles/example_client.dir/src/model/MainClass_one_of_property.cpp.o
2.391 [ 57%] Building CXX object CMakeFiles/example_client.dir/src/ModelBase.cpp.o
2.394 [ 64%] Building CXX object CMakeFiles/example_client.dir/src/MultipartFormData.cpp.o
2.399 [ 71%] Building CXX object CMakeFiles/example_client.dir/src/model/MainClass.cpp.o
2.412 [ 78%] Building CXX object CMakeFiles/example_client.dir/src/Object.cpp.o
2.416 [ 85%] Building CXX object CMakeFiles/example_client.dir/src/model/OneOfClass.cpp.o
4.689 [ 92%] Building CXX object CMakeFiles/example_client.dir/src/model/OneOfClass2.cpp.o
5.990 In file included from /tmp/source/include/example_client/model/MainClass.h:22,
5.990 from /tmp/source/src/model/MainClass.cpp:14:
5.990 /tmp/source/include/example_client/ModelBase.h: In instantiation of ‘static bool example::model::ModelBase::fromJson(const web::json::value&, std::shared_ptr<_Tp>&) [with T = example::model::MainClass_one_of_property]’:
5.990 /tmp/source/src/model/MainClass.cpp:58:38: required from here
5.990 /tmp/source/include/example_client/ModelBase.h:285:30: error: no matching function for call to ‘example::model::MainClass_one_of_property::fromJson(const web::json::value&)’
5.990 285 | ok = outVal->fromJson(val);
5.990 | ~~~~~~~~~~~~~~~~^~~~~
5.992 In file included from /tmp/source/include/example_client/model/MainClass.h:24:
5.992 /tmp/source/include/example_client/model/MainClass_one_of_property.h:47:10: note: candidate: ‘template<class Target> bool example::model::MainClass_one_of_property::fromJson(const web::json::value&)’
5.992 47 | bool fromJson(const web::json::value& json) {
5.992 | ^~~~~~~~
5.992 /tmp/source/include/example_client/model/MainClass_one_of_property.h:47:10: note: template argument deduction/substitution failed:
5.994 /tmp/source/include/example_client/ModelBase.h:285:30: note: couldn’t deduce template parameter ‘Target’
5.994 285 | ok = outVal->fromJson(val);
5.994 | ~~~~~~~~~~~~~~~~^~~~~
6.167 /tmp/source/include/example_client/ModelBase.h: In instantiation of ‘static bool example::model::ModelBase::fromString(const utility::string_t&, std::shared_ptr<_Tp>&) [with T = example::model::MainClass_one_of_property; utility::string_t = std::__cxx11::basic_string<char>]’:
6.167 /tmp/source/include/example_client/ModelBase.h:375:22: required from ‘static bool example::model::ModelBase::fromHttpContent(std::shared_ptr<example::model::HttpContent>, std::shared_ptr<_Tp>&) [with T = example::model::MainClass_one_of_property]’
6.167 /tmp/source/src/model/MainClass.cpp:90:41: required from here
6.167 /tmp/source/include/example_client/ModelBase.h:271:30: error: no matching function for call to ‘example::model::MainClass_one_of_property::fromJson(web::json::value)’
6.167 271 | ok = outVal->fromJson(web::json::value::parse(val));
6.167 | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6.167 /tmp/source/include/example_client/model/MainClass_one_of_property.h:47:10: note: candidate: ‘template<class Target> bool example::model::MainClass_one_of_property::fromJson(const web::json::value&)’
6.167 47 | bool fromJson(const web::json::value& json) {
6.167 | ^~~~~~~~
6.167 /tmp/source/include/example_client/model/MainClass_one_of_property.h:47:10: note: template argument deduction/substitution failed:
6.167 /tmp/source/include/example_client/ModelBase.h:271:30: note: couldn’t deduce template parameter ‘Target’
6.167 271 | ok = outVal->fromJson(web::json::value::parse(val));
6.167 | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7.308 cc1plus: note: unrecognized command-line option ‘-Wno-unused-lambda-capture’ may have been intended to silence earlier diagnostics
7.331 gmake[2]: *** [CMakeFiles/example_client.dir/build.make:202: CMakeFiles/example_client.dir/src/model/MainClass.cpp.o] Error 1
7.331 gmake[2]: *** Waiting for unfinished jobs....
14.31 gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/example_client.dir/all] Error 2
14.31 gmake: *** [Makefile:136: all] Error 2
------
1 warning found (use --debug to expand):
- FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1)
Dockerfile:32
--------------------
31 |
32 | >>> RUN cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
33 | >>> -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
34 | >>> -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} /tmp/source \
35 | >>> && cmake --build . --target install -j$(nproc)
36 |
--------------------
ERROR: failed to solve: process "/bin/sh -c cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} /tmp/source && cmake --build . --target install -j$(nproc)" did not complete successfully: exit code: 2
openapi-generator version
Tried with latest docker image (v.7.8.0).
OpenAPI declaration file content or url
This is the minimal example that does not build (minimal_failing_example.yaml):
Generate C++ Code from the openapi document "minimal_failing_example.yaml" with the latest master.
Build with GCC -> this leads to the above-mentioned errors.
Related issues/PRs
This issue exists since v7.7.0.
Prior to v7.7.0 code generation and building does not lead to errors, but oneOf properties are not generated correctly.
In v7.6.0 oneOf properties are essentially generated as if they were in an allOf.
Issue #4239 was suggested to be due to inline-schema handling, which this example does not use.
Issue #6378 describes different faulty behavior in connection with oneOf, allOf and anyOf.
After the before-mentioned issues this fix for oneOfs introducing std::variant was introduced in v7.7.0 which has fixed some cases (see succeeding example) but leads to errors in others (see failing example).
Suggest a fix
The issue seems to be linked to 'from_json' function, which seems to be called without the template parameter.
OneOfs do work when they are on the highest level in a schema definition, which may point towards a possible solution.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Cpp Code with OneOfs on the property level within another schema can be generated with cpp-restsdk, but building with GCC produces the following errors:
openapi-generator version
Tried with latest docker image (v.7.8.0).
OpenAPI declaration file content or url
This is the minimal example that does not build (minimal_failing_example.yaml):
While this is a minimal example of a oneOf on the schema level that does build (minimal_succeeding_example.yaml):
Generation Details
In Unix shell I applied the following commands to generate the code and compile it with GCC.
with the following generator options (generator_options.yml):
This is the Dockerfile to build the C++ code with GCC (Dockerfile):
Steps to reproduce
Related issues/PRs
This issue exists since v7.7.0.
Prior to v7.7.0 code generation and building does not lead to errors, but oneOf properties are not generated correctly.
In v7.6.0 oneOf properties are essentially generated as if they were in an allOf.
Issue #4239 was suggested to be due to inline-schema handling, which this example does not use.
Issue #6378 describes different faulty behavior in connection with oneOf, allOf and anyOf.
After the before-mentioned issues this fix for oneOfs introducing std::variant was introduced in v7.7.0 which has fixed some cases (see succeeding example) but leads to errors in others (see failing example).
Suggest a fix
The issue seems to be linked to 'from_json' function, which seems to be called without the template parameter.
OneOfs do work when they are on the highest level in a schema definition, which may point towards a possible solution.
The text was updated successfully, but these errors were encountered: