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 744e0102dfd..a6385fbda37 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 CppRestClientCodegen() { 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 94fc2cc9517..39c20612dd8 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 {{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 c0ad03eaf83..442b04ec660 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 d15f49a2ad6..430ab7b9fd2 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 a74dfffbb74..538c51967ba 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 6df224f185a..b5c66268afd 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 00000000000..5ad0497e5a0 --- /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 00000000000..2bc1d86eb1f --- /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 de2e2851960..4d293d9d7ec 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 351a2727b64..1114e513a30 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 7d2e5c1ecda..ffd0b371afc 100644 --- a/samples/client/petstore/cpprest/ModelBase.h +++ b/samples/client/petstore/cpprest/ModelBase.h @@ -78,6 +78,7 @@ class ModelBase 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 00000000000..985b229d8d1 --- /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 00000000000..7b661929fb1 --- /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 62dab57218b..e95340a2eb5 100644 --- a/samples/client/petstore/cpprest/api/PetApi.h +++ b/samples/client/petstore/cpprest/api/PetApi.h @@ -20,7 +20,7 @@ #define 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 7962595aaa0..96b9f10fbde 100644 --- a/samples/client/petstore/cpprest/api/StoreApi.h +++ b/samples/client/petstore/cpprest/api/StoreApi.h @@ -20,7 +20,7 @@ #define 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 92d720c6a00..254a337f1bb 100644 --- a/samples/client/petstore/cpprest/api/UserApi.h +++ b/samples/client/petstore/cpprest/api/UserApi.h @@ -20,7 +20,7 @@ #define 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 ff7ebe5f8f2..3d48392ceaf 100644 --- a/samples/client/petstore/cpprest/model/ApiResponse.h +++ b/samples/client/petstore/cpprest/model/ApiResponse.h @@ -20,7 +20,7 @@ #define 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 c07a4f55b4d..15c232db74a 100644 --- a/samples/client/petstore/cpprest/model/Category.h +++ b/samples/client/petstore/cpprest/model/Category.h @@ -20,7 +20,7 @@ #define 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 6ca957ae4bc..169322d66d4 100644 --- a/samples/client/petstore/cpprest/model/Order.h +++ b/samples/client/petstore/cpprest/model/Order.h @@ -20,7 +20,7 @@ #define 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 df26cd36d1c..a6516c3b7ee 100644 --- a/samples/client/petstore/cpprest/model/Pet.h +++ b/samples/client/petstore/cpprest/model/Pet.h @@ -20,7 +20,7 @@ #define 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 24b9e654188..1e53948ff0f 100644 --- a/samples/client/petstore/cpprest/model/Tag.h +++ b/samples/client/petstore/cpprest/model/Tag.h @@ -20,7 +20,7 @@ #define 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 69eedb0fcfa..71439aa276c 100644 --- a/samples/client/petstore/cpprest/model/User.h +++ b/samples/client/petstore/cpprest/model/User.h @@ -20,7 +20,7 @@ #define User_H_ -#include "ModelBase.h" +#include "../ModelBase.h" #include