forked from loafle/openapi-generator-original
commit c5a0d0f7394aa742fa336fff7e7c1d3049761868 Merge: 8c4991ba3ed f8ff8c87609 Author: William Cheng <wing328hk@gmail.com> Date: Tue Aug 17 18:28:12 2021 +0800 Merge branch 'mustache-linting' of https://github.com/NathanBaulch/openapi-generator into NathanBaulch-mustache-linting commit f8ff8c87609b1ca36fa26fb8474806999638195e Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Thu Aug 5 14:12:47 2021 +1000 Reorder tags that handle missing values commit f5d8a33709d6a3f846a9fe4520b78c3d637051d9 Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Thu Aug 5 14:08:59 2021 +1000 Use dot notation where possible commit 493d14921e2333f3ae19ef6fc89318b7e263a80c Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Thu Aug 5 14:10:49 2021 +1000 Remove empty tags commit 32480dc53f48227d55531b94e307d72671373737 Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Thu Aug 5 10:41:58 2021 +1000 Remove redundant sections commit a8edabd722c34aa094b4aeb11c22664529c3a219 Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Wed Aug 4 22:02:22 2021 +1000 Trim extra EOF new lines commit e89bd7458e3594bf0d30e580bc9408e45b018a57 Author: Nathan Baulch <nathan.baulch@gmail.com> Date: Wed Aug 4 21:59:26 2021 +1000 Trim trailing whitespace
418 lines
8.8 KiB
C++
418 lines
8.8 KiB
C++
#include "PetApi.h"
|
|
|
|
using namespace Tiny;
|
|
|
|
|
|
|
|
Response<
|
|
Pet
|
|
>
|
|
PetApi::
|
|
addPet(
|
|
|
|
Pet pet
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet"; //
|
|
// Query |
|
|
// Headers |
|
|
// Form |
|
|
// Body | pet
|
|
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | POST
|
|
http.addHeader("Content-Type", "application/json");
|
|
|
|
|
|
|
|
payload = pet.toJson().dump();
|
|
|
|
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
|
|
Pet obj(output_string);
|
|
|
|
|
|
Response<Pet> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
String
|
|
>
|
|
PetApi::
|
|
deletePet(
|
|
|
|
long petId
|
|
,
|
|
|
|
std::string apiKey
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/{petId}"; //petId
|
|
// Query |
|
|
// Headers | apiKey
|
|
// Form |
|
|
// Body |
|
|
|
|
std::string s_petId("{");
|
|
s_petId.append("petId");
|
|
s_petId.append("}");
|
|
|
|
int pos = url.find(s_petId);
|
|
|
|
url.erase(pos, s_petId.length());
|
|
url.insert(pos, stringify(petId));
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | DELETE
|
|
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
Response<String> response(output, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
std::list<Pet>
|
|
>
|
|
PetApi::
|
|
findPetsByStatus(
|
|
std::list<std::string> status
|
|
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/findByStatus"; //
|
|
// Query | status
|
|
// Headers |
|
|
// Form |
|
|
// Body |
|
|
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | GET
|
|
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
std::list<Pet> obj = std::list<Pet>();
|
|
bourne::json jsonPayload(output_string);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto& var : jsonPayload.array_range())
|
|
{
|
|
Pet tmp(var.dump());
|
|
obj.push_back(tmp);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response<std::list<Pet>> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
std::list<Pet>
|
|
>
|
|
PetApi::
|
|
findPetsByTags(
|
|
std::list<std::string> tags
|
|
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/findByTags"; //
|
|
// Query | tags
|
|
// Headers |
|
|
// Form |
|
|
// Body |
|
|
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | GET
|
|
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
std::list<Pet> obj = std::list<Pet>();
|
|
bourne::json jsonPayload(output_string);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto& var : jsonPayload.array_range())
|
|
{
|
|
Pet tmp(var.dump());
|
|
obj.push_back(tmp);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response<std::list<Pet>> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
Pet
|
|
>
|
|
PetApi::
|
|
getPetById(
|
|
|
|
long petId
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/{petId}"; //petId
|
|
// Query |
|
|
// Headers |
|
|
// Form |
|
|
// Body |
|
|
|
|
std::string s_petId("{");
|
|
s_petId.append("petId");
|
|
s_petId.append("}");
|
|
|
|
int pos = url.find(s_petId);
|
|
|
|
url.erase(pos, s_petId.length());
|
|
url.insert(pos, stringify(petId));
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | GET
|
|
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
|
|
Pet obj(output_string);
|
|
|
|
|
|
Response<Pet> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
Pet
|
|
>
|
|
PetApi::
|
|
updatePet(
|
|
|
|
Pet pet
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet"; //
|
|
// Query |
|
|
// Headers |
|
|
// Form |
|
|
// Body | pet
|
|
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | PUT
|
|
http.addHeader("Content-Type", "application/json");
|
|
|
|
|
|
|
|
payload = pet.toJson().dump();
|
|
|
|
int httpCode = http.sendRequest("PUT", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
|
|
Pet obj(output_string);
|
|
|
|
|
|
Response<Pet> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
String
|
|
>
|
|
PetApi::
|
|
updatePetWithForm(
|
|
|
|
long petId
|
|
,
|
|
|
|
std::string name
|
|
,
|
|
|
|
std::string status
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/{petId}"; //petId
|
|
// Query |
|
|
// Headers |
|
|
// Form | name status
|
|
// Body |
|
|
|
|
std::string s_petId("{");
|
|
s_petId.append("petId");
|
|
s_petId.append("}");
|
|
|
|
int pos = url.find(s_petId);
|
|
|
|
url.erase(pos, s_petId.length());
|
|
url.insert(pos, stringify(petId));
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | POST
|
|
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
Response<String> response(output, httpCode);
|
|
return response;
|
|
}
|
|
|
|
Response<
|
|
ApiResponse
|
|
>
|
|
PetApi::
|
|
uploadFile(
|
|
|
|
long petId
|
|
,
|
|
|
|
std::string additionalMetadata
|
|
,
|
|
|
|
std::string file
|
|
|
|
)
|
|
{
|
|
std::string url = basepath + "/pet/{petId}/uploadImage"; //petId
|
|
// Query |
|
|
// Headers |
|
|
// Form | additionalMetadata file
|
|
// Body |
|
|
|
|
std::string s_petId("{");
|
|
s_petId.append("petId");
|
|
s_petId.append("}");
|
|
|
|
int pos = url.find(s_petId);
|
|
|
|
url.erase(pos, s_petId.length());
|
|
url.insert(pos, stringify(petId));
|
|
|
|
begin(url);
|
|
|
|
std::string payload = "";
|
|
// Send Request
|
|
// METHOD | POST
|
|
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
|
|
|
|
// Handle Request
|
|
String output = http.getString();
|
|
std::string output_string = output.c_str();
|
|
|
|
http.end();
|
|
|
|
|
|
|
|
|
|
ApiResponse obj(output_string);
|
|
|
|
|
|
Response<ApiResponse> response(obj, httpCode);
|
|
return response;
|
|
}
|
|
|
|
|
|
|