Skip to content

Commit 8d39871

Browse files
authored
Revert "[cpp-restsdk] add support for oneOf via std::variant (#18474)" (#18820)
This reverts commit 6a3d406.
1 parent 6a3d406 commit 8d39871

23 files changed

Lines changed: 60 additions & 644 deletions

File tree

‎docs/generators/cpp-restsdk.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
249249
|Union|✗|OAS3
250250
|allOf|✗|OAS2,OAS3
251251
|anyOf|✗|OAS3
252-
|oneOf|✓|OAS3
252+
|oneOf|✗|OAS3
253253
|not|✗|OAS3
254254

255255
### Security Feature

‎modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public CppRestSdkClientCodegen() {
105105
GlobalFeature.MultiServer
106106
)
107107
.includeSchemaSupportFeatures(
108-
SchemaSupportFeature.Polymorphism,
109-
SchemaSupportFeature.oneOf
108+
SchemaSupportFeature.Polymorphism
110109
)
111110
.excludeParameterFeatures(
112111
ParameterFeature.Cookie

‎modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{
265265
{{/authMethods}}
266266
267267
return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("{{httpMethod}}"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
268-
.then([=, this](web::http::http_response localVarResponse)
268+
.then([=](web::http::http_response localVarResponse)
269269
{
270270
if (m_ApiClient->getResponseHandler())
271271
{
@@ -299,7 +299,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{
299299
{{#vendorExtensions.x-codegen-response-ishttpcontent}}
300300
return localVarResponse.extract_vector();
301301
})
302-
.then([=, this](std::vector<unsigned char> localVarResponse)
302+
.then([=](std::vector<unsigned char> localVarResponse)
303303
{
304304
{{{returnType}}} localVarResult = std::make_shared<HttpContent>();
305305
std::shared_ptr<std::stringstream> stream = std::make_shared<std::stringstream>(std::string(localVarResponse.begin(), localVarResponse.end()));
@@ -309,7 +309,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{
309309
{{^vendorExtensions.x-codegen-response-ishttpcontent}}
310310
return localVarResponse.extract_string();
311311
})
312-
.then([=, this](utility::string_t localVarResponse)
312+
.then([=](utility::string_t localVarResponse)
313313
{
314314
{{^returnType}}
315315
return void();

‎modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,16 @@
88
#
99
# NOTE: Auto generated by OpenAPI Generator (https://openapi-generator.tech).
1010

11-
cmake_minimum_required (VERSION 3.5)
11+
cmake_minimum_required (VERSION 3.1)
1212

13-
project({{{packageName}}} CXX)
13+
project({{{packageName}}})
1414

1515
# Force -fPIC even if the project is configured for building a static library.
1616
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
17-
1817
set(CXX_STANDARD_REQUIRED ON)
18+
1919
if(NOT CMAKE_CXX_STANDARD)
20-
if(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR
21-
DEFINED CMAKE_CXX20_EXTENSION_COMPILE_OPTION)
22-
set(CMAKE_CXX_STANDARD 20)
23-
elseif(DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION OR
24-
DEFINED CMAKE_CXX17_EXTENSION_COMPILE_OPTION)
25-
set(CMAKE_CXX_STANDARD 17)
26-
elseif(DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION OR
27-
DEFINED CMAKE_CXX14_EXTENSION_COMPILE_OPTION)
28-
set(CMAKE_CXX_STANDARD 14)
29-
else()
30-
set(CMAKE_CXX_STANDARD 11)
31-
endif()
20+
set(CMAKE_CXX_STANDARD 14)
3221
endif()
3322

3423
if(NOT CMAKE_BUILD_TYPE)
@@ -49,12 +38,12 @@ add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
4938
target_compile_options(${PROJECT_NAME}
5039
PRIVATE
5140
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
52-
-Wall -Wno-unused-variable -Wno-unused-lambda-capture>
41+
-Wall -Wno-unused-variable>
5342
)
5443

5544
target_include_directories(${PROJECT_NAME}
5645
PUBLIC
57-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
46+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5847
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
5948
)
6049

@@ -101,4 +90,4 @@ install(
10190
install(
10291
EXPORT ${PROJECT_NAME}Targets
10392
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
104-
)
93+
)

‎modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,61 +24,6 @@ namespace {{this}} {
2424
{{#vendorExtensions.x-forward-declarations}}{{.}}
2525
{{/vendorExtensions.x-forward-declarations}}
2626
{{/vendorExtensions.x-has-forward-declarations}}
27-
{{#oneOf}}{{#-first}}
28-
#include <variant>
29-
30-
class {{declspec}} {{classname}}
31-
{
32-
public:
33-
{{classname}}() = default;
34-
~{{classname}}() = default;
35-
36-
/////////////////////////////////////////////
37-
38-
void validate();
39-
40-
web::json::value toJson() const;
41-
42-
template<typename Target>
43-
bool fromJson(const web::json::value& json) {
44-
// convert json to Target type
45-
Target target;
46-
if (!target.fromJson(json)) {
47-
return false;
48-
}
49-
50-
m_variantValue = target;
51-
return true;
52-
}
53-
54-
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const;
55-
56-
template<typename Target>
57-
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) {
58-
// convert multipart to Target type
59-
Target target;
60-
if (!target.fromMultiPart(multipart, namePrefix)) {
61-
return false;
62-
}
63-
64-
m_variantValue = target;
65-
return true;
66-
}
67-
68-
/////////////////////////////////////////////
69-
/// {{classname}} members
70-
71-
using VariantType = std::variant<{{#oneOf}}{{^-first}}, {{/-first}}{{{.}}}{{/oneOf}}>;
72-
73-
const VariantType& getVariant() const;
74-
void setVariant(VariantType value);
75-
76-
protected:
77-
VariantType m_variantValue;
78-
};
79-
80-
{{/-first}}{{/oneOf}}
81-
{{^oneOf}}
8227
{{#isEnum}}
8328
class {{declspec}} {{classname}}
8429
: public {{{parent}}}{{^parent}}ModelBase{{/parent}}
@@ -175,7 +120,6 @@ protected:
175120
};
176121

177122
{{/isEnum}}
178-
{{/oneOf}}
179123

180124
{{#modelNamespaceDeclarations}}
181125
}

‎modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,7 @@
66
{{#modelNamespaceDeclarations}}
77
namespace {{this}} {
88
{{/modelNamespaceDeclarations}}
9-
{{#oneOf}}{{#-first}}
109

11-
void {{classname}}::validate()
12-
{
13-
// TODO: implement validation
14-
}
15-
16-
const {{classname}}::VariantType& {{classname}}::getVariant() const
17-
{
18-
return m_variantValue;
19-
}
20-
21-
void {{classname}}::setVariant({{classname}}::VariantType value)
22-
{
23-
m_variantValue = value;
24-
}
25-
26-
web::json::value {{classname}}::toJson() const
27-
{
28-
web::json::value val = web::json::value::object();
29-
30-
std::visit([&](auto&& arg) {
31-
using T = std::decay_t<decltype(arg)>;
32-
if constexpr (std::is_same_v<T, std::monostate>) {
33-
val = web::json::value::null();
34-
} else {
35-
val = arg.toJson();
36-
}
37-
}, m_variantValue);
38-
39-
return val;
40-
}
41-
42-
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
43-
{
44-
std::visit([&](auto&& arg) {
45-
using T = std::decay_t<decltype(arg)>;
46-
if constexpr (!std::is_same_v<T, std::monostate>) {
47-
arg.toMultipart(multipart, prefix);
48-
}
49-
}, m_variantValue);
50-
}
51-
52-
{{#oneOf}}
53-
template bool {{classname}}::fromJson<{{.}}>(const web::json::value& json);
54-
template bool {{classname}}::fromMultiPart<{{.}}>(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix);
55-
{{/oneOf}}
56-
57-
{{/-first}}{{/oneOf}}
58-
{{^oneOf}}
5910
{{#isEnum}}
6011

6112
namespace
@@ -318,7 +269,6 @@ void {{classname}}::unset{{name}}()
318269
{{/isInherited}}
319270
{{/vars}}
320271
{{/isEnum}}
321-
{{/oneOf}}
322272
{{#modelNamespaceDeclarations}}
323273
}
324274
{{/modelNamespaceDeclarations}}

‎modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -569,27 +569,6 @@ paths:
569569
description: User not found
570570
security:
571571
- api_key: []
572-
/user_or_pet:
573-
post:
574-
tags:
575-
- user_or_pet
576-
summary: Create user or pet
577-
description: This can only be done by the logged in user or pet.
578-
operationId: createUserOrPet
579-
responses:
580-
default:
581-
description: successful operation
582-
security:
583-
- api_key: []
584-
requestBody:
585-
content:
586-
application/json:
587-
schema:
588-
oneOf:
589-
- $ref: '#/components/schemas/User'
590-
- $ref: '#/components/schemas/Pet'
591-
description: Created user or pet object
592-
required: true
593572
externalDocs:
594573
description: Find out more about Swagger
595574
url: 'http://swagger.io'

‎samples/client/petstore/cpp-restsdk/client/.openapi-generator/FILES‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ include/CppRestPetstoreClient/Object.h
1616
include/CppRestPetstoreClient/api/PetApi.h
1717
include/CppRestPetstoreClient/api/StoreApi.h
1818
include/CppRestPetstoreClient/api/UserApi.h
19-
include/CppRestPetstoreClient/api/UserOrPetApi.h
2019
include/CppRestPetstoreClient/model/ApiResponse.h
2120
include/CppRestPetstoreClient/model/Category.h
22-
include/CppRestPetstoreClient/model/CreateUserOrPet_request.h
2321
include/CppRestPetstoreClient/model/Order.h
2422
include/CppRestPetstoreClient/model/Pet.h
2523
include/CppRestPetstoreClient/model/SchemaWithSet.h
@@ -39,10 +37,8 @@ src/Object.cpp
3937
src/api/PetApi.cpp
4038
src/api/StoreApi.cpp
4139
src/api/UserApi.cpp
42-
src/api/UserOrPetApi.cpp
4340
src/model/ApiResponse.cpp
4441
src/model/Category.cpp
45-
src/model/CreateUserOrPet_request.cpp
4642
src/model/Order.cpp
4743
src/model/Pet.cpp
4844
src/model/SchemaWithSet.cpp

‎samples/client/petstore/cpp-restsdk/client/CMakeLists.txt‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,16 @@
88
#
99
# NOTE: Auto generated by OpenAPI Generator (https://openapi-generator.tech).
1010

11-
cmake_minimum_required (VERSION 3.5)
11+
cmake_minimum_required (VERSION 3.1)
1212

13-
project(CppRestPetstoreClient CXX)
13+
project(CppRestPetstoreClient)
1414

1515
# Force -fPIC even if the project is configured for building a static library.
1616
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
17-
1817
set(CXX_STANDARD_REQUIRED ON)
18+
1919
if(NOT CMAKE_CXX_STANDARD)
20-
if(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR
21-
DEFINED CMAKE_CXX20_EXTENSION_COMPILE_OPTION)
22-
set(CMAKE_CXX_STANDARD 20)
23-
elseif(DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION OR
24-
DEFINED CMAKE_CXX17_EXTENSION_COMPILE_OPTION)
25-
set(CMAKE_CXX_STANDARD 17)
26-
elseif(DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION OR
27-
DEFINED CMAKE_CXX14_EXTENSION_COMPILE_OPTION)
28-
set(CMAKE_CXX_STANDARD 14)
29-
else()
30-
set(CMAKE_CXX_STANDARD 11)
31-
endif()
20+
set(CMAKE_CXX_STANDARD 14)
3221
endif()
3322

3423
if(NOT CMAKE_BUILD_TYPE)
@@ -49,12 +38,12 @@ add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
4938
target_compile_options(${PROJECT_NAME}
5039
PRIVATE
5140
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
52-
-Wall -Wno-unused-variable -Wno-unused-lambda-capture>
41+
-Wall -Wno-unused-variable>
5342
)
5443

5544
target_include_directories(${PROJECT_NAME}
5645
PUBLIC
57-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
46+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5847
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
5948
)
6049

@@ -101,4 +90,4 @@ install(
10190
install(
10291
EXPORT ${PROJECT_NAME}Targets
10392
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
104-
)
93+
)

0 commit comments

Comments
 (0)