-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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-restsdk] add support for oneOf via std::variant #18821
Changes from 4 commits
1d728ec
173b538
25532fe
0cec8f7
9e1835c
74ad8db
da98bb7
5533140
b324c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,61 @@ namespace {{this}} { | |
{{#vendorExtensions.x-forward-declarations}}{{.}} | ||
{{/vendorExtensions.x-forward-declarations}} | ||
{{/vendorExtensions.x-has-forward-declarations}} | ||
{{#oneOf}}{{#-first}} | ||
#include <variant> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move the include towards the top so that it is before the namespaces. Probably before or after |
||
|
||
class {{declspec}} {{classname}} | ||
{ | ||
public: | ||
{{classname}}() = default; | ||
~{{classname}}() = default; | ||
|
||
///////////////////////////////////////////// | ||
|
||
void validate(); | ||
|
||
web::json::value toJson() const; | ||
|
||
template<typename Target> | ||
bool fromJson(const web::json::value& json) { | ||
// convert json to Target type | ||
Target target; | ||
if (!target.fromJson(json)) { | ||
return false; | ||
} | ||
|
||
m_variantValue = target; | ||
return true; | ||
} | ||
|
||
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const; | ||
|
||
template<typename Target> | ||
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) { | ||
// convert multipart to Target type | ||
Target target; | ||
if (!target.fromMultiPart(multipart, namePrefix)) { | ||
return false; | ||
} | ||
|
||
m_variantValue = target; | ||
return true; | ||
} | ||
|
||
///////////////////////////////////////////// | ||
/// {{classname}} members | ||
|
||
using VariantType = std::variant<{{#oneOf}}{{^-first}}, {{/-first}}{{{.}}}{{/oneOf}}>; | ||
|
||
const VariantType& getVariant() const; | ||
void setVariant(VariantType value); | ||
|
||
protected: | ||
VariantType m_variantValue; | ||
}; | ||
|
||
{{/-first}}{{/oneOf}} | ||
{{^oneOf}} | ||
{{#isEnum}} | ||
class {{declspec}} {{classname}} | ||
: public {{{parent}}}{{^parent}}ModelBase{{/parent}} | ||
|
@@ -120,6 +175,7 @@ protected: | |
}; | ||
|
||
{{/isEnum}} | ||
{{/oneOf}} | ||
|
||
{{#modelNamespaceDeclarations}} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,29 @@ | |
# | ||
# NOTE: Auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
|
||
cmake_minimum_required (VERSION 3.1) | ||
cmake_minimum_required (VERSION 3.5) | ||
|
||
project(CppRestPetstoreClient) | ||
project(CppRestPetstoreClient CXX) | ||
|
||
# Force -fPIC even if the project is configured for building a static library. | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
set(CXX_STANDARD_REQUIRED ON) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aminya did you need to add the above line to CMakeLists file in order to build the client? I tried the above but no luck. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we don't need this. The few lines below automatically use the latest standard. This should be removed. |
||
|
||
set(CXX_STANDARD_REQUIRED ON) | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
if(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR | ||
DEFINED CMAKE_CXX20_EXTENSION_COMPILE_OPTION) | ||
set(CMAKE_CXX_STANDARD 20) | ||
elseif(DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION OR | ||
DEFINED CMAKE_CXX17_EXTENSION_COMPILE_OPTION) | ||
set(CMAKE_CXX_STANDARD 17) | ||
elseif(DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION OR | ||
DEFINED CMAKE_CXX14_EXTENSION_COMPILE_OPTION) | ||
set(CMAKE_CXX_STANDARD 14) | ||
else() | ||
set(CMAKE_CXX_STANDARD 11) | ||
endif() | ||
endif() | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
|
@@ -38,12 +51,12 @@ add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) | |
target_compile_options(${PROJECT_NAME} | ||
PRIVATE | ||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: | ||
-Wall -Wno-unused-variable> | ||
-Wall -Wno-unused-variable -Wno-unused-lambda-capture> | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
) | ||
|
||
|
@@ -90,4 +103,4 @@ install( | |
install( | ||
EXPORT ${PROJECT_NAME}Targets | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some logging to be able to see what is happening. The test would need re-generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it's using C++ 11 according to the error message:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the
libstdc++
version. But the compiler standard itself could be different.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the issue! #18821 (comment)