Created by: etherealjoy
Changes
- Added support for maps. Handling maps require generic overloaded functions for all map types.
- Added support for ByteArray.
- Simplify Model generation since the overloaded functions handle all valid OAS data types.
- Add nested map/array support.
- Catch deserialization exceptions.
- Additional checks during (de)serialization.
- No API changes for the end user.
- Remove broken inheritance from std::vector and std::map as it requires STL compliant implementation.
Fixes #5148 (closed) Fixes #4022 (closed) Fixes #3254 (closed) Fixes #2003 (closed) Fixes #934 (closed)
Next Steps/Future enhancements
- Fix multipart/form support.
- Validation can be added since now the deserialization returns a status
- Enhancement of Enum support
- File Upload/Download
Tests Tests with the PetStore spec is done but the spec is too simplistic. In addition to verifying the issues linked above have been solved, a verification using the docker specification v1.39 which is a fairly complicated specification has been done.
#include "ApiTests.h"
#include <iostream>
#include <chrono>
#include <thread>
#include <functional>
OAIApiTests::OAIApiTests(std::string host, std::string basePath){
apiconfiguration = std::make_shared<ApiConfiguration>();
apiconfiguration->setBaseUrl(host + basePath);
apiconfiguration->setUserAgent(U("OpenAPI Client"));
apiclient = std::make_shared<ApiClient>(apiconfiguration);
api = std::make_shared<ContainerApi>(apiclient);
}
OAIApiTests::~OAIApiTests() {
}
void OAIApiTests::runTests(){
testListContainers();
testInspectContainer();
testCreateContainer();
}
void OAIApiTests::testListContainers(){
std::function<void(std::vector<std::shared_ptr<ContainerSummary>>)> responseCallback =\
[](std::vector<std::shared_ptr<ContainerSummary>> containers)
{
std::cout << "containers listed successfully" << std::endl;
};
auto reqTask = api->containerList(true, 100, true, utility::string_t(""))\
.then(responseCallback);
try{
reqTask.wait();
}
catch(const ApiException& ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
catch(const std::exception &ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
}
void OAIApiTests::testInspectContainer(){
std::function<void(std::shared_ptr<Inline_response_200>)> responseCallback = []\
(std::shared_ptr<Inline_response_200> containers)
{
std::cout << "container inspected successfully" << std::endl;
};
auto reqTask = api->containerInspect(utility::string_t("quizzical_germain"), true)\
.then(responseCallback);
try{
reqTask.wait();
}
catch(const ApiException& ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
catch(const std::exception &ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
}
void OAIApiTests::testCreateContainer(){
std::shared_ptr<ContainerCreateConfig> body = make_shared<ContainerCreateConfig>();
utility::string_t name = "";
std::function<void(std::shared_ptr<Inline_response_201>)> responseCallback = [&]\
(std::shared_ptr<Inline_response_201> response)
{
name = response->getId();
std::cout << "created container successfully" << std::endl;
};
body->setImage(utility::string_t("debian"));
auto reqTask = api->containerCreate(body, utility::string_t("cpp-rest"))\
.then(responseCallback);
try{
reqTask.wait();
}
catch(const ApiException& ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
catch(const std::exception &ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
std::function<void()> startCallback = []()
{
std::cout << "started container successfully" << std::endl;
};
reqTask = api->containerStart(name, utility::string_t(""))\
.then(startCallback);
try{
reqTask.wait();
}
catch(const ApiException& ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
catch(const std::exception &ex){
std::cout << ex.what() << std::endl << std::flush;
std::string err(ex.what());
}
}
cc @muttleyxd @stkrwork @ravinikam @MartinDelille
PR checklist
-
Read the contribution guidelines. -
If contributing template-only or documentation-only changes which will change sample output, build the project before. -
Run the shell script(s) under ./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc). -
File the PR against the correct branch: master
,4.3.x
,5.0.x
. Default:master
. -
Copy the technical committee to review the pull request if your PR is targeting a particular programming language.