Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class {{declspec}} {{classname}}
{
public:
{{classname}}();
{{classname}}(utility::string_t str);
operator utility::string_t() const {
return enumToStrMap.at(getValue());
}

{{! operator std::string() const {
return enumToStrMap.at(getValue());
} }}

virtual ~{{classname}}();

/////////////////////////////////////////////
Expand Down Expand Up @@ -124,6 +133,21 @@ public:

protected:
e{{classname}} m_value;
std::map<e{{classname}},utility::string_t> enumToStrMap = {
{{#allowableValues}}
{{#enumVars}}
{ e{{classname}}::{{classname}}_{{{name}}}, "{{{name}}}" }{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
};
std::map<utility::string_t,e{{classname}}> strToEnumMap = {
{{#allowableValues}}
{{#enumVars}}
{ "{{{name}}}", e{{classname}}::{{classname}}_{{{name}}} }{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
};

};
{{/isEnum}}
{{^isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ void {{classname}}::setValue({{classname}}::e{{classname}} const value)
m_value = value;
}

{{classname}}::{{classname}}(utility::string_t str){
setValue( strToEnumMap[str] );
}

{{/isEnum}}
{{^isEnum}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,34 @@ paths:
security:
- petstore_auth:
- 'read:pets'
/pet/findByColor:
get:
tags:
- pet
summary: Finds Pets by color
description: Returns pets filtered by color.
operationId: findPetsByColor
parameters:
- name: color
in: query
description: Color of the pet to filter by
required: false
schema:
$ref: '#/components/schemas/Color'
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid color value
security:
- petstore_auth:
- 'read:pets'
/pet/findByTags:
get:
tags:
Expand Down Expand Up @@ -748,6 +776,18 @@ components:
- sold
xml:
name: Pet
Color:
title: Pet Color
description: pet color in the store
type: string
enum:
- black
- white
- brown
- golden
- mixed
xml:
name: Pet
ApiResponse:
title: An uploaded response
description: Describes the result of uploading an image resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include/CppRestPetstoreClient/api/UserApi.h
include/CppRestPetstoreClient/api/UserOrPetApi.h
include/CppRestPetstoreClient/model/ApiResponse.h
include/CppRestPetstoreClient/model/Category.h
include/CppRestPetstoreClient/model/Color.h
include/CppRestPetstoreClient/model/CreateUserOrPet_request.h
include/CppRestPetstoreClient/model/Order.h
include/CppRestPetstoreClient/model/Pet.h
Expand All @@ -42,6 +43,7 @@ src/api/UserApi.cpp
src/api/UserOrPetApi.cpp
src/model/ApiResponse.cpp
src/model/Category.cpp
src/model/Color.cpp
src/model/CreateUserOrPet_request.cpp
src/model/Order.cpp
src/model/Pet.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "CppRestPetstoreClient/ApiClient.h"

#include "CppRestPetstoreClient/model/ApiResponse.h"
#include "CppRestPetstoreClient/model/Color.h"
#include "CppRestPetstoreClient/HttpContent.h"
#include "CppRestPetstoreClient/model/Pet.h"
#include <vector>
Expand Down Expand Up @@ -69,6 +70,16 @@ class PetApi
boost::optional<utility::string_t> apiKey
) const;
/// <summary>
/// Finds Pets by color
/// </summary>
/// <remarks>
/// Returns pets filtered by color.
/// </remarks>
/// <param name="color">Color of the pet to filter by (optional, default to new Color())</param>
pplx::task<std::vector<std::shared_ptr<Pet>>> findPetsByColor(
boost::optional<std::shared_ptr<Color>> color
) const;
/// <summary>
/// Finds Pets by status
/// </summary>
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 7.14.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/*
* Color.h
*
* pet color in the store
*/

#ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_Color_H_
#define ORG_OPENAPITOOLS_CLIENT_MODEL_Color_H_


#include "CppRestPetstoreClient/ModelBase.h"


namespace org {
namespace openapitools {
namespace client {
namespace model {


class Color
: public ModelBase
{
public:
Color();
Color(utility::string_t str);
operator utility::string_t() const {
return enumToStrMap.at(getValue());
}


virtual ~Color();

/////////////////////////////////////////////
/// ModelBase overrides

void validate() override;

web::json::value toJson() const override;
bool fromJson(const web::json::value& json) override;

void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
bool fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;

enum class eColor
{
Color_BLACK,
Color_WHITE,
Color_BROWN,
Color_GOLDEN,
Color_MIXED,
};

eColor getValue() const;
void setValue(eColor const value);

protected:
eColor m_value;
std::map<eColor,utility::string_t> enumToStrMap = {
{ eColor::Color_BLACK, "BLACK" },
{ eColor::Color_WHITE, "WHITE" },
{ eColor::Color_BROWN, "BROWN" },
{ eColor::Color_GOLDEN, "GOLDEN" },
{ eColor::Color_MIXED, "MIXED" }
};
std::map<utility::string_t,eColor> strToEnumMap = {
{ "BLACK", eColor::Color_BLACK },
{ "WHITE", eColor::Color_WHITE },
{ "BROWN", eColor::Color_BROWN },
{ "GOLDEN", eColor::Color_GOLDEN },
{ "MIXED", eColor::Color_MIXED }
};

};

}
}
}
}

#endif /* ORG_OPENAPITOOLS_CLIENT_MODEL_Color_H_ */
132 changes: 132 additions & 0 deletions samples/client/petstore/cpp-restsdk/client/src/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,138 @@ pplx::task<void> PetApi::deletePet(int64_t petId, boost::optional<utility::strin
return void();
});
}
pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByColor(boost::optional<std::shared_ptr<Color>> color) const
{


std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t localVarPath = utility::conversions::to_string_t("/pet/findByColor");

std::map<utility::string_t, utility::string_t> localVarQueryParams;
std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
std::map<utility::string_t, utility::string_t> localVarFormParams;
std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

utility::string_t localVarResponseHttpContentType;

// use JSON if possible
if ( localVarResponseHttpContentTypes.size() == 0 )
{
localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
}
// JSON
else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
{
localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
}
// multipart formdata
else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
{
localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else
{
throw ApiException(400, utility::conversions::to_string_t("PetApi->findPetsByColor does not produce any supported media type"));
}

localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

if (color && *color != nullptr)
{
localVarQueryParams[utility::conversions::to_string_t("color")] = ApiClient::parameterToString(*color);
}

std::shared_ptr<IHttpBody> localVarHttpBody;
utility::string_t localVarRequestHttpContentType;

// use JSON if possible
if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
}
// multipart formdata
else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->findPetsByColor does not consume any supported media type"));
}

// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config

return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
.then([=, this](web::http::http_response localVarResponse)
{
if (m_ApiClient->getResponseHandler())
{
m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
}

// 1xx - informational : OK
// 2xx - successful : OK
// 3xx - redirection : OK
// 4xx - client error : not OK
// 5xx - client error : not OK
if (localVarResponse.status_code() >= 400)
{
throw ApiException(localVarResponse.status_code()
, utility::conversions::to_string_t("error calling findPetsByColor: ") + localVarResponse.reason_phrase()
, std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
}

// check response content type
if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
{
utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
{
throw ApiException(500
, utility::conversions::to_string_t("error calling findPetsByColor: unexpected response type: ") + localVarContentType
, std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
}
}

return localVarResponse.extract_string();
})
.then([=, this](utility::string_t localVarResponse)
{
std::vector<std::shared_ptr<Pet>> localVarResult;

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;
ModelBase::fromJson(localVarItem, localVarItemObj);
localVarResult.push_back(localVarItemObj);
}
}
// else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
// {
// TODO multipart response parsing
// }
else
{
throw ApiException(500
, utility::conversions::to_string_t("error calling findPetsByColor: unsupported response type"));
}

return localVarResult;
});
}
pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByStatus(std::vector<utility::string_t> status) const
{

Expand Down
Loading
Loading