From 1d728eca4bbf458a4f957f75a14c92976ff80a76 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 1 Jun 2024 21:53:18 +0800 Subject: [PATCH 1/8] =?UTF-8?q?Revert=20"Revert=20"[cpp-restsdk]=20add=20s?= =?UTF-8?q?upport=20for=20oneOf=20via=20std::variant=20(#18474)=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8d398719c99fbcbfa6471e0bb938f9d384454f8f. --- docs/generators/cpp-restsdk.md | 2 +- .../languages/CppRestSdkClientCodegen.java | 3 +- .../cpp-rest-sdk-client/api-source.mustache | 6 +- .../cpp-rest-sdk-client/cmake-lists.mustache | 25 ++- .../cpp-rest-sdk-client/model-header.mustache | 56 ++++++ .../cpp-rest-sdk-client/model-source.mustache | 50 +++++ .../resources/3_0/cpp-restsdk/petstore.yaml | 21 +++ .../client/.openapi-generator/FILES | 4 + .../cpp-restsdk/client/CMakeLists.txt | 25 ++- .../CppRestPetstoreClient/api/UserOrPetApi.h | 66 +++++++ .../CppRestPetstoreClient/model/ApiResponse.h | 1 + .../CppRestPetstoreClient/model/Category.h | 1 + .../model/CreateUserOrPet_request.h | 98 ++++++++++ .../CppRestPetstoreClient/model/Order.h | 1 + .../include/CppRestPetstoreClient/model/Pet.h | 1 + .../include/CppRestPetstoreClient/model/Tag.h | 1 + .../CppRestPetstoreClient/model/User.h | 1 + .../petstore/cpp-restsdk/client/pom.xml | 11 +- .../cpp-restsdk/client/src/api/PetApi.cpp | 32 ++-- .../cpp-restsdk/client/src/api/StoreApi.cpp | 16 +- .../cpp-restsdk/client/src/api/UserApi.cpp | 32 ++-- .../client/src/api/UserOrPetApi.cpp | 177 ++++++++++++++++++ .../src/model/CreateUserOrPet_request.cpp | 74 ++++++++ 23 files changed, 644 insertions(+), 60 deletions(-) create mode 100644 samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h create mode 100644 samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h create mode 100644 samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp create mode 100644 samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp diff --git a/docs/generators/cpp-restsdk.md b/docs/generators/cpp-restsdk.md index aef6bfe1c397..f8095ede9104 100644 --- a/docs/generators/cpp-restsdk.md +++ b/docs/generators/cpp-restsdk.md @@ -249,7 +249,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Union|✗|OAS3 |allOf|✗|OAS2,OAS3 |anyOf|✗|OAS3 -|oneOf|✗|OAS3 +|oneOf|✓|OAS3 |not|✗|OAS3 ### Security Feature diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java index 19e8dfdf504d..a802ea26f878 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java @@ -105,7 +105,8 @@ public CppRestSdkClientCodegen() { GlobalFeature.MultiServer ) .includeSchemaSupportFeatures( - SchemaSupportFeature.Polymorphism + SchemaSupportFeature.Polymorphism, + SchemaSupportFeature.oneOf ) .excludeParameterFeatures( ParameterFeature.Cookie diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache index 5338b5a9dc2a..f4275fd66e94 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache @@ -265,7 +265,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{ {{/authMethods}} return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("{{httpMethod}}"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -299,7 +299,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{ {{#vendorExtensions.x-codegen-response-ishttpcontent}} return localVarResponse.extract_vector(); }) - .then([=](std::vector localVarResponse) + .then([=, this](std::vector localVarResponse) { {{{returnType}}} localVarResult = std::make_shared(); std::shared_ptr stream = std::make_shared(std::string(localVarResponse.begin(), localVarResponse.end())); @@ -309,7 +309,7 @@ pplx::task<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{classname}}::{{ {{^vendorExtensions.x-codegen-response-ishttpcontent}} return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { {{^returnType}} return void(); diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache index 0b21eeb050c8..f3b23e27b311 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache @@ -8,16 +8,27 @@ # # NOTE: Auto generated by OpenAPI Generator (https://openapi-generator.tech). -cmake_minimum_required (VERSION 3.1) +cmake_minimum_required (VERSION 3.5) -project({{{packageName}}}) +project({{{packageName}}} 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(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 +49,12 @@ add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) target_compile_options(${PROJECT_NAME} PRIVATE $<$,$,$>: - -Wall -Wno-unused-variable> + -Wall -Wno-unused-variable -Wno-unused-lambda-capture> ) target_include_directories(${PROJECT_NAME} PUBLIC - $ + $ $ ) @@ -90,4 +101,4 @@ install( install( EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) \ No newline at end of file +) diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache index b5f070074df6..48859cf019e3 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache @@ -24,6 +24,61 @@ namespace {{this}} { {{#vendorExtensions.x-forward-declarations}}{{.}} {{/vendorExtensions.x-forward-declarations}} {{/vendorExtensions.x-has-forward-declarations}} +{{#oneOf}}{{#-first}} +#include + +class {{declspec}} {{classname}} +{ +public: + {{classname}}() = default; + ~{{classname}}() = default; + + ///////////////////////////////////////////// + + void validate(); + + web::json::value toJson() const; + + template + 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 multipart, const utility::string_t& namePrefix) const; + + template + bool fromMultiPart(std::shared_ptr 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}} } diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache index e8d2ea96a402..49e9894da568 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache @@ -6,7 +6,56 @@ {{#modelNamespaceDeclarations}} namespace {{this}} { {{/modelNamespaceDeclarations}} +{{#oneOf}}{{#-first}} +void {{classname}}::validate() +{ + // TODO: implement validation +} + +const {{classname}}::VariantType& {{classname}}::getVariant() const +{ + return m_variantValue; +} + +void {{classname}}::setVariant({{classname}}::VariantType value) +{ + m_variantValue = value; +} + +web::json::value {{classname}}::toJson() const +{ + web::json::value val = web::json::value::object(); + + std::visit([&](auto&& arg) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + val = web::json::value::null(); + } else { + val = arg.toJson(); + } + }, m_variantValue); + + return val; +} + +void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + std::visit([&](auto&& arg) { + using T = std::decay_t; + if constexpr (!std::is_same_v) { + arg.toMultipart(multipart, prefix); + } + }, m_variantValue); +} + +{{#oneOf}} +template bool {{classname}}::fromJson<{{.}}>(const web::json::value& json); +template bool {{classname}}::fromMultiPart<{{.}}>(std::shared_ptr multipart, const utility::string_t& namePrefix); +{{/oneOf}} + +{{/-first}}{{/oneOf}} +{{^oneOf}} {{#isEnum}} namespace @@ -269,6 +318,7 @@ void {{classname}}::unset{{name}}() {{/isInherited}} {{/vars}} {{/isEnum}} +{{/oneOf}} {{#modelNamespaceDeclarations}} } {{/modelNamespaceDeclarations}} diff --git a/modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml index 64ca7deaaf89..28dc856f83e1 100644 --- a/modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml @@ -569,6 +569,27 @@ paths: description: User not found security: - api_key: [] + /user_or_pet: + post: + tags: + - user_or_pet + summary: Create user or pet + description: This can only be done by the logged in user or pet. + operationId: createUserOrPet + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/User' + - $ref: '#/components/schemas/Pet' + description: Created user or pet object + required: true externalDocs: description: Find out more about Swagger url: 'http://swagger.io' diff --git a/samples/client/petstore/cpp-restsdk/client/.openapi-generator/FILES b/samples/client/petstore/cpp-restsdk/client/.openapi-generator/FILES index 06401fbfbce3..0570b3e661c6 100644 --- a/samples/client/petstore/cpp-restsdk/client/.openapi-generator/FILES +++ b/samples/client/petstore/cpp-restsdk/client/.openapi-generator/FILES @@ -16,8 +16,10 @@ include/CppRestPetstoreClient/Object.h include/CppRestPetstoreClient/api/PetApi.h include/CppRestPetstoreClient/api/StoreApi.h include/CppRestPetstoreClient/api/UserApi.h +include/CppRestPetstoreClient/api/UserOrPetApi.h include/CppRestPetstoreClient/model/ApiResponse.h include/CppRestPetstoreClient/model/Category.h +include/CppRestPetstoreClient/model/CreateUserOrPet_request.h include/CppRestPetstoreClient/model/Order.h include/CppRestPetstoreClient/model/Pet.h include/CppRestPetstoreClient/model/SchemaWithSet.h @@ -37,8 +39,10 @@ src/Object.cpp src/api/PetApi.cpp src/api/StoreApi.cpp src/api/UserApi.cpp +src/api/UserOrPetApi.cpp src/model/ApiResponse.cpp src/model/Category.cpp +src/model/CreateUserOrPet_request.cpp src/model/Order.cpp src/model/Pet.cpp src/model/SchemaWithSet.cpp diff --git a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt index 1212e2c4d0fd..4c8236584363 100644 --- a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt @@ -8,16 +8,27 @@ # # 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(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 +49,12 @@ add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) target_compile_options(${PROJECT_NAME} PRIVATE $<$,$,$>: - -Wall -Wno-unused-variable> + -Wall -Wno-unused-variable -Wno-unused-lambda-capture> ) target_include_directories(${PROJECT_NAME} PUBLIC - $ + $ $ ) @@ -90,4 +101,4 @@ install( install( EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) \ No newline at end of file +) diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h new file mode 100644 index 000000000000..0cdff5070966 --- /dev/null +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h @@ -0,0 +1,66 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/* + * UserOrPetApi.h + * + * + */ + +#ifndef ORG_OPENAPITOOLS_CLIENT_API_UserOrPetApi_H_ +#define ORG_OPENAPITOOLS_CLIENT_API_UserOrPetApi_H_ + + + +#include "CppRestPetstoreClient/ApiClient.h" + +#include "CppRestPetstoreClient/model/CreateUserOrPet_request.h" +#include + +namespace org { +namespace openapitools { +namespace client { +namespace api { + +using namespace org::openapitools::client::model; + + + +class UserOrPetApi +{ +public: + + explicit UserOrPetApi( std::shared_ptr apiClient ); + + virtual ~UserOrPetApi(); + + /// + /// Create user or pet + /// + /// + /// This can only be done by the logged in user or pet. + /// + /// Created user or pet object + pplx::task createUserOrPet( + std::shared_ptr createUserOrPetRequest + ) const; + +protected: + std::shared_ptr m_ApiClient; +}; + +} +} +} +} + +#endif /* ORG_OPENAPITOOLS_CLIENT_API_UserOrPetApi_H_ */ + diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/ApiResponse.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/ApiResponse.h index 51070cb4ebf5..9ac0849a547b 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/ApiResponse.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/ApiResponse.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// Describes the result of uploading an image resource /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Category.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Category.h index 56c2e158283b..72b3bd910995 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Category.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Category.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// A category for a pet /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h new file mode 100644 index 000000000000..fca485b639a0 --- /dev/null +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h @@ -0,0 +1,98 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/* + * CreateUserOrPet_request.h + * + * + */ + +#ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_CreateUserOrPet_request_H_ +#define ORG_OPENAPITOOLS_CLIENT_MODEL_CreateUserOrPet_request_H_ + + +#include "CppRestPetstoreClient/ModelBase.h" + +#include "CppRestPetstoreClient/model/User.h" +#include "CppRestPetstoreClient/model/Tag.h" +#include "CppRestPetstoreClient/model/Category.h" +#include +#include "CppRestPetstoreClient/model/Pet.h" +#include + +namespace org { +namespace openapitools { +namespace client { +namespace model { + +class Category; +class Tag; + +#include + +class CreateUserOrPet_request +{ +public: + CreateUserOrPet_request() = default; + ~CreateUserOrPet_request() = default; + + ///////////////////////////////////////////// + + void validate(); + + web::json::value toJson() const; + + template + 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 multipart, const utility::string_t& namePrefix) const; + + template + bool fromMultiPart(std::shared_ptr 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; + } + + ///////////////////////////////////////////// + /// CreateUserOrPet_request members + + using VariantType = std::variant; + + const VariantType& getVariant() const; + void setVariant(VariantType value); + +protected: + VariantType m_variantValue; +}; + + + +} +} +} +} + +#endif /* ORG_OPENAPITOOLS_CLIENT_MODEL_CreateUserOrPet_request_H_ */ diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Order.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Order.h index aa553ee97684..929b9cadd861 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Order.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Order.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// An order for a pets from the pet store /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h index b00392e43c6d..8efc8946566e 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h @@ -34,6 +34,7 @@ namespace model { class Category; class Tag; + /// /// A pet for sale in the pet store /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Tag.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Tag.h index 078b2fb0f77c..0d515b01d279 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Tag.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Tag.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// A tag for a pet /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/User.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/User.h index 79199c5a76be..294358d30e32 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/User.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/User.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// A User who is purchasing from the pet store /// diff --git a/samples/client/petstore/cpp-restsdk/client/pom.xml b/samples/client/petstore/cpp-restsdk/client/pom.xml index f127ec6ede34..b9113db04229 100644 --- a/samples/client/petstore/cpp-restsdk/client/pom.xml +++ b/samples/client/petstore/cpp-restsdk/client/pom.xml @@ -35,8 +35,11 @@ cmake + -S=${project.basedir} + -B=${project.build.directory} -DCMAKE_CXX_FLAGS="-I/usr/local/opt/openssl/include" -DCMAKE_MODULE_LINKER_FLAGS="-L/usr/local/opt/openssl/lib" + -DCMAKE_BUILD_TYPE=Debug @@ -47,7 +50,13 @@ exec - make + cmake + + --build + ${project.build.directory} + --config=Debug + --parallel + diff --git a/samples/client/petstore/cpp-restsdk/client/src/api/PetApi.cpp b/samples/client/petstore/cpp-restsdk/client/src/api/PetApi.cpp index 65a4c04cf920..10063efefc4f 100644 --- a/samples/client/petstore/cpp-restsdk/client/src/api/PetApi.cpp +++ b/samples/client/petstore/cpp-restsdk/client/src/api/PetApi.cpp @@ -128,7 +128,7 @@ pplx::task> PetApi::addPet(std::shared_ptr pet) const // oauth2 authentication is added automatically as part of the http_client_config return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -161,7 +161,7 @@ pplx::task> PetApi::addPet(std::shared_ptr pet) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new Pet()); @@ -256,7 +256,7 @@ pplx::task PetApi::deletePet(int64_t petId, boost::optionalcallApi(localVarPath, utility::conversions::to_string_t("DELETE"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -289,7 +289,7 @@ pplx::task PetApi::deletePet(int64_t petId, boost::optional>> PetApi::findPetsByStatus(std::vect // oauth2 authentication is added automatically as part of the http_client_config return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -399,7 +399,7 @@ pplx::task>> PetApi::findPetsByStatus(std::vect return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::vector> localVarResult; @@ -498,7 +498,7 @@ pplx::task>> PetApi::findPetsByTags(std::vector // oauth2 authentication is added automatically as part of the http_client_config return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -531,7 +531,7 @@ pplx::task>> PetApi::findPetsByTags(std::vector return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::vector> localVarResult; @@ -634,7 +634,7 @@ pplx::task> PetApi::getPetById(int64_t petId) const } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -667,7 +667,7 @@ pplx::task> PetApi::getPetById(int64_t petId) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new Pet()); @@ -783,7 +783,7 @@ pplx::task> PetApi::updatePet(std::shared_ptr pet) con // oauth2 authentication is added automatically as part of the http_client_config return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("PUT"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -816,7 +816,7 @@ pplx::task> PetApi::updatePet(std::shared_ptr pet) con return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new Pet()); @@ -916,7 +916,7 @@ pplx::task PetApi::updatePetWithForm(int64_t petId, boost::optionalcallApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -949,7 +949,7 @@ pplx::task PetApi::updatePetWithForm(int64_t petId, boost::optional> PetApi::uploadFile(int64_t petId, boost // oauth2 authentication is added automatically as part of the http_client_config return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -1065,7 +1065,7 @@ pplx::task> PetApi::uploadFile(int64_t petId, boost return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new ApiResponse()); diff --git a/samples/client/petstore/cpp-restsdk/client/src/api/StoreApi.cpp b/samples/client/petstore/cpp-restsdk/client/src/api/StoreApi.cpp index 3ac1ae0f7538..9b0cb610dc35 100644 --- a/samples/client/petstore/cpp-restsdk/client/src/api/StoreApi.cpp +++ b/samples/client/petstore/cpp-restsdk/client/src/api/StoreApi.cpp @@ -101,7 +101,7 @@ pplx::task StoreApi::deleteOrder(utility::string_t orderId) const return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("DELETE"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -134,7 +134,7 @@ pplx::task StoreApi::deleteOrder(utility::string_t orderId) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { return void(); }); @@ -213,7 +213,7 @@ pplx::task> StoreApi::getInventory() const } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -246,7 +246,7 @@ pplx::task> StoreApi::getInventory() const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::map localVarResult; @@ -342,7 +342,7 @@ pplx::task> StoreApi::getOrderById(int64_t orderId) const return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -375,7 +375,7 @@ pplx::task> StoreApi::getOrderById(int64_t orderId) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new Order()); @@ -488,7 +488,7 @@ pplx::task> StoreApi::placeOrder(std::shared_ptr o return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -521,7 +521,7 @@ pplx::task> StoreApi::placeOrder(std::shared_ptr o return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new Order()); diff --git a/samples/client/petstore/cpp-restsdk/client/src/api/UserApi.cpp b/samples/client/petstore/cpp-restsdk/client/src/api/UserApi.cpp index 0b1e6bd1f485..65811119fcd2 100644 --- a/samples/client/petstore/cpp-restsdk/client/src/api/UserApi.cpp +++ b/samples/client/petstore/cpp-restsdk/client/src/api/UserApi.cpp @@ -131,7 +131,7 @@ pplx::task UserApi::createUser(std::shared_ptr user) const } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -164,7 +164,7 @@ pplx::task UserApi::createUser(std::shared_ptr user) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { return void(); }); @@ -270,7 +270,7 @@ pplx::task UserApi::createUsersWithArrayInput(std::vectorcallApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -303,7 +303,7 @@ pplx::task UserApi::createUsersWithArrayInput(std::vector UserApi::createUsersWithListInput(std::vectorcallApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -442,7 +442,7 @@ pplx::task UserApi::createUsersWithListInput(std::vector UserApi::deleteUser(utility::string_t username) const } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("DELETE"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -554,7 +554,7 @@ pplx::task UserApi::deleteUser(utility::string_t username) const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { return void(); }); @@ -627,7 +627,7 @@ pplx::task> UserApi::getUserByName(utility::string_t usern return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -660,7 +660,7 @@ pplx::task> UserApi::getUserByName(utility::string_t usern return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { std::shared_ptr localVarResult(new User()); @@ -761,7 +761,7 @@ pplx::task UserApi::loginUser(utility::string_t username, uti return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -794,7 +794,7 @@ pplx::task UserApi::loginUser(utility::string_t username, uti return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { utility::string_t localVarResult(utility::conversions::to_string_t("")); @@ -894,7 +894,7 @@ pplx::task UserApi::logoutUser() const } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -927,7 +927,7 @@ pplx::task UserApi::logoutUser() const return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { return void(); }); @@ -1029,7 +1029,7 @@ pplx::task UserApi::updateUser(utility::string_t username, std::shared_ptr } return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("PUT"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) - .then([=](web::http::http_response localVarResponse) + .then([=, this](web::http::http_response localVarResponse) { if (m_ApiClient->getResponseHandler()) { @@ -1062,7 +1062,7 @@ pplx::task UserApi::updateUser(utility::string_t username, std::shared_ptr return localVarResponse.extract_string(); }) - .then([=](utility::string_t localVarResponse) + .then([=, this](utility::string_t localVarResponse) { return void(); }); diff --git a/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp b/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp new file mode 100644 index 000000000000..c6f106804a20 --- /dev/null +++ b/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp @@ -0,0 +1,177 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +#include "CppRestPetstoreClient/api/UserOrPetApi.h" +#include "CppRestPetstoreClient/IHttpBody.h" +#include "CppRestPetstoreClient/JsonBody.h" +#include "CppRestPetstoreClient/MultipartFormData.h" + +#include + +#include + +namespace org { +namespace openapitools { +namespace client { +namespace api { + +using namespace org::openapitools::client::model; + +UserOrPetApi::UserOrPetApi( std::shared_ptr apiClient ) + : m_ApiClient(apiClient) +{ +} + +UserOrPetApi::~UserOrPetApi() +{ +} + +pplx::task UserOrPetApi::createUserOrPet(std::shared_ptr createUserOrPetRequest) const +{ + + // verify the required parameter 'createUserOrPetRequest' is set + if (createUserOrPetRequest == nullptr) + { + throw ApiException(400, utility::conversions::to_string_t("Missing required parameter 'createUserOrPetRequest' when calling UserOrPetApi->createUserOrPet")); + } + + + std::shared_ptr localVarApiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t localVarPath = utility::conversions::to_string_t("/user_or_pet"); + + std::map localVarQueryParams; + std::map localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() ); + std::map localVarFormParams; + std::map> localVarFileParams; + + std::unordered_set localVarResponseHttpContentTypes; + + utility::string_t localVarResponseHttpContentType; + + // use JSON if possible + if ( localVarResponseHttpContentTypes.size() == 0 ) + { + localVarResponseHttpContentType = utility::conversions::to_string_t("application/json"); + } + // JSON + else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() ) + { + localVarResponseHttpContentType = utility::conversions::to_string_t("application/json"); + } + // multipart formdata + else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() ) + { + localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data"); + } + else + { + throw ApiException(400, utility::conversions::to_string_t("UserOrPetApi->createUserOrPet does not produce any supported media type")); + } + + localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType; + + std::unordered_set localVarConsumeHttpContentTypes; + localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") ); + + + std::shared_ptr localVarHttpBody; + utility::string_t localVarRequestHttpContentType; + + // use JSON if possible + if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() ) + { + localVarRequestHttpContentType = utility::conversions::to_string_t("application/json"); + web::json::value localVarJson; + + localVarJson = ModelBase::toJson(createUserOrPetRequest); + + + localVarHttpBody = std::shared_ptr( new JsonBody( localVarJson ) ); + } + // multipart formdata + else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() ) + { + localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data"); + std::shared_ptr localVarMultipart(new MultipartFormData); + + if(createUserOrPetRequest.get()) + { + createUserOrPetRequest->toMultipart(localVarMultipart, utility::conversions::to_string_t("createUserOrPetRequest")); + } + + + localVarHttpBody = localVarMultipart; + localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary(); + } + else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end()) + { + localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded"); + } + else + { + throw ApiException(415, utility::conversions::to_string_t("UserOrPetApi->createUserOrPet does not consume any supported media type")); + } + + // authentication (api_key) required + { + utility::string_t localVarApiKey = localVarApiConfiguration->getApiKey(utility::conversions::to_string_t("api_key")); + if ( localVarApiKey.size() > 0 ) + { + localVarHeaderParams[utility::conversions::to_string_t("api_key")] = localVarApiKey; + } + } + + return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType) + .then([=, this](web::http::http_response localVarResponse) + { + if (m_ApiClient->getResponseHandler()) + { + m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers()); + } + + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (localVarResponse.status_code() >= 400) + { + throw ApiException(localVarResponse.status_code() + , utility::conversions::to_string_t("error calling createUserOrPet: ") + localVarResponse.reason_phrase() + , std::make_shared(localVarResponse.extract_utf8string(true).get())); + } + + // check response content type + if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type"))) + { + utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")]; + if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , utility::conversions::to_string_t("error calling createUserOrPet: unexpected response type: ") + localVarContentType + , std::make_shared(localVarResponse.extract_utf8string(true).get())); + } + } + + return localVarResponse.extract_string(); + }) + .then([=, this](utility::string_t localVarResponse) + { + return void(); + }); +} + +} +} +} +} + diff --git a/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp b/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp new file mode 100644 index 000000000000..bf350d7f0037 --- /dev/null +++ b/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp @@ -0,0 +1,74 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +#include "CppRestPetstoreClient/model/CreateUserOrPet_request.h" + +namespace org { +namespace openapitools { +namespace client { +namespace model { + + +void CreateUserOrPet_request::validate() +{ + // TODO: implement validation +} + +const CreateUserOrPet_request::VariantType& CreateUserOrPet_request::getVariant() const +{ + return m_variantValue; +} + +void CreateUserOrPet_request::setVariant(CreateUserOrPet_request::VariantType value) +{ + m_variantValue = value; +} + +web::json::value CreateUserOrPet_request::toJson() const +{ + web::json::value val = web::json::value::object(); + + std::visit([&](auto&& arg) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + val = web::json::value::null(); + } else { + val = arg.toJson(); + } + }, m_variantValue); + + return val; +} + +void CreateUserOrPet_request::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + std::visit([&](auto&& arg) { + using T = std::decay_t; + if constexpr (!std::is_same_v) { + arg.toMultipart(multipart, prefix); + } + }, m_variantValue); +} + +template bool CreateUserOrPet_request::fromJson(const web::json::value& json); +template bool CreateUserOrPet_request::fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix); +template bool CreateUserOrPet_request::fromJson(const web::json::value& json); +template bool CreateUserOrPet_request::fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix); + + +} +} +} +} + + From 173b5387721884a4b1ff897a6ab346e4e484814e Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 1 Jun 2024 22:02:03 +0800 Subject: [PATCH 2/8] update samples --- .../client/include/CppRestPetstoreClient/api/UserOrPetApi.h | 2 +- .../CppRestPetstoreClient/model/CreateUserOrPet_request.h | 2 +- .../client/include/CppRestPetstoreClient/model/SchemaWithSet.h | 1 + .../CppRestPetstoreClient/model/SchemaWithSet_vaccinationBook.h | 1 + .../client/include/CppRestPetstoreClient/model/Vaccine.h | 1 + .../client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp | 2 +- .../cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp | 2 +- 7 files changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h index 0cdff5070966..b620355822ae 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/api/UserOrPetApi.h @@ -4,7 +4,7 @@ * * The version of the OpenAPI document: 1.0.0 * - * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * NOTE: This class is auto generated by OpenAPI-Generator 7.7.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h index fca485b639a0..1285d5507749 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h @@ -4,7 +4,7 @@ * * The version of the OpenAPI document: 1.0.0 * - * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * NOTE: This class is auto generated by OpenAPI-Generator 7.7.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet.h index acc340488c8d..75e2272abf28 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet.h @@ -32,6 +32,7 @@ namespace model { class SchemaWithSet_vaccinationBook; + /// /// Schema with a set property /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet_vaccinationBook.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet_vaccinationBook.h index 74dda9d58fc6..f19ef6935d22 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet_vaccinationBook.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/SchemaWithSet_vaccinationBook.h @@ -31,6 +31,7 @@ namespace model { class Vaccine; + /// /// Vaccination book of the pet /// diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Vaccine.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Vaccine.h index b86e1ff65b3c..90694a853899 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Vaccine.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Vaccine.h @@ -29,6 +29,7 @@ namespace client { namespace model { + /// /// /// diff --git a/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp b/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp index c6f106804a20..8837e1cdc6cb 100644 --- a/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp +++ b/samples/client/petstore/cpp-restsdk/client/src/api/UserOrPetApi.cpp @@ -4,7 +4,7 @@ * * The version of the OpenAPI document: 1.0.0 * - * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * NOTE: This class is auto generated by OpenAPI-Generator 7.7.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ diff --git a/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp b/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp index bf350d7f0037..ff4369ed8dda 100644 --- a/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp +++ b/samples/client/petstore/cpp-restsdk/client/src/model/CreateUserOrPet_request.cpp @@ -4,7 +4,7 @@ * * The version of the OpenAPI document: 1.0.0 * - * NOTE: This class is auto generated by OpenAPI-Generator 7.6.0-SNAPSHOT. + * NOTE: This class is auto generated by OpenAPI-Generator 7.7.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ From 25532feb0cf90647b95e7c815577e61545af467f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 1 Jun 2024 22:08:14 +0800 Subject: [PATCH 3/8] update pom --- samples/client/petstore/cpp-restsdk/client/pom.xml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/samples/client/petstore/cpp-restsdk/client/pom.xml b/samples/client/petstore/cpp-restsdk/client/pom.xml index b9113db04229..6c5f5ed24c96 100644 --- a/samples/client/petstore/cpp-restsdk/client/pom.xml +++ b/samples/client/petstore/cpp-restsdk/client/pom.xml @@ -35,8 +35,6 @@ cmake - -S=${project.basedir} - -B=${project.build.directory} -DCMAKE_CXX_FLAGS="-I/usr/local/opt/openssl/include" -DCMAKE_MODULE_LINKER_FLAGS="-L/usr/local/opt/openssl/lib" -DCMAKE_BUILD_TYPE=Debug @@ -50,13 +48,7 @@ exec - cmake - - --build - ${project.build.directory} - --config=Debug - --parallel - + make From 0cec8f725dd8017217b75e827a54da5440dd55d1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 1 Jun 2024 22:37:22 +0800 Subject: [PATCH 4/8] set cxx 17 --- samples/client/petstore/cpp-restsdk/client/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt index 4c8236584363..976aab0fa895 100644 --- a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt @@ -15,6 +15,8 @@ project(CppRestPetstoreClient CXX) # Force -fPIC even if the project is configured for building a static library. set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_STANDARD 17) + set(CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_CXX_STANDARD) if(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR From 9e1835c3e04b362c76313a653c11f7dc6a884361 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 2 Jun 2024 18:15:06 +0800 Subject: [PATCH 5/8] Revert "set cxx 17" This reverts commit 0cec8f725dd8017217b75e827a54da5440dd55d1. --- samples/client/petstore/cpp-restsdk/client/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt index 976aab0fa895..4c8236584363 100644 --- a/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-restsdk/client/CMakeLists.txt @@ -15,8 +15,6 @@ project(CppRestPetstoreClient CXX) # Force -fPIC even if the project is configured for building a static library. set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_CXX_STANDARD 17) - set(CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_CXX_STANDARD) if(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR From 74ad8db36b272a70fb94053a57d934f5097a4d76 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 2 Jun 2024 18:15:35 +0800 Subject: [PATCH 6/8] install clang 6.0 --- CI/circle_parallel.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 2ab6fbeb71b4..477f177810fc 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -41,6 +41,7 @@ elif [ "$NODE_INDEX" = "2" ]; then # install cpprestsdk sudo apt-get install libcpprest-dev + sudo apt-get install clang-6.0 # run go integration tests (cd samples/client/petstore/go && mvn integration-test) From da98bb72b5a29742bcd8aa1ea3f39ef4710221f1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 4 Jun 2024 16:59:08 +0800 Subject: [PATCH 7/8] Update CI/circle_parallel.sh Co-authored-by: Amin Yahyaabadi --- CI/circle_parallel.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 477f177810fc..56cd4f5161de 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -41,7 +41,10 @@ elif [ "$NODE_INDEX" = "2" ]; then # install cpprestsdk sudo apt-get install libcpprest-dev - sudo apt-get install clang-6.0 + wget "https://github.com/aminya/setup-cpp/releases/download/v0.37.0/setup-cpp-x64-linux" + chmod +x ./setup-cpp-x64-linux + sudo ./setup-cpp-x64-linux --compiler llvm --cmake true --ninja true + source ~/.cpprc # activate cpp environment variables # run go integration tests (cd samples/client/petstore/go && mvn integration-test) From 5533140cea9daeea8bd808aa3f56473c5f5df949 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 6 Jun 2024 16:44:36 +0800 Subject: [PATCH 8/8] fix include --- .../resources/cpp-rest-sdk-client/model-header.mustache | 6 +++++- .../CppRestPetstoreClient/model/CreateUserOrPet_request.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache index 48859cf019e3..e7374f4a1018 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache @@ -8,6 +8,11 @@ #ifndef {{modelHeaderGuardPrefix}}_{{classname}}_H_ #define {{modelHeaderGuardPrefix}}_{{classname}}_H_ +{{#oneOf}} +{{#-first}} +#include +{{/-first}} +{{/oneOf}} {{^parent}} {{{defaultInclude}}} #include "{{packageName}}/ModelBase.h" @@ -25,7 +30,6 @@ namespace {{this}} { {{/vendorExtensions.x-forward-declarations}} {{/vendorExtensions.x-has-forward-declarations}} {{#oneOf}}{{#-first}} -#include class {{declspec}} {{classname}} { diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h index 1285d5507749..723cd51b3b08 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h @@ -18,6 +18,7 @@ #ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_CreateUserOrPet_request_H_ #define ORG_OPENAPITOOLS_CLIENT_MODEL_CreateUserOrPet_request_H_ +#include #include "CppRestPetstoreClient/ModelBase.h" @@ -36,7 +37,6 @@ namespace model { class Category; class Tag; -#include class CreateUserOrPet_request {