[cpp-restsdk] add support for AnyType (#18463)

* [cpp-restsdk] add support for AnyType

* [cpp-restsdk] fix the AnyType header generation path
This commit is contained in:
Amin Yahyaabadi 2024-04-23 22:44:21 -07:00 committed by GitHub
parent dc96d648f7
commit 7036b99e91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 211 additions and 1 deletions

5
.gitignore vendored
View File

@ -85,6 +85,11 @@ samples/client/petstore/cpp-restsdk/CMakeCache.txt
samples/client/petstore/cpp-restsdk/CMakeFiles/ samples/client/petstore/cpp-restsdk/CMakeFiles/
samples/client/petstore/cpp-restsdk/Makefile samples/client/petstore/cpp-restsdk/Makefile
samples/client/petstore/cpp-restsdk/cmake_install.cmake samples/client/petstore/cpp-restsdk/cmake_install.cmake
samples/client/petstore/cpp-restsdk/client/CMakeFiles
samples/client/petstore/cpp-restsdk/client/Makefile
samples/client/petstore/cpp-restsdk/client/cmake_install.cmake
samples/client/petstore/cpp-restsdk/client/CppRestPetstoreClientConfig.cmake
samples/client/petstore/cpp-restsdk/client/CMakeCache.txt
#Java/Android #Java/Android
**/.gradle **/.gradle

View File

@ -184,7 +184,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Uuid|✗| |Uuid|✗|
|Array|✓|OAS2,OAS3 |Array|✓|OAS2,OAS3
|Null|✗|OAS3 |Null|✗|OAS3
|AnyType||OAS2,OAS3 |AnyType||OAS2,OAS3
|Object|✓|OAS2,OAS3 |Object|✓|OAS2,OAS3
|Maps|✓|ToolingExtension |Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2 |CollectionFormat|✓|OAS2

View File

@ -111,6 +111,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
.excludeParameterFeatures( .excludeParameterFeatures(
ParameterFeature.Cookie ParameterFeature.Cookie
) )
.includeDataTypeFeatures(
DataTypeFeature.AnyType)
); );
apiPackage = "org.openapitools.client.api"; apiPackage = "org.openapitools.client.api";
@ -174,6 +176,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
importMapping.put("std::string", "#include <string>"); importMapping.put("std::string", "#include <string>");
importMapping.put("HttpContent", "#include \"HttpContent.h\""); importMapping.put("HttpContent", "#include \"HttpContent.h\"");
importMapping.put("Object", "#include \"Object.h\""); importMapping.put("Object", "#include \"Object.h\"");
importMapping.put("AnyType", "#include \"AnyType.h\"");
importMapping.put("utility::string_t", "#include <cpprest/details/basic_types.h>"); importMapping.put("utility::string_t", "#include <cpprest/details/basic_types.h>");
importMapping.put("utility::datetime", "#include <cpprest/details/basic_types.h>"); importMapping.put("utility::datetime", "#include <cpprest/details/basic_types.h>");
} }
@ -214,11 +217,14 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
importMapping.put("HttpContent", "#include \"" + packageName + "/" + "HttpContent.h\""); importMapping.put("HttpContent", "#include \"" + packageName + "/" + "HttpContent.h\"");
importMapping.put("Object", "#include \"" + packageName + "/" + "Object.h\""); importMapping.put("Object", "#include \"" + packageName + "/" + "Object.h\"");
importMapping.put("AnyType", "#include \"" + packageName + "/" + "AnyType.h\"");
supportingFiles.add(new SupportingFile("modelbase-header.mustache", getHeaderFolder(), "ModelBase.h")); supportingFiles.add(new SupportingFile("modelbase-header.mustache", getHeaderFolder(), "ModelBase.h"));
supportingFiles.add(new SupportingFile("modelbase-source.mustache", getSourceFolder(), "ModelBase.cpp")); supportingFiles.add(new SupportingFile("modelbase-source.mustache", getSourceFolder(), "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("object-header.mustache", getHeaderFolder(), "Object.h")); supportingFiles.add(new SupportingFile("object-header.mustache", getHeaderFolder(), "Object.h"));
supportingFiles.add(new SupportingFile("object-source.mustache", getSourceFolder(), "Object.cpp")); supportingFiles.add(new SupportingFile("object-source.mustache", getSourceFolder(), "Object.cpp"));
supportingFiles.add(new SupportingFile("anytype-header.mustache", getHeaderFolder(), "AnyType.h"));
supportingFiles.add(new SupportingFile("anytype-source.mustache", getSourceFolder(), "AnyType.cpp"));
supportingFiles.add(new SupportingFile("apiclient-header.mustache", getHeaderFolder(), "ApiClient.h")); supportingFiles.add(new SupportingFile("apiclient-header.mustache", getHeaderFolder(), "ApiClient.h"));
supportingFiles.add(new SupportingFile("apiclient-source.mustache", getSourceFolder(), "ApiClient.cpp")); supportingFiles.add(new SupportingFile("apiclient-source.mustache", getSourceFolder(), "ApiClient.cpp"));
supportingFiles.add(new SupportingFile("apiconfiguration-header.mustache", getHeaderFolder(), "ApiConfiguration.h")); supportingFiles.add(new SupportingFile("apiconfiguration-header.mustache", getHeaderFolder(), "ApiConfiguration.h"));

View File

@ -0,0 +1,46 @@
{{>licenseInfo}}
/*
* AnyType.h
*
* This is the implementation of an any JSON type.
*/
#ifndef {{modelHeaderGuardPrefix}}_AnyType_H_
#define {{modelHeaderGuardPrefix}}_AnyType_H_
{{{defaultInclude}}}
#include "{{packageName}}/Object.h"
#include <cpprest/details/basic_types.h>
#include <cpprest/json.h>
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
class {{declspec}} AnyType : public Object {
public:
AnyType();
virtual ~AnyType();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
web::json::value toJson() const override;
bool fromJson(const web::json::value &json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &namePrefix) const override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &namePrefix) override;
private:
web::json::value m_value;
};
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
#endif /* {{modelHeaderGuardPrefix}}_AnyType_H_ */

View File

@ -0,0 +1,40 @@
{{>licenseInfo}}
#include "{{packageName}}/AnyType.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
AnyType::AnyType() { m_value = web::json::value::null(); }
AnyType::~AnyType() {}
void AnyType::validate() {}
web::json::value AnyType::toJson() const { return m_value; }
bool AnyType::fromJson(const web::json::value &val) {
m_value = val;
m_IsSet = true;
return isSet();
}
void AnyType::toMultipart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &prefix) const {
if (m_value.is_object()) {
return Object::toMultipart(multipart, prefix);
}
throw std::runtime_error("AnyType::toMultipart: unsupported type");
}
bool AnyType::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &prefix) {
if (m_value.is_object()) {
return Object::fromMultiPart(multipart, prefix);
}
return false;
}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}

