Change the Model template (#5222)

This commit is contained in:
sunn 2020-02-25 10:21:44 +01:00 committed by GitHub
parent 54c2956461
commit 2d6311cbdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1795 additions and 1272 deletions

View File

@ -24,6 +24,7 @@ import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.templating.mustache.IndentedLambda;
@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
abstract public class AbstractCppCodegen extends DefaultCodegen implements CodegenConfig {
@ -327,7 +329,17 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
}
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
List<Object> models = (List<Object>) objs.get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
// cannot handle inheritance from maps and arrays in C++
if((cm.isArrayModel || cm.isMapModel ) && (cm.parentModel == null)) {
cm.parent = null;
}
}
return postProcessModelsEnum(objs);
}
}

View File

@ -169,7 +169,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
typeMapping.put("map", "std::map");
typeMapping.put("file", "HttpContent");
typeMapping.put("object", "Object");
typeMapping.put("binary", "utility::string_t");
typeMapping.put("binary", "HttpContent");
typeMapping.put("number", "double");
typeMapping.put("UUID", "utility::string_t");
typeMapping.put("URI", "utility::string_t");
@ -348,6 +348,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isFileSchema(p) || ModelUtils.isBinarySchema(p)) {
return "std::shared_ptr<" + openAPIType + ">";
} else if (ModelUtils.isStringSchema(p)
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
@ -403,9 +405,10 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
boolean isPrimitiveType = parameter.isPrimitiveType == Boolean.TRUE;
boolean isListContainer = parameter.isListContainer == Boolean.TRUE;
boolean isMapContainer = parameter.isMapContainer == Boolean.TRUE;
boolean isString = parameter.isString == Boolean.TRUE;
if (!isPrimitiveType && !isListContainer && !isString && !parameter.dataType.startsWith("std::shared_ptr")) {
if (!isPrimitiveType && !isListContainer && !isMapContainer && !isString && !parameter.dataType.startsWith("std::shared_ptr")) {
parameter.dataType = "std::shared_ptr<" + parameter.dataType + ">";
}
}

View File

@ -44,10 +44,10 @@ make
- Once visual studio opens, CMake should show up in top menu bar.
- Select CMake > Build All.
*Note: If the CMake menu item doesn't show up in Visual Studio, CMake
for Visual Studio must be installed. In this case, open the 'Visual Studio
Installer' application. Select 'modify' Visual Studio 2017. Make sure
'Desktop Development with C++' is installed, and specifically that 'Visual
*Note: If the CMake menu item doesn't show up in Visual Studio, CMake
for Visual Studio must be installed. In this case, open the 'Visual Studio
Installer' application. Select 'modify' Visual Studio 2017. Make sure
'Desktop Development with C++' is installed, and specifically that 'Visual
C++ tools for CMake' is selected in the 'Installation Details' section.
Also be sure to review the CMakeLists.txt file. Edits are likely required.*

View File

@ -33,7 +33,7 @@ public:
{{#operation}}
virtual pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}(
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{^required}}boost::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
) const = 0;
{{/operation}}
@ -67,7 +67,7 @@ public:
{{/allParams}}
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}(
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{^required}}boost::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
) const{{#gmockApis}} override{{/gmockApis}};
{{/operation}}

View File

@ -26,7 +26,7 @@ using namespace {{modelNamespace}};
}
{{#operation}}
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{classname}}::{{operationId}}({{#allParams}}{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) const
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{classname}}::{{operationId}}({{#allParams}}{{^required}}boost::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) const
{
{{#allParams}}{{#required}}{{^isPrimitiveType}}{{^isContainer}}
// verify the required parameter '{{paramName}}' is set
@ -160,13 +160,13 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
web::json::value localVarJson;
{{#isPrimitiveType}}
localVarJson = ModelBase::toJson({{paramName}});
localVarJson = ModelBase::toJson({{paramName}}{{^required}}.get(){{/required}});
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
{
std::vector<web::json::value> localVarJsonArray;
for( auto& localVarItem : {{paramName}} )
for( auto& localVarItem : {{paramName}}{{^required}}.get(){{/required}} )
{
{{#items.isPrimitiveType}}localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
{{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
@ -193,30 +193,32 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
{{#bodyParam}}
std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);
{{#isPrimitiveType}}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), {{paramName}}));
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), {{paramName}}{{^required}}.get(){{/required}}));
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}
{
std::vector<web::json::value> localVarJsonArray;
for( auto& localVarItem : {{paramName}} )
for( auto& localVarItem : {{paramName}}{{^required}}.get(){{/required}} )
{
{{#items.isPrimitiveType}}localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
{{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
{{/items.isString}}{{^items.isString}}{{#items.isDateTime}}localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
{{/items.isDateTime}}{{^items.isDateTime}}localVarJsonArray.push_back( localVarItem.get() ? localVarItem->toJson() : web::json::value::null() );
{{/items.isDateTime}}{{/items.isString}}{{/items.isPrimitiveType}}
localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), web::json::value::array(localVarJsonArray), utility::conversions::to_string_t("application/json")));
}{{/isListContainer}}
{{^isListContainer}}{{#isString}}localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), {{paramName}}));
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), localVarJsonArray, utility::conversions::to_string_t("application/json")));
}{{/isListContainer}}{{#isMapContainer}}
{
std::map<utility::string_t, web::json::value> localVarJsonMap;
for( auto& localVarItem : {{paramName}}{{^required}}.get(){{/required}} )
{
web::json::value jval;
localVarJsonMap.insert( std::pair<utility::string_t, web::json::value>(localVarItem.first, ModelBase::toJson(localVarItem.second) ));
}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), localVarJsonMap, utility::conversions::to_string_t("application/json")));
}{{/isMapContainer}}
{{^isListContainer}}{{^isMapContainer}}{{#isString}}localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("{{paramName}}"), {{paramName}}));
{{/isString}}{{^isString}}if({{^required}}{{paramName}} && (*{{paramName}}){{/required}}{{#required}}{{paramName}}{{/required}}.get())
{
{{^required}}(*{{/required}}{{paramName}}{{^required}}){{/required}}->toMultipart(localVarMultipart, utility::conversions::to_string_t("{{paramName}}"));
}
{{/isString}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{/isMapContainer}}{{/isListContainer}}{{/isPrimitiveType}}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
@ -318,29 +320,20 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
{{#isListContainer}}for( auto& localVarItem : localVarJson.as_array() )
{{#isListContainer}}
for( auto& localVarItem : localVarJson.as_array() )
{
{{#vendorExtensions.x-codegen-response.items.isPrimitiveType}}localVarResult.push_back(ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(localVarItem));
{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.items.isString}}localVarResult.push_back(ModelBase::stringFromJson(localVarItem));
{{/vendorExtensions.x-codegen-response.items.isString}}{{^vendorExtensions.x-codegen-response.items.isString}}{{{vendorExtensions.x-codegen-response.items.datatype}}} localVarItemObj({{{vendorExtensions.x-codegen-response.items.defaultValue}}});
localVarItemObj->fromJson(localVarItem);
{{{vendorExtensions.x-codegen-response.items.datatype}}} localVarItemObj;
ModelBase::fromJson(localVarItem, localVarItemObj);
localVarResult.push_back(localVarItemObj);
{{/vendorExtensions.x-codegen-response.items.isString}}{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}
}
{{/isListContainer}}{{^isListContainer}}{{#isMapContainer}}for( auto& localVarItem : localVarJson.as_object() )
}{{/isListContainer}}{{#isMapContainer}}
for( auto& localVarItem : localVarJson.as_object() )
{
{{#vendorExtensions.x-codegen-response.items.isPrimitiveType}}localVarResult[localVarItem.first] = ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(localVarItem.second);
{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.items.isString}}localVarResult[localVarItem.first] = ModelBase::stringFromJson(localVarItem.second);
{{/vendorExtensions.x-codegen-response.items.isString}}{{^vendorExtensions.x-codegen-response.items.isString}}{{{vendorExtensions.x-codegen-response.items.datatype}}} localVarItemObj({{{vendorExtensions.x-codegen-response.items.defaultValue}}});
localVarItemObj->fromJson(localVarItem.second);
{{{vendorExtensions.x-codegen-response.items.datatype}}} localVarItemObj;
ModelBase::fromJson(localVarItem.second, localVarItemObj);
localVarResult[localVarItem.first] = localVarItemObj;
{{/vendorExtensions.x-codegen-response.items.isString}}{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}
}
{{/isMapContainer}}{{^isMapContainer}}{{#vendorExtensions.x-codegen-response.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.items.datatype}}localVarResult = ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(localVarJson);
{{/vendorExtensions.x-codegen-response.items.datatype}}{{^vendorExtensions.x-codegen-response.items.datatype}}localVarResult = ModelBase::{{vendorExtensions.x-codegen-response.datatype}}FromJson(localVarJson);
{{/vendorExtensions.x-codegen-response.items.datatype}}{{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.isString}}localVarResult = ModelBase::stringFromJson(localVarJson);
{{/vendorExtensions.x-codegen-response.isString}}{{^vendorExtensions.x-codegen-response.isString}}localVarResult->fromJson(localVarJson);{{/vendorExtensions.x-codegen-response.isString}}{{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{/isMapContainer}}{{/isListContainer}}
}{{/isMapContainer}}{{^isListContainer}}{{^isMapContainer}}
ModelBase::fromJson(localVarJson, localVarResult);{{/isMapContainer}}{{/isListContainer}}
}{{#vendorExtensions.x-codegen-response.isString}}
else if(localVarResponseHttpContentType == utility::conversions::to_string_t("text/plain"))
{

View File

@ -24,19 +24,19 @@ public:
HttpContent();
virtual ~HttpContent();
virtual utility::string_t getContentDisposition();
virtual utility::string_t getContentDisposition() const;
virtual void setContentDisposition( const utility::string_t& value );
virtual utility::string_t getName();
virtual utility::string_t getName() const;
virtual void setName( const utility::string_t& value );
virtual utility::string_t getFileName();
virtual utility::string_t getFileName() const;
virtual void setFileName( const utility::string_t& value );
virtual utility::string_t getContentType();
virtual utility::string_t getContentType() const;
virtual void setContentType( const utility::string_t& value );
virtual std::shared_ptr<std::istream> getData();
virtual std::shared_ptr<std::istream> getData() const;
virtual void setData( std::shared_ptr<std::istream> value );
virtual void writeTo( std::ostream& stream );

View File

@ -13,7 +13,7 @@ HttpContent::~HttpContent()
{
}
utility::string_t HttpContent::getContentDisposition()
utility::string_t HttpContent::getContentDisposition() const
{
return m_ContentDisposition;
}
@ -23,7 +23,7 @@ void HttpContent::setContentDisposition( const utility::string_t & value )
m_ContentDisposition = value;
}
utility::string_t HttpContent::getName()
utility::string_t HttpContent::getName() const
{
return m_Name;
}
@ -33,7 +33,7 @@ void HttpContent::setName( const utility::string_t & value )
m_Name = value;
}
utility::string_t HttpContent::getFileName()
utility::string_t HttpContent::getFileName() const
{
return m_FileName;
}
@ -43,7 +43,7 @@ void HttpContent::setFileName( const utility::string_t & value )
m_FileName = value;
}
utility::string_t HttpContent::getContentType()
utility::string_t HttpContent::getContentType() const
{
return m_ContentType;
}
@ -53,7 +53,7 @@ void HttpContent::setContentType( const utility::string_t & value )
m_ContentType = value;
}
std::shared_ptr<std::istream> HttpContent::getData()
std::shared_ptr<std::istream> HttpContent::getData() const
{
return m_Data;
}

View File

@ -34,12 +34,12 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
enum class e{{classname}}
enum class e{{classname}}
{
{{#allowableValues}}
{{#enumVars}}
@ -48,8 +48,8 @@ public:
/// {{enumDescription}}
/// </summary>
{{/enumDescription}}
{{classname}}_{{{name}}}{{^last}},{{/last}}
{{/enumVars}}
{{classname}}_{{{name}}}{{^last}},{{/last}}
{{/enumVars}}
{{/allowableValues}}
};
@ -78,10 +78,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// {{classname}} members
@ -93,9 +93,8 @@ public:
/// </summary>
{{#isContainer}}{{{dataType}}}& {{getter}}();
{{/isContainer}}{{^isContainer}}{{{dataType}}} {{getter}}() const;
{{/isContainer}}{{^required}}bool {{nameInCamelCase}}IsSet() const;
{{/isContainer}}bool {{nameInCamelCase}}IsSet() const;
void unset{{name}}();
{{/required}}
{{#isPrimitiveType}}
void {{setter}}({{{dataType}}} value);
@ -111,8 +110,7 @@ protected:
{{#vars}}
{{^isInherited}}
{{{dataType}}} m_{{name}};
{{^required}}bool m_{{name}}IsSet;
{{/required}}
bool m_{{name}}IsSet;
{{/isInherited}}
{{/vars}}
};

View File

@ -33,12 +33,13 @@ web::json::value {{classname}}::toJson() const
return val;
}
void {{classname}}::fromJson(const web::json::value& val)
bool {{classname}}::fromJson(const web::json::value& val)
{
auto s = val.as_string();
{{#allowableValues}}{{#enumVars}}
if (s == utility::conversions::to_string_t({{{value}}})) m_value = e{{classname}}::{{classname}}_{{name}};{{/enumVars}}{{/allowableValues}}
return true;
}
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -57,24 +58,25 @@ void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, co
multipart->add(ModelBase::toHttpContent(namePrefix, s));
}
void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
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(".");
}
{
utility::string_t s;
s = ModelBase::stringFromHttpContent(multipart->getContent(namePrefix));
ok = ModelBase::fromHttpContent(multipart->getContent(namePrefix), s);
e{{classname}} v;
{{#allowableValues}}{{#enumVars}}
if (s == utility::conversions::to_string_t({{{value}}})) v = e{{classname}}::{{classname}}_{{name}};{{/enumVars}}{{/allowableValues}}
setValue(v);
}
return ok;
}
{{classname}}::e{{classname}} {{classname}}::getValue() const
@ -108,9 +110,7 @@ void {{classname}}::setValue({{classname}}::e{{classname}} const value)
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{^required}}
m_{{name}}IsSet = false;
{{/required}}
{{/isInherited}}
{{/vars}}
}
@ -127,263 +127,37 @@ void {{classname}}::validate()
web::json::value {{classname}}::toJson() const
{
{{#parent}}
web::json::value val = this->{{{parent}}}::toJson();
{{/parent}}
web::json::value val = this->{{{parent}}}::toJson();{{/parent}}
{{^parent}}
web::json::value val = web::json::value::object();
{{/parent}}
{{#vars}}
{{^isInherited}}
{{#isPrimitiveType}}
{{^isListContainer}}
{{^isMapContainer}}
{{^required}}
{{#vars}}{{^isInherited}}
if(m_{{name}}IsSet)
{
val[utility::conversions::to_string_t("{{baseName}}")] = ModelBase::toJson(m_{{name}});
}
{{/required}}
{{#required}}
val[utility::conversions::to_string_t("{{baseName}}")] = ModelBase::toJson(m_{{name}});
{{/required}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{#isListContainer}}
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_{{name}} )
{
jsonArray.push_back(ModelBase::toJson(item));
}
{{#required}}
val[utility::conversions::to_string_t("{{baseName}}")] = web::json::value::array(jsonArray);
{{/required}}
{{^required}}
if(jsonArray.size() > 0)
{
val[utility::conversions::to_string_t("{{baseName}}")] = web::json::value::array(jsonArray);
}
{{/required}}
}
{{/isListContainer}}
{{#isMapContainer}}
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_{{name}} )
{
web::json::value tmp = web::json::value::object();
tmp[utility::conversions::to_string_t("key")] = ModelBase::toJson(item.first);
tmp[utility::conversions::to_string_t("value")] = ModelBase::toJson(item.second);
jsonArray.push_back(tmp);
}
{{#required}}
val[utility::conversions::to_string_t("{{baseName}}")] = web::json::value::array(jsonArray);
{{/required}}
{{^required}}
if(jsonArray.size() > 0)
{
val[utility::conversions::to_string_t("{{baseName}}")] = web::json::value::array(jsonArray);
}
{{/required}}
}
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^isPrimitiveType}}
{{^required}}
if(m_{{name}}IsSet)
{
val[utility::conversions::to_string_t("{{baseName}}")] = ModelBase::toJson(m_{{name}});
}
{{/required}}
{{#required}}
val[utility::conversions::to_string_t("{{baseName}}")] = ModelBase::toJson(m_{{name}});
{{/required}}
{{/isPrimitiveType}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isInherited}}
{{/vars}}
}{{/isInherited}}{{/vars}}
return val;
}
void {{classname}}::fromJson(const web::json::value& val)
bool {{classname}}::fromJson(const web::json::value& val)
{
bool ok = true;
{{#parent}}
this->{{{parent}}}::fromJson(val);
ok &= this->{{{parent}}}::fromJson(val);
{{/parent}}
{{#vars}}
{{^isInherited}}
{{#isPrimitiveType}}
{{^isListContainer}}
{{^isMapContainer}}
{{^required}}
{{#vars}}{{^isInherited}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("{{baseName}}"));
if(!fieldValue.is_null())
{
{{setter}}(ModelBase::{{baseType}}FromJson(fieldValue));
{{{dataType}}} refVal_{{baseName}};
ok &= ModelBase::fromJson(fieldValue, refVal_{{baseName}});
{{setter}}(refVal_{{baseName}});
}
}
{{/required}}
{{#required}}
{{setter}}(ModelBase::{{baseType}}FromJson(val.at(utility::conversions::to_string_t("{{baseName}}"))));
{{/required}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{#isListContainer}}
{
m_{{name}}.clear();
std::vector<web::json::value> jsonArray;
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
{{/required}}
for( auto& item : val.at(utility::conversions::to_string_t("{{baseName}}")).as_array() )
{
{{#items.isPrimitiveType}}
m_{{name}}.push_back(ModelBase::{{items.baseType}}FromJson(item));
{{/items.isPrimitiveType}}
{{^items.isPrimitiveType}}
{{#items.isString}}
m_{{name}}.push_back(ModelBase::stringFromJson(item));
{{/items.isString}}
{{^items.isString}}
{{#items.isDateTime}}
m_{{name}}.push_back(ModelBase::dateFromJson(item));
{{/items.isDateTime}}
{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.push_back( {{{items.datatype}}}(nullptr) );
}
else
{
auto newItem = std::make_shared<{{{items.datatype}}}::element_type>();
newItem->fromJson(item);
m_{{name}}.push_back( newItem );
}
{{/items.isDateTime}}
{{/items.isString}}
{{/items.isPrimitiveType}}
}
{{^required}}
}
{{/required}}
}
{{/isListContainer}}
{{#isMapContainer}}
{
m_{{name}}.clear();
std::vector<web::json::value> jsonArray;
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
{{/required}}
for( const auto& item : val.at(utility::conversions::to_string_t("{{baseName}}")).as_array() )
{
if(item.has_field(utility::conversions::to_string_t("key")))
{
utility::string_t key = ModelBase::stringFromJson(item.at(utility::conversions::to_string_t("key")));
{{#items.isPrimitiveType}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::{{items.baseType}}FromJson(item.at(utility::conversions::to_string_t("value")))));
{{/items.isPrimitiveType}}
{{^items.isPrimitiveType}}
{{#items.isString}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::stringFromJson(item.at(utility::conversions::to_string_t("value")))));
{{/items.isString}}
{{^items.isString}}
{{#items.isDateTime}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::dateFromJson(item.at(utility::conversions::to_string_t("value")))));
{{/items.isDateTime}}
{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, {{{items.datatype}}}(nullptr) ));
}
else
{
auto newItem = std::make_shared<{{{items.datatype}}}::element_type>();
newItem->fromJson(item.at(utility::conversions::to_string_t("value")));
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, newItem ));
}
{{/items.isDateTime}}
{{/items.isString}}
{{/items.isPrimitiveType}}
}
}
{{^required}}
}
{{/required}}
}
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^isPrimitiveType}}
{{^required}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("{{baseName}}"));
if(!fieldValue.is_null())
{
{{#isString}}
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromJson(fieldValue));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromJson(fieldValue));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}
auto newItem = std::make_shared<{{{datatype}}}::element_type>();
newItem->fromJson(fieldValue);
{{setter}}( newItem );
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
}
}
{{/required}}
{{#required}}
{{#isString}}
{{setter}}(ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("{{baseName}}"))));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromJson(val[utility::conversions::to_string_t("{{baseName}}")]));
{{/isByteArray}}
{{^isString}}
{{^isByteArray}}
{{#isDateTime}}
{{setter}}
(ModelBase::dateFromJson(val.at(utility::conversions::to_string_t("{{baseName}}"))));
{{/isDateTime}}
{{^isDateTime}}
{{#vendorExtensions.x-codegen-file}}
{{setter}}(ModelBase::fileFromJson(val.at(utility::conversions::to_string_t("{{baseName}}"))));
{{/vendorExtensions.x-codegen-file}}
{{^vendorExtensions.x-codegen-file}}
auto new{{name}} = std::make_shared<{{{dataType}}}::element_type>();
new{{name}}->fromJson(val.at(utility::conversions::to_string_t("{{baseName}}")));
{{setter}}( new{{name}} );
{{/vendorExtensions.x-codegen-file}}
{{/isDateTime}}
{{/isByteArray}}
{{/isString}}
{{/required}}
{{/isPrimitiveType}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isInherited}}
{{/vars}}
}{{/isInherited}}{{/vars}}
return ok;
}
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -393,115 +167,17 @@ void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, co
{
namePrefix += utility::conversions::to_string_t(".");
}
{{#vars}}
{{#isPrimitiveType}}
{{^isMapContainer}}
{{^isListContainer}}
{{^required}}
if(m_{{name}}IsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
}
{{/required}}
{{#required}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/required}}
{{/isListContainer}}
{{/isMapContainer}}
{{/isPrimitiveType}}
{{#isListContainer}}
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_{{name}} )
{
jsonArray.push_back(ModelBase::toJson(item));
}
{{#required}}multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
{{/required}}{{^required}}
if(jsonArray.size() > 0)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
}
{{/required}}
}
{{/isListContainer}}
{{#isMapContainer}}
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_{{name}} )
{
web::json::value tmp = web::json::value::object();
tmp[utility::conversions::to_string_t("key")] = ModelBase::toJson(item.first);
tmp[utility::conversions::to_string_t("value")] = ModelBase::toJson(item.second);
jsonArray.push_back(tmp);
}
{{#required}}multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
{{/required}}{{^required}}
if(jsonArray.size() > 0)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
}
{{/required}}
}
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^isPrimitiveType}}
{{^required}}
if(m_{{name}}IsSet)
{
{{#isString}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isString}}
{{#isByteArray}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}if (m_{{name}}.get())
{
m_{{name}}->toMultipart(multipart, utility::conversions::to_string_t("{{baseName}}."));
}
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
}
{{/required}}
{{#required}}
{{#isString}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isString}}
{{#isByteArray}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isByteArray}}
{{^isString}}
{{#isDateTime}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/isDateTime}}
{{^isDateTime}}
{{^isByteArray}}
{{#vendorExtensions.x-codegen-file}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
{{/vendorExtensions.x-codegen-file}}
{{^vendorExtensions.x-codegen-file}}
m_{{name}}->toMultipart(multipart, utility::conversions::to_string_t("{{baseName}}."));
{{/vendorExtensions.x-codegen-file}}
{{/isByteArray}}
{{/isDateTime}}
{{/isString}}
{{/required}}
{{/isPrimitiveType}}
{{/isMapContainer}}
{{/isListContainer}}
{{/vars}}
}
void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -509,168 +185,14 @@ void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
}
{{#vars}}
{{#isPrimitiveType}}
{{^isListContainer}}
{{^isMapContainer}}
{{^required}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
{{setter}}(ModelBase::{{baseType}}FromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{{dataType}}} refVal_{{baseName}};
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}")), refVal_{{baseName}} );
{{setter}}(refVal_{{baseName}});
}
{{/required}}
{{#required}}
{{setter}}(ModelBase::{{baseType}}FromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/required}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{#isListContainer}}
{
m_{{name}}.clear();
{{^required}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
{{/required}}
web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
for( auto& item : jsonArray.as_array() )
{
{{#isPrimitiveType}}
m_{{name}}.push_back(ModelBase::{{items.baseType}}FromJson(item));
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#items.isString}}
m_{{name}}.push_back(ModelBase::stringFromJson(item));
{{/items.isString}}
{{^items.isString}}
{{#items.isDateTime}}
m_{{name}}.push_back(ModelBase::dateFromJson(item));
{{/items.isDateTime}}
{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.push_back( {{{items.datatype}}}(nullptr) );
}
else
{
auto newItem = std::make_shared<{{{items.datatype}}}::element_type>();
newItem->fromJson(item);
m_{{name}}.push_back( newItem );
}
{{/items.isDateTime}}
{{/items.isString}}
{{/isPrimitiveType}}
}
{{^required}}
}
{{/required}}
}
{{/isListContainer}}
{{#isMapContainer}}
{
m_{{name}}.clear();
{{^required}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
{{/required}}
web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
for( auto& item : jsonArray.as_array() )
{
utility::string_t key;
if(item.has_field(utility::conversions::to_string_t("key")))
{
key = ModelBase::stringFromJson(item[utility::conversions::to_string_t("key")]);
}
{{#items.isPrimitiveType}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::{{items.baseType}}FromJson(item[utility::conversions::to_string_t("value")])));
{{/items.isPrimitiveType}}
{{^items.isPrimitiveType}}
{{#items.isString}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::stringFromJson(item[utility::conversions::to_string_t("value")])));
{{/items.isString}}
{{^items.isString}}
{{#items.isDateTime}}
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::dateFromJson(item[utility::conversions::to_string_t("value")])));
{{/items.isDateTime}}
{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, {{{items.datatype}}}(nullptr) ));
}
else
{
auto newItem = std::make_shared<{{{items.datatype}}}::element_type>();
newItem->fromJson(item[utility::conversions::to_string_t("value")]);
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, newItem ));
}
{{/items.isDateTime}}
{{/items.isString}}
{{/items.isPrimitiveType}}
}
{{^required}}
}
{{/required}}
}
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^isPrimitiveType}}
{{^required}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
{{#isString}}
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isByteArray}}
{{^isString}}
{{^isByteArray}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isDateTime}}
{{^isDateTime}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
auto newItem = std::make_shared<{{{datatype}}}::element_type>();
newItem->fromMultiPart(multipart, utility::conversions::to_string_t("{{baseName}}."));
{{setter}}( newItem );
}
{{/isDateTime}}
{{/isByteArray}}
{{/isString}}
}
{{/required}}
{{#required}}
{{#isString}}
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isString}}
{{#isByteArray}}
{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isByteArray}}
{{^isString}}
{{^isByteArray}}
{{#isDateTime}}
{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}"))));
{{/isDateTime}}
{{^isDateTime}}
{{#vendorExtensions.x-codegen-file}}
{{setter}}(multipart->getContent(utility::conversions::to_string_t("{{baseName}}")));
{{/vendorExtensions.x-codegen-file}}
{{^vendorExtensions.x-codegen-file}}
auto new{{name}} = std::make_shared<{{{dataType}}}::element_type>();
new{{name}}->fromMultiPart(multipart, utility::conversions::to_string_t("{{baseName}}."));
{{setter}}( new{{name}} );
{{/vendorExtensions.x-codegen-file}}
{{/isDateTime}}
{{/isByteArray}}
{{/isString}}
{{/required}}
{{/isPrimitiveType}}
{{/isMapContainer}}
{{/isListContainer}}
{{/vars}}
return ok;
}
{{#vars}}
@ -696,10 +218,9 @@ void {{classname}}::{{setter}}(const {{{dataType}}}& value)
{{/isPrimitiveType}}
{
m_{{name}} = value;
{{^required}}m_{{name}}IsSet = true;{{/required}}
m_{{name}}IsSet = true;
}
{{^required}}
bool {{classname}}::{{nameInCamelCase}}IsSet() const
{
return m_{{name}}IsSet;
@ -709,8 +230,6 @@ void {{classname}}::unset{{name}}()
{
m_{{name}}IsSet = false;
}
{{/required}}
{{/isInherited}}
{{/vars}}
{{/isEnum}}

View File

@ -9,14 +9,15 @@
#define {{modelHeaderGuardPrefix}}_ModelBase_H_
{{{defaultInclude}}}
#include <map>
#include <vector>
#include "HttpContent.h"
#include "MultipartFormData.h"
#include <cpprest/details/basic_types.h>
#include <cpprest/json.h>
#include <vector>
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
@ -30,68 +31,252 @@ public:
virtual void validate() = 0;
virtual web::json::value toJson() const = 0;
virtual void fromJson(const web::json::value& json) = 0;
virtual bool fromJson( const web::json::value& json ) = 0;
virtual void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const = 0;
virtual void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) = 0;
virtual void toMultipart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) const = 0;
virtual bool fromMultiPart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) = 0;
static web::json::value toJson( const utility::string_t& value );
static web::json::value toJson( const utility::datetime& value );
static web::json::value toJson( std::shared_ptr<HttpContent> value );
static web::json::value toJson( std::shared_ptr<ModelBase> value );
static web::json::value toJson( int32_t value );
static web::json::value toJson( int64_t value );
static web::json::value toJson( double value );
static web::json::value toJson( bool value );
template<class T>
static web::json::value toJson(const std::vector<T>& value);
virtual bool isSet() const;
static int64_t int64_tFromJson(const web::json::value& val);
static int32_t int32_tFromJson(const web::json::value& val);
static float floatFromJson(const web::json::value& val);
static utility::string_t stringFromJson(const web::json::value& val);
static utility::datetime dateFromJson(const web::json::value& val);
static double doubleFromJson(const web::json::value& val);
static bool boolFromJson(const web::json::value& val);
static std::shared_ptr<HttpContent> fileFromJson(const web::json::value& val);
static utility::string_t toString( const bool val );
static utility::string_t toString( const float val );
static utility::string_t toString( const double val );
static utility::string_t toString( const int32_t val );
static utility::string_t toString( const int64_t val );
static utility::string_t toString( const utility::string_t &val );
static utility::string_t toString( const utility::datetime &val );
static utility::string_t toString( const web::json::value &val );
static utility::string_t toString( const std::shared_ptr<HttpContent>& val );
template <typename T>
static utility::string_t toString( const std::shared_ptr<T>& val );
template <typename T>
static utility::string_t toString( const std::vector<T> & val );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
static web::json::value toJson( bool val );
static web::json::value toJson( float val );
static web::json::value toJson( double val );
static web::json::value toJson( int32_t val );
static web::json::value toJson( int64_t val );
static web::json::value toJson( const utility::string_t& val );
static web::json::value toJson( const utility::datetime& val );
static web::json::value toJson( const web::json::value& val );
static web::json::value toJson( const std::shared_ptr<HttpContent>& val );
template<typename T>
static web::json::value toJson( const std::shared_ptr<T>& val );
template<typename T>
static web::json::value toJson( const std::vector<T>& val );
template<typename T>
static web::json::value toJson( const std::map<utility::string_t, T>& val );
static bool fromString( const utility::string_t& val, bool & );
static bool fromString( const utility::string_t& val, float & );
static bool fromString( const utility::string_t& val, double & );
static bool fromString( const utility::string_t& val, int32_t & );
static bool fromString( const utility::string_t& val, int64_t & );
static bool fromString( const utility::string_t& val, utility::string_t & );
static bool fromString( const utility::string_t& val, utility::datetime & );
static bool fromString( const utility::string_t& val, web::json::value & );
static bool fromString( const utility::string_t& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::shared_ptr<T>& );
template<typename T>
static bool fromString( const utility::string_t& val, std::vector<T> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::map<utility::string_t, T> & );
static bool fromJson( const web::json::value& val, bool & );
static bool fromJson( const web::json::value& val, float & );
static bool fromJson( const web::json::value& val, double & );
static bool fromJson( const web::json::value& val, int32_t & );
static bool fromJson( const web::json::value& val, int64_t & );
static bool fromJson( const web::json::value& val, utility::string_t & );
static bool fromJson( const web::json::value& val, utility::datetime & );
static bool fromJson( const web::json::value& val, web::json::value & );
static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
template<typename T>
static bool fromJson( const web::json::value& val, std::vector<T> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::map<utility::string_t, T> & );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <class T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<T>& , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static int64_t int64_tFromHttpContent(std::shared_ptr<HttpContent> val);
static int32_t int32_tFromHttpContent(std::shared_ptr<HttpContent> val);
static float floatFromHttpContent(std::shared_ptr<HttpContent> val);
static utility::string_t stringFromHttpContent(std::shared_ptr<HttpContent> val);
static utility::datetime dateFromHttpContent(std::shared_ptr<HttpContent> val);
static bool boolFromHttpContent(std::shared_ptr<HttpContent> val);
static double doubleFromHttpContent(std::shared_ptr<HttpContent> val);
static web::json::value valueFromHttpContent(std::shared_ptr<HttpContent> val);
static bool fromHttpContent( std::shared_ptr<HttpContent> val, bool & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, float & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, double & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, int64_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, int32_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::string_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::datetime & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, web::json::value & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & );
static utility::string_t toBase64( utility::string_t value );
static utility::string_t toBase64( std::shared_ptr<std::istream> value );
static std::shared_ptr<std::istream> fromBase64( const utility::string_t& encoded );
protected:
bool m_IsSet;
};
template<class T>
web::json::value ModelBase::toJson(const std::vector<T>& value) {
std::vector<web::json::value> ret;
for (auto& x : value) {
ret.push_back(toJson(x));
template <typename T>
utility::string_t ModelBase::toString( const std::shared_ptr<T>& val )
{
utility::stringstream_t ss;
if( val != nullptr )
{
val->toJson().serialize(ss);
}
return utility::string_t(ss.str());
}
template<typename T>
utility::string_t ModelBase::toString( const std::vector<T> & val )
{
utility::string_t strArray;
for ( const auto &item : val )
{
strArray.append( toString(item) + "," );
}
if (val.count() > 0)
{
strArray.pop_back();
}
return strArray;
}
template<typename T>
web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
{
web::json::value retVal;
if(val != nullptr)
{
retVal = val->toJson();
}
return retVal;
}
template<typename T>
web::json::value ModelBase::toJson( const std::vector<T>& value )
{
std::vector<web::json::value> ret;
for ( const auto& x : value )
{
ret.push_back( toJson(x) );
}
return web::json::value::array(ret);
}
template <class T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType ) {
template<typename T>
web::json::value ModelBase::toJson( const std::map<utility::string_t, T>& val )
{
web::json::value obj;
for ( const auto &itemkey : val )
{
obj[itemkey.first] = toJson( itemkey.second );
}
return obj;
}
template<typename T>
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<T>& outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<T>(new T());
}
if( outVal != nullptr )
{
ok = outVal->fromJson(web::json::value::parse(val));
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<T> &outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<T>(new T());
}
if( outVal != nullptr )
{
ok = outVal->fromJson(val);
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& val, std::vector<T> &outVal )
{
bool ok = true;
if (val.is_array())
{
for (const auto jitem : val.as_array())
{
T item;
ok &= fromJson(jitem, item);
outVal.push_back(item);
}
}
else
{
ok = false;
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& jval, std::map<utility::string_t, T> &outVal )
{
bool ok = true;
if ( jval.is_object() )
{
auto obj = jval.as_object();
for( auto objItr = obj.begin() ; objItr != obj.end() ; objItr++ )
{
T itemVal;
ok &= fromJson(objItr->second, itemVal);
outVal.insert(std::pair<utility::string_t, T>(objItr->first, itemVal));
}
}
else
{
ok = false;
}
return ok;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<T>& value , const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if (value != nullptr )
{
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) );
}
return content;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
{
web::json::value json_array = ModelBase::toJson(value);
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
@ -100,7 +285,39 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
return content;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
{
web::json::value jobj = ModelBase::toJson(value);
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) );
return content;
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& outVal )
{
utility::string_t str;
if(val == nullptr) return false;
if( outVal == nullptr )
{
outVal = std::shared_ptr<T>(new T());
}
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & )
{
return true;
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & )
{
return true;
}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}

View File

@ -5,20 +5,80 @@
namespace {{this}} {
{{/modelNamespaceDeclarations}}
ModelBase::ModelBase()
ModelBase::ModelBase(): m_IsSet(false)
{
}
ModelBase::~ModelBase()
{
}
web::json::value ModelBase::toJson( const utility::string_t& value )
bool ModelBase::isSet() const
{
return web::json::value::string(value);
return m_IsSet;
}
web::json::value ModelBase::toJson( const utility::datetime& value )
utility::string_t ModelBase::toString( const bool val )
{
return web::json::value::string(value.to_string(utility::datetime::ISO_8601));
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const float val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const double val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int32_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int64_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString (const utility::string_t &val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const utility::datetime &val )
{
return val.to_string(utility::datetime::ISO_8601);
}
utility::string_t ModelBase::toString( const web::json::value &val )
{
return val.serialize();
}
utility::string_t ModelBase::toString( const std::shared_ptr<HttpContent>& val )
{
utility::stringstream_t ss;
if( val != nullptr )
{
ss << val->getData();
}
return utility::string_t(ss.str());
}
web::json::value ModelBase::toJson(bool value)
{
return web::json::value::boolean(value);
}
web::json::value ModelBase::toJson( float value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( double value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( int32_t value )
{
@ -28,88 +88,259 @@ web::json::value ModelBase::toJson( int64_t value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( double value )
web::json::value ModelBase::toJson( const utility::string_t& value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson(bool value) {
return web::json::value::boolean(value);
return web::json::value::string(value);
}
web::json::value ModelBase::toJson( std::shared_ptr<HttpContent> content )
web::json::value ModelBase::toJson( const utility::datetime& value )
{
return web::json::value::string(value.to_string(utility::datetime::ISO_8601));
}
web::json::value ModelBase::toJson( const web::json::value& value )
{
web::json::value value;
value[utility::conversions::to_string_t("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition());
value[utility::conversions::to_string_t("ContentType")] = ModelBase::toJson(content->getContentType());
value[utility::conversions::to_string_t("FileName")] = ModelBase::toJson(content->getFileName());
value[utility::conversions::to_string_t("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) );
return value;
}
std::shared_ptr<HttpContent> ModelBase::fileFromJson(const web::json::value& val)
web::json::value ModelBase::toJson( const std::shared_ptr<HttpContent>& content )
{
std::shared_ptr<HttpContent> content(new HttpContent);
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
web::json::value value;
if(content != nullptr)
{
content->setContentDisposition( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("ContentDisposition"))) );
value[utility::conversions::to_string_t("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition());
value[utility::conversions::to_string_t("ContentType")] = ModelBase::toJson(content->getContentType());
value[utility::conversions::to_string_t("FileName")] = ModelBase::toJson(content->getFileName());
value[utility::conversions::to_string_t("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) );
}
if(val.has_field(utility::conversions::to_string_t("ContentType")))
{
content->setContentType( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("ContentType"))) );
}
if(val.has_field(utility::conversions::to_string_t("FileName")))
{
content->setFileName( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("FileName"))) );
}
if(val.has_field(utility::conversions::to_string_t("InputStream")))
{
content->setData( ModelBase::fromBase64( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("InputStream")))) );
}
return content;
return value;
}
web::json::value ModelBase::toJson( std::shared_ptr<ModelBase> content )
bool ModelBase::fromString( const utility::string_t& val, bool &outVal )
{
return content.get() ? content->toJson() : web::json::value::null();
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
bool ModelBase::fromString( const utility::string_t& val, float &outVal )
{
std::shared_ptr<HttpContent> content(new HttpContent);
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
return content;
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
bool ModelBase::fromString( const utility::string_t& val, double &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int32_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int64_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::string_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::datetime &outVal )
{
bool success = true;
auto dt = utility::datetime::from_string(val, utility::datetime::ISO_8601);
if( dt.is_initialized() )
{
outVal = dt;
}
else
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, web::json::value &outVal )
{
outVal = web::json::value::parse(val);
return !outVal.is_null();
}
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<HttpContent>& outVal )
{
bool ok = true;
if(outVal == nullptr)
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
std::shared_ptr<utility::stringstream_t> ssptr = std::make_shared<utility::stringstream_t>(val);
if(outVal != nullptr)
{
outVal->setData(ssptr);
}
else
{
ok = false;
}
return ok;
}
bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
{
outVal = !val.is_boolean() ? false : val.as_bool();
return val.is_boolean();
}
bool ModelBase::fromJson( const web::json::value& val, float & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double();
}
bool ModelBase::fromJson( const web::json::value& val, double & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() ;
}
bool ModelBase::fromJson( const web::json::value& val, int32_t & outVal )
{
outVal = !val.is_integer() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
return val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, int64_t & outVal )
{
outVal = !val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
return val.is_number();
}
bool ModelBase::fromJson( const web::json::value& val, utility::string_t & outVal )
{
outVal = val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
return val.is_string();
}
bool ModelBase::fromJson( const web::json::value& val, utility::datetime & outVal )
{
outVal = val.is_null() ? utility::datetime::from_string(utility::conversions::to_string_t("NULL"), utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
return outVal.is_initialized();
}
bool ModelBase::fromJson( const web::json::value& val, web::json::value & outVal )
{
outVal = val;
return !val.is_null();
}
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpContent>& content )
{
bool result = false;
if( content != nullptr)
{
result = true;
if(content == nullptr)
{
content = std::shared_ptr<HttpContent>(new HttpContent());
}
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentDisposition")), value);
content->setContentDisposition( value );
}
if(val.has_field(utility::conversions::to_string_t("ContentType")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentType")), value);
content->setContentType( value );
}
if(val.has_field(utility::conversions::to_string_t("FileName")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("FileName")), value);
content->setFileName( value );
}
if(val.has_field(utility::conversions::to_string_t("InputStream")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("InputStream")), value);
content->setData( ModelBase::fromBase64( value ) );
}
}
return result;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( value->getContentDisposition() );
content->setContentType( value->getContentType() );
content->setData( value->getData() );
content->setFileName( value->getFileName() );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType )
@ -134,18 +365,118 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
content->setData( std::shared_ptr<std::istream>( valueAsStringStream) ) ;
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
{
std::shared_ptr<HttpContent> content(new HttpContent);
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& value )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if( value != nullptr )
{
content->setName( name );
content->setContentDisposition( value->getContentDisposition() );
content->setContentType( value->getContentType() );
content->setData( value->getData() );
content->setFileName( value->getFileName() );
}
return content;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, bool & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, float & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, double & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int32_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int64_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::string_t & outVal )
{
if( val == nullptr ) return false;
std::shared_ptr<std::istream> data = val->getData();
data->seekg( 0, data->beg );
std::string str((std::istreambuf_iterator<char>(*data.get())),
std::istreambuf_iterator<char>());
outVal = utility::conversions::to_string_t(str);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::datetime & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
outVal = utility::datetime::from_string(str, utility::datetime::ISO_8601);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, web::json::value & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
if( outVal == nullptr )
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
// base64 encoding/decoding based on : https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C.2B.2B
const static char Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const static char Base64PadChar = '=';
@ -195,8 +526,6 @@ utility::string_t ModelBase::toBase64( std::shared_ptr<std::istream> value )
}
return base64;
}
std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& encoded )
{
std::shared_ptr<std::stringstream> result(new std::stringstream);
@ -263,107 +592,6 @@ std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& en
return result;
}
int64_t ModelBase::int64_tFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
}
int32_t ModelBase::int32_tFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
}
float ModelBase::floatFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<float>::quiet_NaN() : static_cast<float>(val.as_double());
}
utility::string_t ModelBase::stringFromJson(const web::json::value& val)
{
return val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
}
utility::datetime ModelBase::dateFromJson(const web::json::value& val)
{
return val.is_null() ? utility::datetime::from_string(utility::conversions::to_string_t("NULL"), utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
}
bool ModelBase::boolFromJson(const web::json::value& val)
{
return val.is_null() ? false : val.as_bool();
}
double ModelBase::doubleFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
}
int64_t ModelBase::int64_tFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
int64_t result = 0;
ss >> result;
return result;
}
int32_t ModelBase::int32_tFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
int32_t result = 0;
ss >> result;
return result;
}
float ModelBase::floatFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
float result = 0;
ss >> result;
return result;
}
utility::string_t ModelBase::stringFromHttpContent(std::shared_ptr<HttpContent> val)
{
std::shared_ptr<std::istream> data = val->getData();
data->seekg( 0, data->beg );
std::string str((std::istreambuf_iterator<char>(*data.get())),
std::istreambuf_iterator<char>());
return utility::conversions::to_string_t(str);
}
utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
return utility::datetime::from_string(str, utility::datetime::ISO_8601);
}
bool ModelBase::boolFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
bool result = false;
ss >> result;
return result;
}
double ModelBase::doubleFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
double result = 0.0;
ss >> result;
return result;
}
web::json::value ModelBase::valueFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
return web::json::value::parse(str);
}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}

View File

@ -85,7 +85,7 @@ void MultipartFormData::writeTo( std::ostream& target )
data->seekg( 0, data->end );
std::vector<char> dataBytes( data->tellg() );
data->seekg( 0, data->beg );
data->read( &dataBytes[0], dataBytes.size() );

View File

@ -29,10 +29,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Object manipulation

View File

@ -16,7 +16,7 @@ Object::~Object()
void Object::validate()
{
// TODO: implement validation
}
web::json::value Object::toJson() const
@ -24,12 +24,14 @@ web::json::value Object::toJson() const
return m_object;
}
void Object::fromJson(const web::json::value& val)
bool Object::fromJson(const web::json::value& val)
{
if (val.is_object())
{
m_object = val;
m_IsSet = true;
}
return isSet();
}
void Object::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -42,7 +44,7 @@ void Object::toMultipart(std::shared_ptr<MultipartFormData> multipart, const uti
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("object"), m_object));
}
void Object::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Object::fromMultiPart(std::shared_ptr<MultipartFormData> 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("."))
@ -50,7 +52,11 @@ void Object::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const u
namePrefix += utility::conversions::to_string_t(".");
}
m_object = ModelBase::valueFromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object")));
if( ModelBase::fromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object")), m_object ) )
{
m_IsSet = true;
}
return isSet();
}
web::json::value Object::getValue(const utility::string_t& key) const
@ -61,7 +67,11 @@ web::json::value Object::getValue(const utility::string_t& key) const
void Object::setValue(const utility::string_t& key, const web::json::value& value)
{
m_object[key] = value;
if( !value.is_null() )
{
m_object[key] = value;
m_IsSet = true;
}
}
{{#modelNamespaceDeclarations}}

View File

@ -24,7 +24,7 @@ HttpContent::~HttpContent()
{
}
utility::string_t HttpContent::getContentDisposition()
utility::string_t HttpContent::getContentDisposition() const
{
return m_ContentDisposition;
}
@ -34,7 +34,7 @@ void HttpContent::setContentDisposition( const utility::string_t & value )
m_ContentDisposition = value;
}
utility::string_t HttpContent::getName()
utility::string_t HttpContent::getName() const
{
return m_Name;
}
@ -44,7 +44,7 @@ void HttpContent::setName( const utility::string_t & value )
m_Name = value;
}
utility::string_t HttpContent::getFileName()
utility::string_t HttpContent::getFileName() const
{
return m_FileName;
}
@ -54,7 +54,7 @@ void HttpContent::setFileName( const utility::string_t & value )
m_FileName = value;
}
utility::string_t HttpContent::getContentType()
utility::string_t HttpContent::getContentType() const
{
return m_ContentType;
}
@ -64,7 +64,7 @@ void HttpContent::setContentType( const utility::string_t & value )
m_ContentType = value;
}
std::shared_ptr<std::istream> HttpContent::getData()
std::shared_ptr<std::istream> HttpContent::getData() const
{
return m_Data;
}

View File

@ -35,19 +35,19 @@ public:
HttpContent();
virtual ~HttpContent();
virtual utility::string_t getContentDisposition();
virtual utility::string_t getContentDisposition() const;
virtual void setContentDisposition( const utility::string_t& value );
virtual utility::string_t getName();
virtual utility::string_t getName() const;
virtual void setName( const utility::string_t& value );
virtual utility::string_t getFileName();
virtual utility::string_t getFileName() const;
virtual void setFileName( const utility::string_t& value );
virtual utility::string_t getContentType();
virtual utility::string_t getContentType() const;
virtual void setContentType( const utility::string_t& value );
virtual std::shared_ptr<std::istream> getData();
virtual std::shared_ptr<std::istream> getData() const;
virtual void setData( std::shared_ptr<std::istream> value );
virtual void writeTo( std::ostream& stream );

View File

@ -16,20 +16,80 @@ namespace openapitools {
namespace client {
namespace model {
ModelBase::ModelBase()
ModelBase::ModelBase(): m_IsSet(false)
{
}
ModelBase::~ModelBase()
{
}
web::json::value ModelBase::toJson( const utility::string_t& value )
bool ModelBase::isSet() const
{
return web::json::value::string(value);
return m_IsSet;
}
web::json::value ModelBase::toJson( const utility::datetime& value )
utility::string_t ModelBase::toString( const bool val )
{
return web::json::value::string(value.to_string(utility::datetime::ISO_8601));
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const float val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const double val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int32_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int64_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString (const utility::string_t &val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const utility::datetime &val )
{
return val.to_string(utility::datetime::ISO_8601);
}
utility::string_t ModelBase::toString( const web::json::value &val )
{
return val.serialize();
}
utility::string_t ModelBase::toString( const std::shared_ptr<HttpContent>& val )
{
utility::stringstream_t ss;
if( val != nullptr )
{
ss << val->getData();
}
return utility::string_t(ss.str());
}
web::json::value ModelBase::toJson(bool value)
{
return web::json::value::boolean(value);
}
web::json::value ModelBase::toJson( float value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( double value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( int32_t value )
{
@ -39,88 +99,259 @@ web::json::value ModelBase::toJson( int64_t value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( double value )
web::json::value ModelBase::toJson( const utility::string_t& value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson(bool value) {
return web::json::value::boolean(value);
return web::json::value::string(value);
}
web::json::value ModelBase::toJson( std::shared_ptr<HttpContent> content )
web::json::value ModelBase::toJson( const utility::datetime& value )
{
return web::json::value::string(value.to_string(utility::datetime::ISO_8601));
}
web::json::value ModelBase::toJson( const web::json::value& value )
{
web::json::value value;
value[utility::conversions::to_string_t("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition());
value[utility::conversions::to_string_t("ContentType")] = ModelBase::toJson(content->getContentType());
value[utility::conversions::to_string_t("FileName")] = ModelBase::toJson(content->getFileName());
value[utility::conversions::to_string_t("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) );
return value;
}
std::shared_ptr<HttpContent> ModelBase::fileFromJson(const web::json::value& val)
web::json::value ModelBase::toJson( const std::shared_ptr<HttpContent>& content )
{
std::shared_ptr<HttpContent> content(new HttpContent);
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
web::json::value value;
if(content != nullptr)
{
content->setContentDisposition( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("ContentDisposition"))) );
value[utility::conversions::to_string_t("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition());
value[utility::conversions::to_string_t("ContentType")] = ModelBase::toJson(content->getContentType());
value[utility::conversions::to_string_t("FileName")] = ModelBase::toJson(content->getFileName());
value[utility::conversions::to_string_t("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) );
}
if(val.has_field(utility::conversions::to_string_t("ContentType")))
{
content->setContentType( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("ContentType"))) );
}
if(val.has_field(utility::conversions::to_string_t("FileName")))
{
content->setFileName( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("FileName"))) );
}
if(val.has_field(utility::conversions::to_string_t("InputStream")))
{
content->setData( ModelBase::fromBase64( ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("InputStream")))) );
}
return content;
return value;
}
web::json::value ModelBase::toJson( std::shared_ptr<ModelBase> content )
bool ModelBase::fromString( const utility::string_t& val, bool &outVal )
{
return content.get() ? content->toJson() : web::json::value::null();
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
bool ModelBase::fromString( const utility::string_t& val, float &outVal )
{
std::shared_ptr<HttpContent> content(new HttpContent);
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
return content;
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
bool ModelBase::fromString( const utility::string_t& val, double &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int32_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int64_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::string_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::datetime &outVal )
{
bool success = true;
auto dt = utility::datetime::from_string(val, utility::datetime::ISO_8601);
if( dt.is_initialized() )
{
outVal = dt;
}
else
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, web::json::value &outVal )
{
outVal = web::json::value::parse(val);
return !outVal.is_null();
}
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<HttpContent>& outVal )
{
bool ok = true;
if(outVal == nullptr)
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
std::shared_ptr<utility::stringstream_t> ssptr = std::make_shared<utility::stringstream_t>(val);
if(outVal != nullptr)
{
outVal->setData(ssptr);
}
else
{
ok = false;
}
return ok;
}
bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
{
outVal = !val.is_boolean() ? false : val.as_bool();
return val.is_boolean();
}
bool ModelBase::fromJson( const web::json::value& val, float & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double();
}
bool ModelBase::fromJson( const web::json::value& val, double & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() ;
}
bool ModelBase::fromJson( const web::json::value& val, int32_t & outVal )
{
outVal = !val.is_integer() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
return val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, int64_t & outVal )
{
outVal = !val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
return val.is_number();
}
bool ModelBase::fromJson( const web::json::value& val, utility::string_t & outVal )
{
outVal = val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
return val.is_string();
}
bool ModelBase::fromJson( const web::json::value& val, utility::datetime & outVal )
{
outVal = val.is_null() ? utility::datetime::from_string(utility::conversions::to_string_t("NULL"), utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
return outVal.is_initialized();
}
bool ModelBase::fromJson( const web::json::value& val, web::json::value & outVal )
{
outVal = val;
return !val.is_null();
}
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpContent>& content )
{
bool result = false;
if( content != nullptr)
{
result = true;
if(content == nullptr)
{
content = std::shared_ptr<HttpContent>(new HttpContent());
}
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentDisposition")), value);
content->setContentDisposition( value );
}
if(val.has_field(utility::conversions::to_string_t("ContentType")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentType")), value);
content->setContentType( value );
}
if(val.has_field(utility::conversions::to_string_t("FileName")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("FileName")), value);
content->setFileName( value );
}
if(val.has_field(utility::conversions::to_string_t("InputStream")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("InputStream")), value);
content->setData( ModelBase::fromBase64( value ) );
}
}
return result;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( value->getContentDisposition() );
content->setContentType( value->getContentType() );
content->setData( value->getData() );
content->setFileName( value->getFileName() );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType )
@ -145,18 +376,118 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
content->setData( std::shared_ptr<std::istream>( valueAsStringStream) ) ;
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
{
std::shared_ptr<HttpContent> content(new HttpContent);
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& value )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if( value != nullptr )
{
content->setName( name );
content->setContentDisposition( value->getContentDisposition() );
content->setContentType( value->getContentType() );
content->setData( value->getData() );
content->setFileName( value->getFileName() );
}
return content;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, bool & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, float & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, double & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int32_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int64_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::string_t & outVal )
{
if( val == nullptr ) return false;
std::shared_ptr<std::istream> data = val->getData();
data->seekg( 0, data->beg );
std::string str((std::istreambuf_iterator<char>(*data.get())),
std::istreambuf_iterator<char>());
outVal = utility::conversions::to_string_t(str);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::datetime & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
outVal = utility::datetime::from_string(str, utility::datetime::ISO_8601);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, web::json::value & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
if( outVal == nullptr )
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
// base64 encoding/decoding based on : https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C.2B.2B
const static char Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const static char Base64PadChar = '=';
@ -206,8 +537,6 @@ utility::string_t ModelBase::toBase64( std::shared_ptr<std::istream> value )
}
return base64;
}
std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& encoded )
{
std::shared_ptr<std::stringstream> result(new std::stringstream);
@ -274,107 +603,6 @@ std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& en
return result;
}
int64_t ModelBase::int64_tFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
}
int32_t ModelBase::int32_tFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
}
float ModelBase::floatFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<float>::quiet_NaN() : static_cast<float>(val.as_double());
}
utility::string_t ModelBase::stringFromJson(const web::json::value& val)
{
return val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
}
utility::datetime ModelBase::dateFromJson(const web::json::value& val)
{
return val.is_null() ? utility::datetime::from_string(utility::conversions::to_string_t("NULL"), utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
}
bool ModelBase::boolFromJson(const web::json::value& val)
{
return val.is_null() ? false : val.as_bool();
}
double ModelBase::doubleFromJson(const web::json::value& val)
{
return val.is_null() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
}
int64_t ModelBase::int64_tFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
int64_t result = 0;
ss >> result;
return result;
}
int32_t ModelBase::int32_tFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
int32_t result = 0;
ss >> result;
return result;
}
float ModelBase::floatFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
float result = 0;
ss >> result;
return result;
}
utility::string_t ModelBase::stringFromHttpContent(std::shared_ptr<HttpContent> val)
{
std::shared_ptr<std::istream> data = val->getData();
data->seekg( 0, data->beg );
std::string str((std::istreambuf_iterator<char>(*data.get())),
std::istreambuf_iterator<char>());
return utility::conversions::to_string_t(str);
}
utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
return utility::datetime::from_string(str, utility::datetime::ISO_8601);
}
bool ModelBase::boolFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
bool result = false;
ss >> result;
return result;
}
double ModelBase::doubleFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
utility::stringstream_t ss(str);
double result = 0.0;
ss >> result;
return result;
}
web::json::value ModelBase::valueFromHttpContent(std::shared_ptr<HttpContent> val)
{
utility::string_t str = ModelBase::stringFromHttpContent(val);
return web::json::value::parse(str);
}
}
}
}

View File

@ -19,14 +19,15 @@
#define ORG_OPENAPITOOLS_CLIENT_MODEL_ModelBase_H_
#include <map>
#include <vector>
#include "HttpContent.h"
#include "MultipartFormData.h"
#include <cpprest/details/basic_types.h>
#include <cpprest/json.h>
#include <vector>
namespace org {
namespace openapitools {
namespace client {
@ -41,68 +42,252 @@ public:
virtual void validate() = 0;
virtual web::json::value toJson() const = 0;
virtual void fromJson(const web::json::value& json) = 0;
virtual bool fromJson( const web::json::value& json ) = 0;
virtual void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const = 0;
virtual void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) = 0;
virtual void toMultipart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) const = 0;
virtual bool fromMultiPart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) = 0;
static web::json::value toJson( const utility::string_t& value );
static web::json::value toJson( const utility::datetime& value );
static web::json::value toJson( std::shared_ptr<HttpContent> value );
static web::json::value toJson( std::shared_ptr<ModelBase> value );
static web::json::value toJson( int32_t value );
static web::json::value toJson( int64_t value );
static web::json::value toJson( double value );
static web::json::value toJson( bool value );
template<class T>
static web::json::value toJson(const std::vector<T>& value);
virtual bool isSet() const;
static int64_t int64_tFromJson(const web::json::value& val);
static int32_t int32_tFromJson(const web::json::value& val);
static float floatFromJson(const web::json::value& val);
static utility::string_t stringFromJson(const web::json::value& val);
static utility::datetime dateFromJson(const web::json::value& val);
static double doubleFromJson(const web::json::value& val);
static bool boolFromJson(const web::json::value& val);
static std::shared_ptr<HttpContent> fileFromJson(const web::json::value& val);
static utility::string_t toString( const bool val );
static utility::string_t toString( const float val );
static utility::string_t toString( const double val );
static utility::string_t toString( const int32_t val );
static utility::string_t toString( const int64_t val );
static utility::string_t toString( const utility::string_t &val );
static utility::string_t toString( const utility::datetime &val );
static utility::string_t toString( const web::json::value &val );
static utility::string_t toString( const std::shared_ptr<HttpContent>& val );
template <typename T>
static utility::string_t toString( const std::shared_ptr<T>& val );
template <typename T>
static utility::string_t toString( const std::vector<T> & val );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
static web::json::value toJson( bool val );
static web::json::value toJson( float val );
static web::json::value toJson( double val );
static web::json::value toJson( int32_t val );
static web::json::value toJson( int64_t val );
static web::json::value toJson( const utility::string_t& val );
static web::json::value toJson( const utility::datetime& val );
static web::json::value toJson( const web::json::value& val );
static web::json::value toJson( const std::shared_ptr<HttpContent>& val );
template<typename T>
static web::json::value toJson( const std::shared_ptr<T>& val );
template<typename T>
static web::json::value toJson( const std::vector<T>& val );
template<typename T>
static web::json::value toJson( const std::map<utility::string_t, T>& val );
static bool fromString( const utility::string_t& val, bool & );
static bool fromString( const utility::string_t& val, float & );
static bool fromString( const utility::string_t& val, double & );
static bool fromString( const utility::string_t& val, int32_t & );
static bool fromString( const utility::string_t& val, int64_t & );
static bool fromString( const utility::string_t& val, utility::string_t & );
static bool fromString( const utility::string_t& val, utility::datetime & );
static bool fromString( const utility::string_t& val, web::json::value & );
static bool fromString( const utility::string_t& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::shared_ptr<T>& );
template<typename T>
static bool fromString( const utility::string_t& val, std::vector<T> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::map<utility::string_t, T> & );
static bool fromJson( const web::json::value& val, bool & );
static bool fromJson( const web::json::value& val, float & );
static bool fromJson( const web::json::value& val, double & );
static bool fromJson( const web::json::value& val, int32_t & );
static bool fromJson( const web::json::value& val, int64_t & );
static bool fromJson( const web::json::value& val, utility::string_t & );
static bool fromJson( const web::json::value& val, utility::datetime & );
static bool fromJson( const web::json::value& val, web::json::value & );
static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
template<typename T>
static bool fromJson( const web::json::value& val, std::vector<T> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::map<utility::string_t, T> & );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <class T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<T>& , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
static int64_t int64_tFromHttpContent(std::shared_ptr<HttpContent> val);
static int32_t int32_tFromHttpContent(std::shared_ptr<HttpContent> val);
static float floatFromHttpContent(std::shared_ptr<HttpContent> val);
static utility::string_t stringFromHttpContent(std::shared_ptr<HttpContent> val);
static utility::datetime dateFromHttpContent(std::shared_ptr<HttpContent> val);
static bool boolFromHttpContent(std::shared_ptr<HttpContent> val);
static double doubleFromHttpContent(std::shared_ptr<HttpContent> val);
static web::json::value valueFromHttpContent(std::shared_ptr<HttpContent> val);
static bool fromHttpContent( std::shared_ptr<HttpContent> val, bool & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, float & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, double & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, int64_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, int32_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::string_t & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::datetime & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, web::json::value & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & );
static utility::string_t toBase64( utility::string_t value );
static utility::string_t toBase64( std::shared_ptr<std::istream> value );
static std::shared_ptr<std::istream> fromBase64( const utility::string_t& encoded );
protected:
bool m_IsSet;
};
template<class T>
web::json::value ModelBase::toJson(const std::vector<T>& value) {
std::vector<web::json::value> ret;
for (auto& x : value) {
ret.push_back(toJson(x));
template <typename T>
utility::string_t ModelBase::toString( const std::shared_ptr<T>& val )
{
utility::stringstream_t ss;
if( val != nullptr )
{
val->toJson().serialize(ss);
}
return utility::string_t(ss.str());
}
template<typename T>
utility::string_t ModelBase::toString( const std::vector<T> & val )
{
utility::string_t strArray;
for ( const auto &item : val )
{
strArray.append( toString(item) + "," );
}
if (val.count() > 0)
{
strArray.pop_back();
}
return strArray;
}
template<typename T>
web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
{
web::json::value retVal;
if(val != nullptr)
{
retVal = val->toJson();
}
return retVal;
}
template<typename T>
web::json::value ModelBase::toJson( const std::vector<T>& value )
{
std::vector<web::json::value> ret;
for ( const auto& x : value )
{
ret.push_back( toJson(x) );
}
return web::json::value::array(ret);
}
template <class T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType ) {
template<typename T>
web::json::value ModelBase::toJson( const std::map<utility::string_t, T>& val )
{
web::json::value obj;
for ( const auto &itemkey : val )
{
obj[itemkey.first] = toJson( itemkey.second );
}
return obj;
}
template<typename T>
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<T>& outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<T>(new T());
}
if( outVal != nullptr )
{
ok = outVal->fromJson(web::json::value::parse(val));
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<T> &outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<T>(new T());
}
if( outVal != nullptr )
{
ok = outVal->fromJson(val);
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& val, std::vector<T> &outVal )
{
bool ok = true;
if (val.is_array())
{
for (const auto jitem : val.as_array())
{
T item;
ok &= fromJson(jitem, item);
outVal.push_back(item);
}
}
else
{
ok = false;
}
return ok;
}
template<typename T>
bool ModelBase::fromJson( const web::json::value& jval, std::map<utility::string_t, T> &outVal )
{
bool ok = true;
if ( jval.is_object() )
{
auto obj = jval.as_object();
for( auto objItr = obj.begin() ; objItr != obj.end() ; objItr++ )
{
T itemVal;
ok &= fromJson(objItr->second, itemVal);
outVal.insert(std::pair<utility::string_t, T>(objItr->first, itemVal));
}
}
else
{
ok = false;
}
return ok;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<T>& value , const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if (value != nullptr )
{
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) );
}
return content;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
{
web::json::value json_array = ModelBase::toJson(value);
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
@ -111,7 +296,39 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
return content;
}
template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
{
web::json::value jobj = ModelBase::toJson(value);
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) );
return content;
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& outVal )
{
utility::string_t str;
if(val == nullptr) return false;
if( outVal == nullptr )
{
outVal = std::shared_ptr<T>(new T());
}
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & )
{
return true;
}
template <typename T>
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & )
{
return true;
}
}
}
}

View File

@ -96,7 +96,7 @@ void MultipartFormData::writeTo( std::ostream& target )
data->seekg( 0, data->end );
std::vector<char> dataBytes( data->tellg() );
data->seekg( 0, data->beg );
data->read( &dataBytes[0], dataBytes.size() );

View File

@ -27,7 +27,7 @@ Object::~Object()
void Object::validate()
{
// TODO: implement validation
}
web::json::value Object::toJson() const
@ -35,12 +35,14 @@ web::json::value Object::toJson() const
return m_object;
}
void Object::fromJson(const web::json::value& val)
bool Object::fromJson(const web::json::value& val)
{
if (val.is_object())
{
m_object = val;
m_IsSet = true;
}
return isSet();
}
void Object::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -53,7 +55,7 @@ void Object::toMultipart(std::shared_ptr<MultipartFormData> multipart, const uti
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("object"), m_object));
}
void Object::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Object::fromMultiPart(std::shared_ptr<MultipartFormData> 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("."))
@ -61,7 +63,11 @@ void Object::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const u
namePrefix += utility::conversions::to_string_t(".");
}
m_object = ModelBase::valueFromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object")));
if( ModelBase::fromHttpContent(multipart->getContent(namePrefix + utility::conversions::to_string_t("object")), m_object ) )
{
m_IsSet = true;
}
return isSet();
}
web::json::value Object::getValue(const utility::string_t& key) const
@ -72,7 +78,11 @@ web::json::value Object::getValue(const utility::string_t& key) const
void Object::setValue(const utility::string_t& key, const web::json::value& value)
{
m_object[key] = value;
if( !value.is_null() )
{
m_object[key] = value;
m_IsSet = true;
}
}
}

View File

@ -40,10 +40,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Object manipulation

View File

@ -36,10 +36,10 @@ make
- Once visual studio opens, CMake should show up in top menu bar.
- Select CMake > Build All.
*Note: If the CMake menu item doesn't show up in Visual Studio, CMake
for Visual Studio must be installed. In this case, open the 'Visual Studio
Installer' application. Select 'modify' Visual Studio 2017. Make sure
'Desktop Development with C++' is installed, and specifically that 'Visual
*Note: If the CMake menu item doesn't show up in Visual Studio, CMake
for Visual Studio must be installed. In this case, open the 'Visual Studio
Installer' application. Select 'modify' Visual Studio 2017. Make sure
'Desktop Development with C++' is installed, and specifically that 'Visual
C++ tools for CMake' is selected in the 'Installation Details' section.
Also be sure to review the CMakeLists.txt file. Edits are likely required.*

View File

@ -108,6 +108,7 @@ pplx::task<void> PetApi::addPet(std::shared_ptr<Pet> body) const
{
body->toMultipart(localVarMultipart, utility::conversions::to_string_t("body"));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
@ -373,15 +374,12 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByStatus(std::vect
if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
for( auto& localVarItem : localVarJson.as_array() )
{
std::shared_ptr<Pet> localVarItemObj(new Pet());
localVarItemObj->fromJson(localVarItem);
std::shared_ptr<Pet> localVarItemObj;
ModelBase::fromJson(localVarItem, localVarItemObj);
localVarResult.push_back(localVarItemObj);
}
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -504,15 +502,12 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByTags(std::vector
if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
for( auto& localVarItem : localVarJson.as_array() )
{
std::shared_ptr<Pet> localVarItemObj(new Pet());
localVarItemObj->fromJson(localVarItem);
std::shared_ptr<Pet> localVarItemObj;
ModelBase::fromJson(localVarItem, localVarItemObj);
localVarResult.push_back(localVarItemObj);
}
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -640,7 +635,7 @@ pplx::task<std::shared_ptr<Pet>> PetApi::getPetById(int64_t petId) const
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult->fromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -728,6 +723,7 @@ pplx::task<void> PetApi::updatePet(std::shared_ptr<Pet> body) const
{
body->toMultipart(localVarMultipart, utility::conversions::to_string_t("body"));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
@ -1005,7 +1001,7 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult->fromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {

View File

@ -248,10 +248,10 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory() const
for( auto& localVarItem : localVarJson.as_object() )
{
localVarResult[localVarItem.first] = ModelBase::int32_tFromJson(localVarItem.second);
int32_t localVarItemObj;
ModelBase::fromJson(localVarItem.second, localVarItemObj);
localVarResult[localVarItem.first] = localVarItemObj;
}
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -371,7 +371,7 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId) const
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult->fromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -459,6 +459,7 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
{
body->toMultipart(localVarMultipart, utility::conversions::to_string_t("body"));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
@ -511,7 +512,7 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult->fromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {

View File

@ -106,6 +106,7 @@ pplx::task<void> UserApi::createUser(std::shared_ptr<User> body) const
{
body->toMultipart(localVarMultipart, utility::conversions::to_string_t("body"));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
@ -222,16 +223,17 @@ pplx::task<void> UserApi::createUsersWithArrayInput(std::vector<std::shared_ptr<
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);
{
std::vector<web::json::value> localVarJsonArray;
for( auto& localVarItem : body )
{
localVarJsonArray.push_back( localVarItem.get() ? localVarItem->toJson() : web::json::value::null() );
localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("body"), web::json::value::array(localVarJsonArray), utility::conversions::to_string_t("application/json")));
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("body"), localVarJsonArray, utility::conversions::to_string_t("application/json")));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
@ -347,16 +349,17 @@ pplx::task<void> UserApi::createUsersWithListInput(std::vector<std::shared_ptr<U
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);
{
std::vector<web::json::value> localVarJsonArray;
for( auto& localVarItem : body )
{
localVarJsonArray.push_back( localVarItem.get() ? localVarItem->toJson() : web::json::value::null() );
localVarJsonArray.push_back(ModelBase::toJson(localVarItem));
}
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("body"), web::json::value::array(localVarJsonArray), utility::conversions::to_string_t("application/json")));
localVarMultipart->add(ModelBase::toHttpContent(utility::conversions::to_string_t("body"), localVarJsonArray, utility::conversions::to_string_t("application/json")));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
@ -610,7 +613,7 @@ pplx::task<std::shared_ptr<User>> UserApi::getUserByName(utility::string_t usern
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult->fromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
@ -740,8 +743,7 @@ pplx::task<utility::string_t> UserApi::loginUser(utility::string_t username, uti
{
web::json::value localVarJson = web::json::value::parse(localVarResponse);
localVarResult = ModelBase::stringFromJson(localVarJson);
ModelBase::fromJson(localVarJson, localVarResult);
}
else if(localVarResponseHttpContentType == utility::conversions::to_string_t("text/plain"))
{
@ -931,6 +933,7 @@ pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr
{
body->toMultipart(localVarMultipart, utility::conversions::to_string_t("body"));
}
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();

View File

@ -42,8 +42,9 @@ void ApiResponse::validate()
web::json::value ApiResponse::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_CodeIsSet)
{
val[utility::conversions::to_string_t("code")] = ModelBase::toJson(m_Code);
@ -60,14 +61,18 @@ web::json::value ApiResponse::toJson() const
return val;
}
void ApiResponse::fromJson(const web::json::value& val)
bool ApiResponse::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("code")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("code"));
if(!fieldValue.is_null())
{
setCode(ModelBase::int32_tFromJson(fieldValue));
int32_t refVal_code;
ok &= ModelBase::fromJson(fieldValue, refVal_code);
setCode(refVal_code);
}
}
if(val.has_field(utility::conversions::to_string_t("type")))
@ -75,7 +80,9 @@ void ApiResponse::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("type"));
if(!fieldValue.is_null())
{
setType(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_type;
ok &= ModelBase::fromJson(fieldValue, refVal_type);
setType(refVal_type);
}
}
if(val.has_field(utility::conversions::to_string_t("message")))
@ -83,9 +90,12 @@ void ApiResponse::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("message"));
if(!fieldValue.is_null())
{
setMessage(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_message;
ok &= ModelBase::fromJson(fieldValue, refVal_message);
setMessage(refVal_message);
}
}
return ok;
}
void ApiResponse::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -95,7 +105,6 @@ void ApiResponse::toMultipart(std::shared_ptr<MultipartFormData> multipart, cons
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_CodeIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("code"), m_Code));
@ -110,8 +119,9 @@ void ApiResponse::toMultipart(std::shared_ptr<MultipartFormData> multipart, cons
}
}
void ApiResponse::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool ApiResponse::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -120,16 +130,23 @@ void ApiResponse::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, co
if(multipart->hasContent(utility::conversions::to_string_t("code")))
{
setCode(ModelBase::int32_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("code"))));
int32_t refVal_code;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("code")), refVal_code );
setCode(refVal_code);
}
if(multipart->hasContent(utility::conversions::to_string_t("type")))
{
setType(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("type"))));
utility::string_t refVal_type;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("type")), refVal_type );
setType(refVal_type);
}
if(multipart->hasContent(utility::conversions::to_string_t("message")))
{
setMessage(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("message"))));
utility::string_t refVal_message;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("message")), refVal_message );
setMessage(refVal_message);
}
return ok;
}
int32_t ApiResponse::getCode() const
@ -152,7 +169,6 @@ void ApiResponse::unsetCode()
{
m_CodeIsSet = false;
}
utility::string_t ApiResponse::getType() const
{
return m_Type;
@ -173,7 +189,6 @@ void ApiResponse::unsetType()
{
m_TypeIsSet = false;
}
utility::string_t ApiResponse::getMessage() const
{
return m_Message;
@ -194,7 +209,6 @@ void ApiResponse::unsetMessage()
{
m_MessageIsSet = false;
}
}
}
}

View File

@ -45,10 +45,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// ApiResponse members

View File

@ -40,8 +40,9 @@ void Category::validate()
web::json::value Category::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_IdIsSet)
{
val[utility::conversions::to_string_t("id")] = ModelBase::toJson(m_Id);
@ -54,14 +55,18 @@ web::json::value Category::toJson() const
return val;
}
void Category::fromJson(const web::json::value& val)
bool Category::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("id")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("id"));
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_id;
ok &= ModelBase::fromJson(fieldValue, refVal_id);
setId(refVal_id);
}
}
if(val.has_field(utility::conversions::to_string_t("name")))
@ -69,9 +74,12 @@ void Category::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("name"));
if(!fieldValue.is_null())
{
setName(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_name;
ok &= ModelBase::fromJson(fieldValue, refVal_name);
setName(refVal_name);
}
}
return ok;
}
void Category::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -81,7 +89,6 @@ void Category::toMultipart(std::shared_ptr<MultipartFormData> multipart, const u
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_IdIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("id"), m_Id));
@ -92,8 +99,9 @@ void Category::toMultipart(std::shared_ptr<MultipartFormData> multipart, const u
}
}
void Category::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Category::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -102,12 +110,17 @@ void Category::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const
if(multipart->hasContent(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("id"))));
int64_t refVal_id;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("id")), refVal_id );
setId(refVal_id);
}
if(multipart->hasContent(utility::conversions::to_string_t("name")))
{
setName(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("name"))));
utility::string_t refVal_name;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("name")), refVal_name );
setName(refVal_name);
}
return ok;
}
int64_t Category::getId() const
@ -130,7 +143,6 @@ void Category::unsetId()
{
m_IdIsSet = false;
}
utility::string_t Category::getName() const
{
return m_Name;
@ -151,7 +163,6 @@ void Category::unsetName()
{
m_NameIsSet = false;
}
}
}
}

View File

@ -45,10 +45,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Category members

View File

@ -48,8 +48,9 @@ void Order::validate()
web::json::value Order::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_IdIsSet)
{
val[utility::conversions::to_string_t("id")] = ModelBase::toJson(m_Id);
@ -78,14 +79,18 @@ web::json::value Order::toJson() const
return val;
}
void Order::fromJson(const web::json::value& val)
bool Order::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("id")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("id"));
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_id;
ok &= ModelBase::fromJson(fieldValue, refVal_id);
setId(refVal_id);
}
}
if(val.has_field(utility::conversions::to_string_t("petId")))
@ -93,7 +98,9 @@ void Order::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("petId"));
if(!fieldValue.is_null())
{
setPetId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_petId;
ok &= ModelBase::fromJson(fieldValue, refVal_petId);
setPetId(refVal_petId);
}
}
if(val.has_field(utility::conversions::to_string_t("quantity")))
@ -101,7 +108,9 @@ void Order::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("quantity"));
if(!fieldValue.is_null())
{
setQuantity(ModelBase::int32_tFromJson(fieldValue));
int32_t refVal_quantity;
ok &= ModelBase::fromJson(fieldValue, refVal_quantity);
setQuantity(refVal_quantity);
}
}
if(val.has_field(utility::conversions::to_string_t("shipDate")))
@ -109,7 +118,9 @@ void Order::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("shipDate"));
if(!fieldValue.is_null())
{
setShipDate(ModelBase::dateFromJson(fieldValue));
utility::datetime refVal_shipDate;
ok &= ModelBase::fromJson(fieldValue, refVal_shipDate);
setShipDate(refVal_shipDate);
}
}
if(val.has_field(utility::conversions::to_string_t("status")))
@ -117,7 +128,9 @@ void Order::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("status"));
if(!fieldValue.is_null())
{
setStatus(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_status;
ok &= ModelBase::fromJson(fieldValue, refVal_status);
setStatus(refVal_status);
}
}
if(val.has_field(utility::conversions::to_string_t("complete")))
@ -125,9 +138,12 @@ void Order::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("complete"));
if(!fieldValue.is_null())
{
setComplete(ModelBase::boolFromJson(fieldValue));
bool refVal_complete;
ok &= ModelBase::fromJson(fieldValue, refVal_complete);
setComplete(refVal_complete);
}
}
return ok;
}
void Order::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -137,7 +153,6 @@ void Order::toMultipart(std::shared_ptr<MultipartFormData> multipart, const util
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_IdIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("id"), m_Id));
@ -164,8 +179,9 @@ void Order::toMultipart(std::shared_ptr<MultipartFormData> multipart, const util
}
}
void Order::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Order::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -174,28 +190,41 @@ void Order::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const ut
if(multipart->hasContent(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("id"))));
int64_t refVal_id;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("id")), refVal_id );
setId(refVal_id);
}
if(multipart->hasContent(utility::conversions::to_string_t("petId")))
{
setPetId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("petId"))));
int64_t refVal_petId;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("petId")), refVal_petId );
setPetId(refVal_petId);
}
if(multipart->hasContent(utility::conversions::to_string_t("quantity")))
{
setQuantity(ModelBase::int32_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("quantity"))));
int32_t refVal_quantity;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("quantity")), refVal_quantity );
setQuantity(refVal_quantity);
}
if(multipart->hasContent(utility::conversions::to_string_t("shipDate")))
{
setShipDate(ModelBase::dateFromHttpContent(multipart->getContent(utility::conversions::to_string_t("shipDate"))));
utility::datetime refVal_shipDate;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("shipDate")), refVal_shipDate );
setShipDate(refVal_shipDate);
}
if(multipart->hasContent(utility::conversions::to_string_t("status")))
{
setStatus(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("status"))));
utility::string_t refVal_status;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("status")), refVal_status );
setStatus(refVal_status);
}
if(multipart->hasContent(utility::conversions::to_string_t("complete")))
{
setComplete(ModelBase::boolFromHttpContent(multipart->getContent(utility::conversions::to_string_t("complete"))));
bool refVal_complete;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("complete")), refVal_complete );
setComplete(refVal_complete);
}
return ok;
}
int64_t Order::getId() const
@ -218,7 +247,6 @@ void Order::unsetId()
{
m_IdIsSet = false;
}
int64_t Order::getPetId() const
{
return m_PetId;
@ -239,7 +267,6 @@ void Order::unsetPetId()
{
m_PetIdIsSet = false;
}
int32_t Order::getQuantity() const
{
return m_Quantity;
@ -260,7 +287,6 @@ void Order::unsetQuantity()
{
m_QuantityIsSet = false;
}
utility::datetime Order::getShipDate() const
{
return m_ShipDate;
@ -281,7 +307,6 @@ void Order::unsetShipDate()
{
m_ShipDateIsSet = false;
}
utility::string_t Order::getStatus() const
{
return m_Status;
@ -302,7 +327,6 @@ void Order::unsetStatus()
{
m_StatusIsSet = false;
}
bool Order::isComplete() const
{
return m_Complete;
@ -323,7 +347,6 @@ void Order::unsetComplete()
{
m_CompleteIsSet = false;
}
}
}
}

View File

@ -45,10 +45,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Order members

View File

@ -27,6 +27,8 @@ Pet::Pet()
m_IdIsSet = false;
m_CategoryIsSet = false;
m_Name = utility::conversions::to_string_t("");
m_NameIsSet = false;
m_PhotoUrlsIsSet = false;
m_TagsIsSet = false;
m_Status = utility::conversions::to_string_t("");
m_StatusIsSet = false;
@ -43,8 +45,9 @@ void Pet::validate()
web::json::value Pet::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_IdIsSet)
{
val[utility::conversions::to_string_t("id")] = ModelBase::toJson(m_Id);
@ -53,25 +56,17 @@ web::json::value Pet::toJson() const
{
val[utility::conversions::to_string_t("category")] = ModelBase::toJson(m_Category);
}
val[utility::conversions::to_string_t("name")] = ModelBase::toJson(m_Name);
if(m_NameIsSet)
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_PhotoUrls )
{
jsonArray.push_back(ModelBase::toJson(item));
}
val[utility::conversions::to_string_t("photoUrls")] = web::json::value::array(jsonArray);
val[utility::conversions::to_string_t("name")] = ModelBase::toJson(m_Name);
}
if(m_PhotoUrlsIsSet)
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_Tags )
{
jsonArray.push_back(ModelBase::toJson(item));
}
if(jsonArray.size() > 0)
{
val[utility::conversions::to_string_t("tags")] = web::json::value::array(jsonArray);
}
val[utility::conversions::to_string_t("photoUrls")] = ModelBase::toJson(m_PhotoUrls);
}
if(m_TagsIsSet)
{
val[utility::conversions::to_string_t("tags")] = ModelBase::toJson(m_Tags);
}
if(m_StatusIsSet)
{
@ -81,14 +76,18 @@ web::json::value Pet::toJson() const
return val;
}
void Pet::fromJson(const web::json::value& val)
bool Pet::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("id")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("id"));
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_id;
ok &= ModelBase::fromJson(fieldValue, refVal_id);
setId(refVal_id);
}
}
if(val.has_field(utility::conversions::to_string_t("category")))
@ -96,38 +95,39 @@ void Pet::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("category"));
if(!fieldValue.is_null())
{
auto newItem = std::make_shared<std::shared_ptr<Category>::element_type>();
newItem->fromJson(fieldValue);
setCategory( newItem );
std::shared_ptr<Category> refVal_category;
ok &= ModelBase::fromJson(fieldValue, refVal_category);
setCategory(refVal_category);
}
}
setName(ModelBase::stringFromJson(val.at(utility::conversions::to_string_t("name"))));
if(val.has_field(utility::conversions::to_string_t("name")))
{
m_PhotoUrls.clear();
std::vector<web::json::value> jsonArray;
for( auto& item : val.at(utility::conversions::to_string_t("photoUrls")).as_array() )
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("name"));
if(!fieldValue.is_null())
{
m_PhotoUrls.push_back(ModelBase::stringFromJson(item));
utility::string_t refVal_name;
ok &= ModelBase::fromJson(fieldValue, refVal_name);
setName(refVal_name);
}
}
if(val.has_field(utility::conversions::to_string_t("photoUrls")))
{
m_Tags.clear();
std::vector<web::json::value> jsonArray;
if(val.has_field(utility::conversions::to_string_t("tags")))
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("photoUrls"));
if(!fieldValue.is_null())
{
for( auto& item : val.at(utility::conversions::to_string_t("tags")).as_array() )
{
if(item.is_null())
{
m_Tags.push_back( std::shared_ptr<Tag>(nullptr) );
}
else
{
auto newItem = std::make_shared<std::shared_ptr<Tag>::element_type>();
newItem->fromJson(item);
m_Tags.push_back( newItem );
}
std::vector<utility::string_t> refVal_photoUrls;
ok &= ModelBase::fromJson(fieldValue, refVal_photoUrls);
setPhotoUrls(refVal_photoUrls);
}
}
if(val.has_field(utility::conversions::to_string_t("tags")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("tags"));
if(!fieldValue.is_null())
{
std::vector<std::shared_ptr<Tag>> refVal_tags;
ok &= ModelBase::fromJson(fieldValue, refVal_tags);
setTags(refVal_tags);
}
}
if(val.has_field(utility::conversions::to_string_t("status")))
@ -135,9 +135,12 @@ void Pet::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("status"));
if(!fieldValue.is_null())
{
setStatus(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_status;
ok &= ModelBase::fromJson(fieldValue, refVal_status);
setStatus(refVal_status);
}
}
return ok;
}
void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -147,38 +150,25 @@ void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_IdIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("id"), m_Id));
}
if(m_CategoryIsSet)
{
if (m_Category.get())
{
m_Category->toMultipart(multipart, utility::conversions::to_string_t("category."));
}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("category"), m_Category));
}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("name"), m_Name));
if(m_NameIsSet)
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_PhotoUrls )
{
jsonArray.push_back(ModelBase::toJson(item));
}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("photoUrls"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("name"), m_Name));
}
if(m_PhotoUrlsIsSet)
{
std::vector<web::json::value> jsonArray;
for( auto& item : m_Tags )
{
jsonArray.push_back(ModelBase::toJson(item));
}
if(jsonArray.size() > 0)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("tags"), web::json::value::array(jsonArray), utility::conversions::to_string_t("application/json")));
}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("photoUrls"), m_PhotoUrls));
}
if(m_TagsIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("tags"), m_Tags));
}
if(m_StatusIsSet)
{
@ -186,8 +176,9 @@ void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
}
}
void Pet::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Pet::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -196,52 +187,41 @@ void Pet::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const util
if(multipart->hasContent(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("id"))));
int64_t refVal_id;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("id")), refVal_id );
setId(refVal_id);
}
if(multipart->hasContent(utility::conversions::to_string_t("category")))
{
if(multipart->hasContent(utility::conversions::to_string_t("category")))
{
auto newItem = std::make_shared<std::shared_ptr<Category>::element_type>();
newItem->fromMultiPart(multipart, utility::conversions::to_string_t("category."));
setCategory( newItem );
}
std::shared_ptr<Category> refVal_category;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("category")), refVal_category );
setCategory(refVal_category);
}
setName(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("name"))));
if(multipart->hasContent(utility::conversions::to_string_t("name")))
{
m_PhotoUrls.clear();
web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("photoUrls"))));
for( auto& item : jsonArray.as_array() )
{
m_PhotoUrls.push_back(ModelBase::stringFromJson(item));
}
utility::string_t refVal_name;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("name")), refVal_name );
setName(refVal_name);
}
if(multipart->hasContent(utility::conversions::to_string_t("photoUrls")))
{
m_Tags.clear();
if(multipart->hasContent(utility::conversions::to_string_t("tags")))
{
web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("tags"))));
for( auto& item : jsonArray.as_array() )
{
if(item.is_null())
{
m_Tags.push_back( std::shared_ptr<Tag>(nullptr) );
}
else
{
auto newItem = std::make_shared<std::shared_ptr<Tag>::element_type>();
newItem->fromJson(item);
m_Tags.push_back( newItem );
}
}
}
std::vector<utility::string_t> refVal_photoUrls;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("photoUrls")), refVal_photoUrls );
setPhotoUrls(refVal_photoUrls);
}
if(multipart->hasContent(utility::conversions::to_string_t("tags")))
{
std::vector<std::shared_ptr<Tag>> refVal_tags;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("tags")), refVal_tags );
setTags(refVal_tags);
}
if(multipart->hasContent(utility::conversions::to_string_t("status")))
{
setStatus(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("status"))));
utility::string_t refVal_status;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("status")), refVal_status );
setStatus(refVal_status);
}
return ok;
}
int64_t Pet::getId() const
@ -264,7 +244,6 @@ void Pet::unsetId()
{
m_IdIsSet = false;
}
std::shared_ptr<Category> Pet::getCategory() const
{
return m_Category;
@ -285,7 +264,6 @@ void Pet::unsetCategory()
{
m_CategoryIsSet = false;
}
utility::string_t Pet::getName() const
{
return m_Name;
@ -294,9 +272,18 @@ utility::string_t Pet::getName() const
void Pet::setName(const utility::string_t& value)
{
m_Name = value;
m_NameIsSet = true;
}
bool Pet::nameIsSet() const
{
return m_NameIsSet;
}
void Pet::unsetName()
{
m_NameIsSet = false;
}
std::vector<utility::string_t>& Pet::getPhotoUrls()
{
return m_PhotoUrls;
@ -305,9 +292,18 @@ std::vector<utility::string_t>& Pet::getPhotoUrls()
void Pet::setPhotoUrls(const std::vector<utility::string_t>& value)
{
m_PhotoUrls = value;
m_PhotoUrlsIsSet = true;
}
bool Pet::photoUrlsIsSet() const
{
return m_PhotoUrlsIsSet;
}
void Pet::unsetPhotoUrls()
{
m_PhotoUrlsIsSet = false;
}
std::vector<std::shared_ptr<Tag>>& Pet::getTags()
{
return m_Tags;
@ -328,7 +324,6 @@ void Pet::unsetTags()
{
m_TagsIsSet = false;
}
utility::string_t Pet::getStatus() const
{
return m_Status;
@ -349,7 +344,6 @@ void Pet::unsetStatus()
{
m_StatusIsSet = false;
}
}
}
}

View File

@ -48,10 +48,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Pet members
@ -78,14 +78,18 @@ public:
///
/// </summary>
utility::string_t getName() const;
bool nameIsSet() const;
void unsetName();
void setName(const utility::string_t& value);
/// <summary>
///
/// </summary>
std::vector<utility::string_t>& getPhotoUrls();
bool photoUrlsIsSet() const;
void unsetPhotoUrls();
void setPhotoUrls(const std::vector<utility::string_t>& value);
/// <summary>
@ -113,8 +117,10 @@ protected:
std::shared_ptr<Category> m_Category;
bool m_CategoryIsSet;
utility::string_t m_Name;
std::vector<utility::string_t> m_PhotoUrls;
std::vector<std::shared_ptr<Tag>> m_Tags;
bool m_NameIsSet;
std::vector<utility::string_t> m_PhotoUrls;
bool m_PhotoUrlsIsSet;
std::vector<std::shared_ptr<Tag>> m_Tags;
bool m_TagsIsSet;
utility::string_t m_Status;
bool m_StatusIsSet;

View File

@ -40,8 +40,9 @@ void Tag::validate()
web::json::value Tag::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_IdIsSet)
{
val[utility::conversions::to_string_t("id")] = ModelBase::toJson(m_Id);
@ -54,14 +55,18 @@ web::json::value Tag::toJson() const
return val;
}
void Tag::fromJson(const web::json::value& val)
bool Tag::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("id")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("id"));
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_id;
ok &= ModelBase::fromJson(fieldValue, refVal_id);
setId(refVal_id);
}
}
if(val.has_field(utility::conversions::to_string_t("name")))
@ -69,9 +74,12 @@ void Tag::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("name"));
if(!fieldValue.is_null())
{
setName(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_name;
ok &= ModelBase::fromJson(fieldValue, refVal_name);
setName(refVal_name);
}
}
return ok;
}
void Tag::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -81,7 +89,6 @@ void Tag::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_IdIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("id"), m_Id));
@ -92,8 +99,9 @@ void Tag::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
}
}
void Tag::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool Tag::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -102,12 +110,17 @@ void Tag::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const util
if(multipart->hasContent(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("id"))));
int64_t refVal_id;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("id")), refVal_id );
setId(refVal_id);
}
if(multipart->hasContent(utility::conversions::to_string_t("name")))
{
setName(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("name"))));
utility::string_t refVal_name;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("name")), refVal_name );
setName(refVal_name);
}
return ok;
}
int64_t Tag::getId() const
@ -130,7 +143,6 @@ void Tag::unsetId()
{
m_IdIsSet = false;
}
utility::string_t Tag::getName() const
{
return m_Name;
@ -151,7 +163,6 @@ void Tag::unsetName()
{
m_NameIsSet = false;
}
}
}
}

