mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
[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:
parent
dc96d648f7
commit
7036b99e91
5
.gitignore
vendored
5
.gitignore
vendored
@ -85,6 +85,11 @@ samples/client/petstore/cpp-restsdk/CMakeCache.txt
|
||||
samples/client/petstore/cpp-restsdk/CMakeFiles/
|
||||
samples/client/petstore/cpp-restsdk/Makefile
|
||||
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
|
||||
**/.gradle
|
||||
|
@ -184,7 +184,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|Uuid|✗|
|
||||
|Array|✓|OAS2,OAS3
|
||||
|Null|✗|OAS3
|
||||
|AnyType|✗|OAS2,OAS3
|
||||
|AnyType|✓|OAS2,OAS3
|
||||
|Object|✓|OAS2,OAS3
|
||||
|Maps|✓|ToolingExtension
|
||||
|CollectionFormat|✓|OAS2
|
||||
|
@ -111,6 +111,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
.excludeParameterFeatures(
|
||||
ParameterFeature.Cookie
|
||||
)
|
||||
.includeDataTypeFeatures(
|
||||
DataTypeFeature.AnyType)
|
||||
);
|
||||
|
||||
apiPackage = "org.openapitools.client.api";
|
||||
@ -174,6 +176,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
importMapping.put("std::string", "#include <string>");
|
||||
importMapping.put("HttpContent", "#include \"HttpContent.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::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("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-source.mustache", getSourceFolder(), "ModelBase.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object-header.mustache", getHeaderFolder(), "Object.h"));
|
||||
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-source.mustache", getSourceFolder(), "ApiClient.cpp"));
|
||||
supportingFiles.add(new SupportingFile("apiconfiguration-header.mustache", getHeaderFolder(), "ApiConfiguration.h"));
|
||||
|
46
modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/anytype-header.mustache
vendored
Normal file
46
modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/anytype-header.mustache
vendored
Normal 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_ */
|
40
modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/anytype-source.mustache
vendored
Normal file
40
modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/anytype-source.mustache
vendored
Normal 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}}
|
@ -1,8 +1,10 @@
|
||||
.gitignore
|
||||
.openapi-generator-ignore
|
||||
CMakeLists.txt
|
||||
Config.cmake.in
|
||||
README.md
|
||||
git_push.sh
|
||||
include/CppRestPetstoreClient/AnyType.h
|
||||
include/CppRestPetstoreClient/ApiClient.h
|
||||
include/CppRestPetstoreClient/ApiConfiguration.h
|
||||
include/CppRestPetstoreClient/ApiException.h
|
||||
@ -21,6 +23,7 @@ include/CppRestPetstoreClient/model/Order.h
|
||||
include/CppRestPetstoreClient/model/Pet.h
|
||||
include/CppRestPetstoreClient/model/Tag.h
|
||||
include/CppRestPetstoreClient/model/User.h
|
||||
src/AnyType.cpp
|
||||
src/ApiClient.cpp
|
||||
src/ApiConfiguration.cpp
|
||||
src/ApiException.cpp
|
||||
|
@ -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_ */
|
52
samples/client/petstore/cpp-restsdk/client/src/AnyType.cpp
Normal file
52
samples/client/petstore/cpp-restsdk/client/src/AnyType.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user