View File

@ -1,8 +1,10 @@
.gitignore .gitignore
.openapi-generator-ignore
CMakeLists.txt CMakeLists.txt
Config.cmake.in Config.cmake.in
README.md README.md
git_push.sh git_push.sh
include/CppRestPetstoreClient/AnyType.h
include/CppRestPetstoreClient/ApiClient.h include/CppRestPetstoreClient/ApiClient.h
include/CppRestPetstoreClient/ApiConfiguration.h include/CppRestPetstoreClient/ApiConfiguration.h
include/CppRestPetstoreClient/ApiException.h include/CppRestPetstoreClient/ApiException.h
@ -21,6 +23,7 @@ include/CppRestPetstoreClient/model/Order.h
include/CppRestPetstoreClient/model/Pet.h include/CppRestPetstoreClient/model/Pet.h
include/CppRestPetstoreClient/model/Tag.h include/CppRestPetstoreClient/model/Tag.h
include/CppRestPetstoreClient/model/User.h include/CppRestPetstoreClient/model/User.h
src/AnyType.cpp
src/ApiClient.cpp src/ApiClient.cpp
src/ApiConfiguration.cpp src/ApiConfiguration.cpp
src/ApiException.cpp src/ApiException.cpp

View File

@ -0,0 +1,58 @@
/**
* 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.
*/
/*
* AnyType.h
*
* This is the implementation of an any JSON type.
*/
#ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_AnyType_H_
#define ORG_OPENAPITOOLS_CLIENT_MODEL_AnyType_H_
#include "CppRestPetstoreClient/Object.h"
#include <cpprest/details/basic_types.h>
#include <cpprest/json.h>
namespace org {
namespace openapitools {
namespace client {
namespace model {
class AnyType : public Object {
public:
AnyType();
virtual ~AnyType();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
web::json::value toJson() const override;
bool fromJson(const web::json::value &json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &namePrefix) const override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &namePrefix) override;
private:
web::json::value m_value;
};
}
}
}
}
#endif /* ORG_OPENAPITOOLS_CLIENT_MODEL_AnyType_H_ */

View File

@ -0,0 +1,52 @@
/**
* 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/AnyType.h"
namespace org {
namespace openapitools {
namespace client {
namespace model {
AnyType::AnyType() { m_value = web::json::value::null(); }
AnyType::~AnyType() {}
void AnyType::validate() {}
web::json::value AnyType::toJson() const { return m_value; }
bool AnyType::fromJson(const web::json::value &val) {
m_value = val;
m_IsSet = true;
return isSet();
}
void AnyType::toMultipart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &prefix) const {
if (m_value.is_object()) {
return Object::toMultipart(multipart, prefix);
}
throw std::runtime_error("AnyType::toMultipart: unsupported type");
}
bool AnyType::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
const utility::string_t &prefix) {
if (m_value.is_object()) {
return Object::fromMultiPart(multipart, prefix);
}
return false;
}
}
}
}
}