View File

@ -45,10 +45,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// Tag members

View File

@ -52,8 +52,9 @@ void User::validate()
web::json::value User::toJson() const
{
web::json::value val = web::json::value::object();
web::json::value val = web::json::value::object();
if(m_IdIsSet)
{
val[utility::conversions::to_string_t("id")] = ModelBase::toJson(m_Id);
@ -90,14 +91,18 @@ web::json::value User::toJson() const
return val;
}
void User::fromJson(const web::json::value& val)
bool User::fromJson(const web::json::value& val)
{
bool ok = true;
if(val.has_field(utility::conversions::to_string_t("id")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("id"));
if(!fieldValue.is_null())
{
setId(ModelBase::int64_tFromJson(fieldValue));
int64_t refVal_id;
ok &= ModelBase::fromJson(fieldValue, refVal_id);
setId(refVal_id);
}
}
if(val.has_field(utility::conversions::to_string_t("username")))
@ -105,7 +110,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("username"));
if(!fieldValue.is_null())
{
setUsername(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_username;
ok &= ModelBase::fromJson(fieldValue, refVal_username);
setUsername(refVal_username);
}
}
if(val.has_field(utility::conversions::to_string_t("firstName")))
@ -113,7 +120,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("firstName"));
if(!fieldValue.is_null())
{
setFirstName(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_firstName;
ok &= ModelBase::fromJson(fieldValue, refVal_firstName);
setFirstName(refVal_firstName);
}
}
if(val.has_field(utility::conversions::to_string_t("lastName")))
@ -121,7 +130,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("lastName"));
if(!fieldValue.is_null())
{
setLastName(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_lastName;
ok &= ModelBase::fromJson(fieldValue, refVal_lastName);
setLastName(refVal_lastName);
}
}
if(val.has_field(utility::conversions::to_string_t("email")))
@ -129,7 +140,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("email"));
if(!fieldValue.is_null())
{
setEmail(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_email;
ok &= ModelBase::fromJson(fieldValue, refVal_email);
setEmail(refVal_email);
}
}
if(val.has_field(utility::conversions::to_string_t("password")))
@ -137,7 +150,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("password"));
if(!fieldValue.is_null())
{
setPassword(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_password;
ok &= ModelBase::fromJson(fieldValue, refVal_password);
setPassword(refVal_password);
}
}
if(val.has_field(utility::conversions::to_string_t("phone")))
@ -145,7 +160,9 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("phone"));
if(!fieldValue.is_null())
{
setPhone(ModelBase::stringFromJson(fieldValue));
utility::string_t refVal_phone;
ok &= ModelBase::fromJson(fieldValue, refVal_phone);
setPhone(refVal_phone);
}
}
if(val.has_field(utility::conversions::to_string_t("userStatus")))
@ -153,9 +170,12 @@ void User::fromJson(const web::json::value& val)
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("userStatus"));
if(!fieldValue.is_null())
{
setUserStatus(ModelBase::int32_tFromJson(fieldValue));
int32_t refVal_userStatus;
ok &= ModelBase::fromJson(fieldValue, refVal_userStatus);
setUserStatus(refVal_userStatus);
}
}
return ok;
}
void User::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
@ -165,7 +185,6 @@ void User::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utili
{
namePrefix += utility::conversions::to_string_t(".");
}
if(m_IdIsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("id"), m_Id));
@ -200,8 +219,9 @@ void User::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utili
}
}
void User::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
bool User::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
@ -210,36 +230,53 @@ void User::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const uti
if(multipart->hasContent(utility::conversions::to_string_t("id")))
{
setId(ModelBase::int64_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("id"))));
int64_t refVal_id;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("id")), refVal_id );
setId(refVal_id);
}
if(multipart->hasContent(utility::conversions::to_string_t("username")))
{
setUsername(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("username"))));
utility::string_t refVal_username;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("username")), refVal_username );
setUsername(refVal_username);
}
if(multipart->hasContent(utility::conversions::to_string_t("firstName")))
{
setFirstName(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("firstName"))));
utility::string_t refVal_firstName;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("firstName")), refVal_firstName );
setFirstName(refVal_firstName);
}
if(multipart->hasContent(utility::conversions::to_string_t("lastName")))
{
setLastName(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("lastName"))));
utility::string_t refVal_lastName;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("lastName")), refVal_lastName );
setLastName(refVal_lastName);
}
if(multipart->hasContent(utility::conversions::to_string_t("email")))
{
setEmail(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("email"))));
utility::string_t refVal_email;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("email")), refVal_email );
setEmail(refVal_email);
}
if(multipart->hasContent(utility::conversions::to_string_t("password")))
{
setPassword(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("password"))));
utility::string_t refVal_password;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("password")), refVal_password );
setPassword(refVal_password);
}
if(multipart->hasContent(utility::conversions::to_string_t("phone")))
{
setPhone(ModelBase::stringFromHttpContent(multipart->getContent(utility::conversions::to_string_t("phone"))));
utility::string_t refVal_phone;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("phone")), refVal_phone );
setPhone(refVal_phone);
}
if(multipart->hasContent(utility::conversions::to_string_t("userStatus")))
{
setUserStatus(ModelBase::int32_tFromHttpContent(multipart->getContent(utility::conversions::to_string_t("userStatus"))));
int32_t refVal_userStatus;
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("userStatus")), refVal_userStatus );
setUserStatus(refVal_userStatus);
}
return ok;
}
int64_t User::getId() const
@ -262,7 +299,6 @@ void User::unsetId()
{
m_IdIsSet = false;
}
utility::string_t User::getUsername() const
{
return m_Username;
@ -283,7 +319,6 @@ void User::unsetUsername()
{
m_UsernameIsSet = false;
}
utility::string_t User::getFirstName() const
{
return m_FirstName;
@ -304,7 +339,6 @@ void User::unsetFirstName()
{
m_FirstNameIsSet = false;
}
utility::string_t User::getLastName() const
{
return m_LastName;
@ -325,7 +359,6 @@ void User::unsetLastName()
{
m_LastNameIsSet = false;
}
utility::string_t User::getEmail() const
{
return m_Email;
@ -346,7 +379,6 @@ void User::unsetEmail()
{
m_EmailIsSet = false;
}
utility::string_t User::getPassword() const
{
return m_Password;
@ -367,7 +399,6 @@ void User::unsetPassword()
{
m_PasswordIsSet = false;
}
utility::string_t User::getPhone() const
{
return m_Phone;
@ -388,7 +419,6 @@ void User::unsetPhone()
{
m_PhoneIsSet = false;
}
int32_t User::getUserStatus() const
{
return m_UserStatus;
@ -409,7 +439,6 @@ void User::unsetUserStatus()
{
m_UserStatusIsSet = false;
}
}
}
}

View File

@ -45,10 +45,10 @@ public:
void validate() override;
web::json::value toJson() const override;
void fromJson(const web::json::value& json) override;
bool fromJson(const web::json::value& json) override;
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
/////////////////////////////////////////////
/// User members