diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java index b93ee0d6c9..315a6f0f27 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java @@ -113,6 +113,8 @@ public class CppRestClientCodegen extends AbstractCppCodegen { supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h")); supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp")); + supportingFiles.add(new SupportingFile("object-header.mustache", "", "Object.h")); + supportingFiles.add(new SupportingFile("object-source.mustache", "", "Object.cpp")); supportingFiles.add(new SupportingFile("apiclient-header.mustache", "", "ApiClient.h")); supportingFiles.add(new SupportingFile("apiclient-source.mustache", "", "ApiClient.cpp")); supportingFiles.add(new SupportingFile("apiconfiguration-header.mustache", "", "ApiConfiguration.h")); diff --git a/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache index 31d44de7c4..8493906176 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache @@ -9,7 +9,7 @@ #define {{apiHeaderGuardPrefix}}_{{classname}}_H_ {{{defaultInclude}}} -#include "ApiClient.h" +#include "../ApiClient.h" {{#imports}}{{{import}}} {{/imports}} diff --git a/modules/swagger-codegen/src/main/resources/cpprest/cmake-lists.mustache b/modules/swagger-codegen/src/main/resources/cpprest/cmake-lists.mustache index c0ad03eaf8..442b04ec66 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/cmake-lists.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/cmake-lists.mustache @@ -42,7 +42,7 @@ endif( NOT DEFINED CPPREST_ROOT ) include_directories(${PROJECT_SOURCE_DIR} api model ${CPPREST_INCLUDE_DIR}) #SUPPORTING FILES -set(SUPPORTING_FILES "ApiClient" "ApiConfiguration" "ApiException" "HttpContent" "IHttpBody" "JsonBody" "ModelBase" "MultipartFormData") +set(SUPPORTING_FILES "ApiClient" "ApiConfiguration" "ApiException" "HttpContent" "IHttpBody" "JsonBody" "ModelBase" "MultipartFormData" "Object") #SOURCE FILES file(GLOB SOURCE_FILES "api/*" "model/*") diff --git a/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache index a1f265e23c..61738f52e1 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache @@ -10,7 +10,7 @@ {{^parent}} {{{defaultInclude}}} -#include "ModelBase.h" +#include "../ModelBase.h" {{/parent}} {{#imports}}{{{this}}} diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache index 909aa0520b..a68bc0cc22 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache @@ -66,6 +66,7 @@ public: static utility::datetime dateFromHttpContent(std::shared_ptr val); static bool boolFromHttpContent(std::shared_ptr val); static double doubleFromHttpContent(std::shared_ptr val); + static web::json::value valueFromHttpContent(std::shared_ptr val); static utility::string_t toBase64( utility::string_t value ); diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache index 8d15ede7b1..86f976d145 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache @@ -355,6 +355,12 @@ double ModelBase::doubleFromHttpContent(std::shared_ptr val) return result; } +web::json::value ModelBase::valueFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + return web::json::value::parse(str); +} + {{#modelNamespaceDeclarations}} } {{/modelNamespaceDeclarations}} diff --git a/modules/swagger-codegen/src/main/resources/cpprest/object-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/object-header.mustache new file mode 100644 index 0000000000..5ad0497e5a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/object-header.mustache @@ -0,0 +1,50 @@ +{{>licenseInfo}} +/* + * Object.h + * + * This is the implementation of a JSON object. + */ + +#ifndef {{modelHeaderGuardPrefix}}_Object_H_ +#define {{modelHeaderGuardPrefix}}_Object_H_ + +{{{defaultInclude}}} +#include "ModelBase.h" + +#include +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} Object : public ModelBase +{ +public: + Object(); + virtual ~Object(); + + ///////////////////////////////////////////// + /// ModelBase overrides + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Object manipulation + web::json::value getValue(const utility::string_t& key) const; + void setValue(const utility::string_t& key, const web::json::value& value); + +private: + web::json::value m_object; +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* {{modelHeaderGuardPrefix}}_Object_H_ */ diff --git a/modules/swagger-codegen/src/main/resources/cpprest/object-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/object-source.mustache new file mode 100644 index 0000000000..2bc1d86eb1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/object-source.mustache @@ -0,0 +1,69 @@ +{{>licenseInfo}} +#include "Object.h" + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +Object::Object() +{ + m_object = web::json::value::object(); +} + +Object::~Object() +{ +} + +void Object::validate() +{ + // TODO: implement validation +} + +web::json::value Object::toJson() const +{ + return m_object; +} + +void Object::fromJson(web::json::value& val) +{ + if (val.is_object()) + { + m_object = val; + } +} + +void Object::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(".")) + { + namePrefix += utility::conversions::to_string_t("."); + } + multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("object"), m_object)); +} + +void Object::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(".")) + { + namePrefix += utility::conversions::to_string_t("."); + } + + m_object = ModelBase::valueFromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object"))); +} + +web::json::value Object::getValue(const utility::string_t& key) const +{ + return m_object.at(key); +} + + +void Object::setValue(const utility::string_t& key, const web::json::value& value) +{ + m_object[key] = value; +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} diff --git a/samples/client/petstore/cpprest/CMakeLists.txt b/samples/client/petstore/cpprest/CMakeLists.txt index de2e285196..4d293d9d7e 100644 --- a/samples/client/petstore/cpprest/CMakeLists.txt +++ b/samples/client/petstore/cpprest/CMakeLists.txt @@ -42,7 +42,7 @@ endif( NOT DEFINED CPPREST_ROOT ) include_directories(${PROJECT_SOURCE_DIR} api model ${CPPREST_INCLUDE_DIR}) #SUPPORTING FILES -set(SUPPORTING_FILES "ApiClient" "ApiConfiguration" "ApiException" "HttpContent" "IHttpBody" "JsonBody" "ModelBase" "MultipartFormData") +set(SUPPORTING_FILES "ApiClient" "ApiConfiguration" "ApiException" "HttpContent" "IHttpBody" "JsonBody" "ModelBase" "MultipartFormData" "Object") #SOURCE FILES file(GLOB SOURCE_FILES "api/*" "model/*") diff --git a/samples/client/petstore/cpprest/ModelBase.cpp b/samples/client/petstore/cpprest/ModelBase.cpp index 133b82fec7..984e9f6e0a 100644 --- a/samples/client/petstore/cpprest/ModelBase.cpp +++ b/samples/client/petstore/cpprest/ModelBase.cpp @@ -367,6 +367,12 @@ double ModelBase::doubleFromHttpContent(std::shared_ptr val) return result; } +web::json::value ModelBase::valueFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + return web::json::value::parse(str); +} + } } } diff --git a/samples/client/petstore/cpprest/ModelBase.h b/samples/client/petstore/cpprest/ModelBase.h index 0c13101ef5..b68b7898ad 100644 --- a/samples/client/petstore/cpprest/ModelBase.h +++ b/samples/client/petstore/cpprest/ModelBase.h @@ -78,6 +78,7 @@ public: static utility::datetime dateFromHttpContent(std::shared_ptr val); static bool boolFromHttpContent(std::shared_ptr val); static double doubleFromHttpContent(std::shared_ptr val); + static web::json::value valueFromHttpContent(std::shared_ptr val); static utility::string_t toBase64( utility::string_t value ); diff --git a/samples/client/petstore/cpprest/Object.cpp b/samples/client/petstore/cpprest/Object.cpp new file mode 100644 index 0000000000..985b229d8d --- /dev/null +++ b/samples/client/petstore/cpprest/Object.cpp @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator 2.3.0-SNAPSHOT. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +#include "Object.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +Object::Object() +{ + m_object = web::json::value::object(); +} + +Object::~Object() +{ +} + +void Object::validate() +{ + // TODO: implement validation +} + +web::json::value Object::toJson() const +{ + return m_object; +} + +void Object::fromJson(web::json::value& val) +{ + if (val.is_object()) + { + m_object = val; + } +} + +void Object::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(".")) + { + namePrefix += utility::conversions::to_string_t("."); + } + multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("object"), m_object)); +} + +void Object::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(".")) + { + namePrefix += utility::conversions::to_string_t("."); + } + + m_object = ModelBase::valueFromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object"))); +} + +web::json::value Object::getValue(const utility::string_t& key) const +{ + return m_object.at(key); +} + + +void Object::setValue(const utility::string_t& key, const web::json::value& value) +{ + m_object[key] = value; +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/Object.h b/samples/client/petstore/cpprest/Object.h new file mode 100644 index 0000000000..7b661929fb --- /dev/null +++ b/samples/client/petstore/cpprest/Object.h @@ -0,0 +1,63 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator 2.3.0-SNAPSHOT. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * Object.h + * + * This is the implementation of a JSON object. + */ + +#ifndef _Object_H_ +#define _Object_H_ + + +#include "ModelBase.h" + +#include +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class Object : public ModelBase +{ +public: + Object(); + virtual ~Object(); + + ///////////////////////////////////////////// + /// ModelBase overrides + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Object manipulation + web::json::value getValue(const utility::string_t& key) const; + void setValue(const utility::string_t& key, const web::json::value& value); + +private: + web::json::value m_object; +}; + +} +} +} +} + +#endif /* _Object_H_ */ diff --git a/samples/client/petstore/cpprest/api/PetApi.h b/samples/client/petstore/cpprest/api/PetApi.h index adf9682191..99b335bca7 100644 --- a/samples/client/petstore/cpprest/api/PetApi.h +++ b/samples/client/petstore/cpprest/api/PetApi.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_API_PetApi_H_ -#include "ApiClient.h" +#include "../ApiClient.h" #include "ApiResponse.h" #include "HttpContent.h" diff --git a/samples/client/petstore/cpprest/api/StoreApi.h b/samples/client/petstore/cpprest/api/StoreApi.h index 8140477461..740d0673d6 100644 --- a/samples/client/petstore/cpprest/api/StoreApi.h +++ b/samples/client/petstore/cpprest/api/StoreApi.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_API_StoreApi_H_ -#include "ApiClient.h" +#include "../ApiClient.h" #include "Order.h" #include diff --git a/samples/client/petstore/cpprest/api/UserApi.h b/samples/client/petstore/cpprest/api/UserApi.h index 41da01a5c8..83d80dfedc 100644 --- a/samples/client/petstore/cpprest/api/UserApi.h +++ b/samples/client/petstore/cpprest/api/UserApi.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_API_UserApi_H_ -#include "ApiClient.h" +#include "../ApiClient.h" #include "User.h" #include diff --git a/samples/client/petstore/cpprest/model/ApiResponse.h b/samples/client/petstore/cpprest/model/ApiResponse.h index 248d080d83..5b78aa749a 100644 --- a/samples/client/petstore/cpprest/model/ApiResponse.h +++ b/samples/client/petstore/cpprest/model/ApiResponse.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_ApiResponse_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include diff --git a/samples/client/petstore/cpprest/model/Category.h b/samples/client/petstore/cpprest/model/Category.h index 16b94d97cf..eac7f30e71 100644 --- a/samples/client/petstore/cpprest/model/Category.h +++ b/samples/client/petstore/cpprest/model/Category.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_Category_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include diff --git a/samples/client/petstore/cpprest/model/Order.h b/samples/client/petstore/cpprest/model/Order.h index 844a0fcd9f..d43f15994f 100644 --- a/samples/client/petstore/cpprest/model/Order.h +++ b/samples/client/petstore/cpprest/model/Order.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_Order_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include diff --git a/samples/client/petstore/cpprest/model/Pet.h b/samples/client/petstore/cpprest/model/Pet.h index 0360c6777c..fd5b404070 100644 --- a/samples/client/petstore/cpprest/model/Pet.h +++ b/samples/client/petstore/cpprest/model/Pet.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_Pet_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include "Tag.h" #include diff --git a/samples/client/petstore/cpprest/model/Tag.h b/samples/client/petstore/cpprest/model/Tag.h index 17bd0a0ebb..27cc5958cf 100644 --- a/samples/client/petstore/cpprest/model/Tag.h +++ b/samples/client/petstore/cpprest/model/Tag.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_Tag_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include diff --git a/samples/client/petstore/cpprest/model/User.h b/samples/client/petstore/cpprest/model/User.h index f213883e4c..d2272b03a2 100644 --- a/samples/client/petstore/cpprest/model/User.h +++ b/samples/client/petstore/cpprest/model/User.h @@ -20,7 +20,7 @@ #define IO_SWAGGER_CLIENT_MODEL_User_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include