[C++][Pistache] Compile error when nesting references (#16711) (#18586)

When components/schema/<object> reference other objects, validate() was
getting called on the referenced objects with no arguments. The return
value was void, but checked as if it was a boolean value.
This commit is contained in:
keyjh2 2024-05-07 03:15:42 -06:00 committed by GitHub
parent dec8a430df
commit be94c22d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 1233 additions and 374 deletions

View File

@ -0,0 +1,7 @@
generatorName: cpp-pistache-server
outputDir: samples/server/petstore/cpp-pistache-nested-schema-refs
inputSpec: modules/openapi-generator/src/test/resources/3_0/nested-schema-refs.yaml
templateDir: modules/openapi-generator/src/main/resources/cpp-pistache-server
additionalProperties:
useStructModel: "false"
addExternalLibs: "true"

View File

@ -61,7 +61,7 @@ bool {{classname}}::validate(std::stringstream& msg, const std::string& pathPref
{{> model-validation-body }}
}
{{/hasValidation}}{{#required}}{{#isModel}}
if (!m_{{name}}.validate()) {
if (!m_{{name}}.validate(msg, _pathPrefix + ".{{nameInCamelCase}}")) {
msg << _pathPrefix << ": {{name}} is invalid;";
success = false;
}{{/isModel}}{{/required}}{{/isArray}}{{/vars}}{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}

View File

@ -0,0 +1,37 @@
openapi: 3.0.0
info:
version: 1.0.0
title: Test swagger file
paths:
/pet:
get:
tags:
- store
operationId: getNestedObject
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/outerType'
components:
schemas:
outerType:
type: object
required:
- middle
properties:
middle:
$ref: '#/components/schemas/middleType'
middleType:
type: object
required:
- inner
properties:
inner:
$ref: '#/components/schemas/innerType'
innerType:
type: string

View File

@ -0,0 +1,3 @@
build/
external/
pistache/

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1,14 @@
CMakeLists.txt
README.md
api/ApiBase.h
api/StoreApi.cpp
api/StoreApi.h
impl/StoreApiImpl.cpp
impl/StoreApiImpl.h
main-api-server.cpp
model/Helpers.cpp
model/Helpers.h
model/MiddleType.cpp
model/MiddleType.h
model/OuterType.cpp
model/OuterType.h

View File

@ -0,0 +1 @@
7.6.0-SNAPSHOT

View File

@ -0,0 +1,38 @@
cmake_minimum_required (VERSION 3.2)
project(api-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" )
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(PISTACHE
GIT_REPOSITORY https://github.com/pistacheio/pistache.git
BUILD_IN_SOURCE true
INSTALL_COMMAND meson setup build --prefix=${EXTERNAL_INSTALL_LOCATION} --libdir=lib && meson install -C build
)
ExternalProject_Add(NLOHMANN
GIT_REPOSITORY https://github.com/nlohmann/json.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DJSON_BuildTests=OFF
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} pistache pthread)

View File

@ -0,0 +1,48 @@
# REST API Server for Test swagger file
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Pistache](https://github.com/oktal/pistache) Framework.
## Files organization
The Pistache C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
## Namespaces
org.openapitools.server.api
org.openapitools.server.model

View File

@ -0,0 +1,39 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* ApiBase.h
*
* Generalization of the Api classes
*/
#ifndef ApiBase_H_
#define ApiBase_H_
#include <pistache/router.h>
#include <memory>
namespace org::openapitools::server::api
{
class ApiBase {
public:
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
virtual ~ApiBase() = default;
virtual void init() = 0;
protected:
const std::shared_ptr<Pistache::Rest::Router> router;
};
} // namespace org::openapitools::server::api
#endif /* ApiBase_H_ */

View File

@ -0,0 +1,86 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "StoreApi.h"
#include "Helpers.h"
namespace org::openapitools::server::api
{
using namespace org::openapitools::server::helpers;
using namespace org::openapitools::server::model;
const std::string StoreApi::base = "";
StoreApi::StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
void StoreApi::init() {
setupRoutes();
}
void StoreApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Get(*router, base + "/pet", Routes::bind(&StoreApi::get_nested_object_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
}
std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(const std::exception& ex) const noexcept
{
try {
throw;
} catch (nlohmann::detail::exception &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (org::openapitools::server::helpers::ValidationException &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}
std::pair<Pistache::Http::Code, std::string> StoreApi::handleOperationException(const std::exception& ex) const noexcept
{
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
}
void StoreApi::get_nested_object_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
try {
try {
this->get_nested_object(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
response.send(errorInfo.first, errorInfo.second);
return;
}
} catch (std::exception &e) {
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace org::openapitools::server::api

View File

@ -0,0 +1,77 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* StoreApi.h
*
*
*/
#ifndef StoreApi_H_
#define StoreApi_H_
#include "ApiBase.h"
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <optional>
#include <utility>
#include "OuterType.h"
namespace org::openapitools::server::api
{
class StoreApi : public ApiBase {
public:
explicit StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr);
~StoreApi() override = default;
void init() override;
static const std::string base;
private:
void setupRoutes();
void get_nested_object_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
/// <summary>
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
/// May be overridden to return custom error formats. This is called inside a catch block.
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
/// </summary>
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
/// <summary>
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
/// May be overridden to return custom error formats. This is called inside a catch block.
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
/// </summary>
virtual std::pair<Pistache::Http::Code, std::string> handleOperationException(const std::exception& ex) const noexcept;
/// <summary>
///
/// </summary>
/// <remarks>
///
/// </remarks>
virtual void get_nested_object(Pistache::Http::ResponseWriter &response) = 0;
};
} // namespace org::openapitools::server::api
#endif /* StoreApi_H_ */

View File

@ -0,0 +1,8 @@
#!/bin/bash
# build C++ pistache petstore
#
mkdir -p build
cd build
cmake ..
make -j

View File

@ -0,0 +1,35 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "StoreApiImpl.h"
namespace org {
namespace openapitools {
namespace server {
namespace api {
using namespace org::openapitools::server::model;
StoreApiImpl::StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: StoreApi(rtr)
{
}
void StoreApiImpl::get_nested_object(Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
}
}
}
}

View File

@ -0,0 +1,52 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* StoreApiImpl.h
*
*
*/
#ifndef STORE_API_IMPL_H_
#define STORE_API_IMPL_H_
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <optional>
#include <StoreApi.h>
#include "OuterType.h"
namespace org::openapitools::server::api
{
using namespace org::openapitools::server::model;
class StoreApiImpl : public org::openapitools::server::api::StoreApi {
public:
explicit StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr);
~StoreApiImpl() override = default;
void get_nested_object(Pistache::Http::ResponseWriter &response);
};
} // namespace org::openapitools::server::api
#endif

View File

@ -0,0 +1,93 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <vector>
#include <signal.h>
#include <unistd.h>
#endif
#include "ApiBase.h"
#include "StoreApiImpl.h"
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
static Pistache::Http::Endpoint *httpEndpoint;
#ifdef __linux__
static void sigHandler [[noreturn]] (int sig){
switch(sig){
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGHUP:
default:
httpEndpoint->shutdown();
break;
}
exit(0);
}
static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr);
}
#endif
using namespace org::openapitools::server::api;
int main() {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
httpEndpoint = new Pistache::Http::Endpoint((addr));
auto router = std::make_shared<Pistache::Rest::Router>();
auto opts = Pistache::Http::Endpoint::options()
.threads(PISTACHE_SERVER_THREADS);
opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
httpEndpoint->init(opts);
auto apiImpls = std::vector<std::shared_ptr<ApiBase>>();
apiImpls.push_back(std::make_shared<StoreApiImpl>(router));
for (auto api : apiImpls) {
api->init();
}
httpEndpoint->setHandler(router->handler());
httpEndpoint->serve();
httpEndpoint->shutdown();
}

View File

@ -0,0 +1,148 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "Helpers.h"
#include <regex>
namespace org::openapitools::server::helpers
{
const std::regex regexRfc3339_date(R"(^(\d{4})\-(\d{2})\-(\d{2})$)");
const std::regex regexRfc3339_date_time(
R"(^(\d{4})\-(\d{2})\-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|([\+\-])(\d{2}):(\d{2}))$)"
);
namespace
{
// Determine if given year is a leap year
// See RFC 3339, Appendix C https://tools.ietf.org/html/rfc3339#appendix-C
bool isLeapYear(const uint16_t year) {
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
bool validateDateValues(const uint16_t year, const uint16_t month, const uint16_t day) {
return !(
(month == 0 || month > 12)
|| (day == 0)
|| (month == 2 && day > (28 + (isLeapYear(year) ? 1 : 0)))
|| (month <= 7 && day > (30 + month % 2))
|| (month >= 8 && day > (31 - month % 2))
);
}
bool validateTimeValues(const uint16_t hours, const uint16_t minutes, const uint16_t seconds) {
return (hours <= 23) && (minutes <= 59) && (seconds <= 60);
}
}
bool validateRfc3339_date(const std::string& str) {
std::smatch match;
const bool found = std::regex_search(str, match, regexRfc3339_date);
return found && validateDateValues(static_cast<uint16_t>(std::stoi(match[1])),
static_cast<uint16_t>(std::stoi(match[2])),
static_cast<uint16_t>(std::stoi(match[3])));
}
bool validateRfc3339_date_time(const std::string& str) {
std::smatch match;
const bool found = std::regex_search(str, match, regexRfc3339_date_time);
return found
&& validateDateValues(static_cast<uint16_t>(std::stoi(match[1])),
static_cast<uint16_t>(std::stoi(match[2])),
static_cast<uint16_t>(std::stoi(match[3])))
&& validateTimeValues(static_cast<uint16_t>(std::stoi(match[4])),
static_cast<uint16_t>(std::stoi(match[5])),
static_cast<uint16_t>(std::stoi(match[6])));
}
std::string toStringValue(const std::string &value){
return std::string(value);
}
std::string toStringValue(const int32_t value){
return std::to_string(value);
}
std::string toStringValue(const int64_t value){
return std::to_string(value);
}
std::string toStringValue(const bool value){
return value ? std::string("true") : std::string("false");
}
std::string toStringValue(const float value){
return std::to_string(value);
}
std::string toStringValue(const double value){
return std::to_string(value);
}
bool fromStringValue(const std::string &inStr, std::string &value){
value = std::string(inStr);
return true;
}
bool fromStringValue(const std::string &inStr, int32_t &value){
try {
value = std::stoi( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, int64_t &value){
try {
value = std::stol( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, bool &value){
if (inStr == "true") {
value = true;
return true;
}
if (inStr == "false") {
value = false;
return true;
}
return false;
}
bool fromStringValue(const std::string &inStr, float &value){
try {
value = std::stof( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, double &value){
try {
value = std::stod( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
} // namespace org::openapitools::server::helpers

View File

@ -0,0 +1,136 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Helpers.h
*
* This is the helper class for models and primitives
*/
#ifndef Helpers_H_
#define Helpers_H_
#include <ctime>
#include <string>
#include <sstream>
#include <vector>
#include <map>
namespace org::openapitools::server::helpers
{
class ValidationException : public std::runtime_error
{
public:
explicit ValidationException(const std::string& what)
: std::runtime_error(what)
{ }
~ValidationException() override = default;
};
/// <summary>
/// Validate a string against the full-date definition of RFC 3339, section 5.6.
/// </summary>
bool validateRfc3339_date(const std::string& str);
/// <summary>
/// Validate a string against the date-time definition of RFC 3339, section 5.6.
/// </summary>
bool validateRfc3339_date_time(const std::string& str);
namespace sfinae_helpers
{
struct NoType {};
template <typename T1, typename T2> NoType operator==(const T1&, const T2&);
template <typename T1, typename T2> class EqualsOperatorAvailable
{
public:
enum
{
value = !std::is_same< decltype(std::declval<T1>() == std::declval<T2>()), NoType >::value
};
};
} // namespace sfinae_helpers
/// <summary>
/// Determine if the given vector<T> only has unique elements. T must provide the == operator.
/// </summary>
template <typename T>
bool hasOnlyUniqueItems(const std::vector<T>& vec)
{
static_assert(sfinae_helpers::EqualsOperatorAvailable<T, T>::value,
"hasOnlyUniqueItems<T> cannot be called, passed template type does not provide == operator.");
if (vec.size() <= 1)
{
return true;
}
// Compare every element of vec to every other element of vec.
// This isn't an elegant way to do this, since it's O(n^2),
// but it's the best solution working only with the == operator.
// This could be greatly improved if our models provided a valid hash
// and/or the < operator
for (size_t i = 0; i < vec.size() - 1; i++)
{
for (size_t j = i + 1; j < vec.size(); j++)
{
if (vec[i] == vec[j])
{
return false;
}
}
}
return true;
}
std::string toStringValue(const std::string &value);
std::string toStringValue(const int32_t value);
std::string toStringValue(const int64_t value);
std::string toStringValue(const bool value);
std::string toStringValue(const float value);
std::string toStringValue(const double value);
bool fromStringValue(const std::string &inStr, std::string &value);
bool fromStringValue(const std::string &inStr, int32_t &value);
bool fromStringValue(const std::string &inStr, int64_t &value);
bool fromStringValue(const std::string &inStr, bool &value);
bool fromStringValue(const std::string &inStr, float &value);
bool fromStringValue(const std::string &inStr, double &value);
template<typename T>
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){
try{
for(auto & item : inStr){
T itemValue;
if(fromStringValue(item, itemValue)){
value.push_back(itemValue);
}
}
}
catch(...){
return false;
}
return value.size() > 0;
}
template<typename T>
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){
std::vector<std::string> inStrings;
std::istringstream f(inStr);
std::string s;
while (std::getline(f, s, separator)) {
inStrings.push_back(s);
}
return fromStringValue(inStrings, value);
}
} // namespace org::openapitools::server::helpers
#endif // Helpers_H_

View File

@ -0,0 +1,91 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "MiddleType.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
MiddleType::MiddleType()
{
m_Inner = "";
}
void MiddleType::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool MiddleType::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool MiddleType::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "MiddleType" : pathPrefix;
return success;
}
bool MiddleType::operator==(const MiddleType& rhs) const
{
return
(getInner() == rhs.getInner())
;
}
bool MiddleType::operator!=(const MiddleType& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const MiddleType& o)
{
j = nlohmann::json::object();
j["inner"] = o.m_Inner;
}
void from_json(const nlohmann::json& j, MiddleType& o)
{
j.at("inner").get_to(o.m_Inner);
}
std::string MiddleType::getInner() const
{
return m_Inner;
}
void MiddleType::setInner(std::string const& value)
{
m_Inner = value;
}
} // namespace org::openapitools::server::model

View File

@ -0,0 +1,77 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* MiddleType.h
*
*
*/
#ifndef MiddleType_H_
#define MiddleType_H_
#include <string>
#include <nlohmann/json.hpp>
namespace org::openapitools::server::model
{
/// <summary>
///
/// </summary>
class MiddleType
{
public:
MiddleType();
virtual ~MiddleType() = default;
/// <summary>
/// Validate the current data in the model. Throws a ValidationException on failure.
/// </summary>
void validate() const;
/// <summary>
/// Validate the current data in the model. Returns false on error and writes an error
/// message into the given stringstream.
/// </summary>
bool validate(std::stringstream& msg) const;
/// <summary>
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
/// Not meant to be called outside that case.
/// </summary>
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
bool operator==(const MiddleType& rhs) const;
bool operator!=(const MiddleType& rhs) const;
/////////////////////////////////////////////
/// MiddleType members
/// <summary>
///
/// </summary>
std::string getInner() const;
void setInner(std::string const& value);
friend void to_json(nlohmann::json& j, const MiddleType& o);
friend void from_json(const nlohmann::json& j, MiddleType& o);
protected:
std::string m_Inner;
};
} // namespace org::openapitools::server::model
#endif /* MiddleType_H_ */

View File

@ -0,0 +1,94 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "OuterType.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
OuterType::OuterType()
{
}
void OuterType::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool OuterType::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool OuterType::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "OuterType" : pathPrefix;
if (!m_Middle.validate(msg, _pathPrefix + ".middle")) {
msg << _pathPrefix << ": Middle is invalid;";
success = false;
}
return success;
}
bool OuterType::operator==(const OuterType& rhs) const
{
return
(getMiddle() == rhs.getMiddle())
;
}
bool OuterType::operator!=(const OuterType& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const OuterType& o)
{
j = nlohmann::json::object();
j["middle"] = o.m_Middle;
}
void from_json(const nlohmann::json& j, OuterType& o)
{
j.at("middle").get_to(o.m_Middle);
}
org::openapitools::server::model::MiddleType OuterType::getMiddle() const
{
return m_Middle;
}
void OuterType::setMiddle(org::openapitools::server::model::MiddleType const& value)
{
m_Middle = value;
}
} // namespace org::openapitools::server::model

View File

@ -0,0 +1,77 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* OuterType.h
*
*
*/
#ifndef OuterType_H_
#define OuterType_H_
#include "MiddleType.h"
#include <nlohmann/json.hpp>
namespace org::openapitools::server::model
{
/// <summary>
///
/// </summary>
class OuterType
{
public:
OuterType();
virtual ~OuterType() = default;
/// <summary>
/// Validate the current data in the model. Throws a ValidationException on failure.
/// </summary>
void validate() const;
/// <summary>
/// Validate the current data in the model. Returns false on error and writes an error
/// message into the given stringstream.
/// </summary>
bool validate(std::stringstream& msg) const;
/// <summary>
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
/// Not meant to be called outside that case.
/// </summary>
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
bool operator==(const OuterType& rhs) const;
bool operator!=(const OuterType& rhs) const;
/////////////////////////////////////////////
/// OuterType members
/// <summary>
///
/// </summary>
org::openapitools::server::model::MiddleType getMiddle() const;
void setMiddle(org::openapitools::server::model::MiddleType const& value);
friend void to_json(nlohmann::json& j, const OuterType& o);
friend void from_json(const nlohmann::json& j, OuterType& o);
protected:
org::openapitools::server::model::MiddleType m_Middle;
};
} // namespace org::openapitools::server::model
#endif /* OuterType_H_ */

View File

@ -0,0 +1,43 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>CppPistacheServerTests_container_type_import</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>C++ Pistache Petstore Server (Container Type Import)</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>build-pistache</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./build_petstore.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,3 @@
build/
external/
pistache/

View File

@ -2,7 +2,7 @@
# build C++ pistache petstore
#
mkdir build
mkdir -p build
cd build
cmake ..
make
make -j

View File

@ -1,14 +0,0 @@
#!/bin/bash
# ref: http://pistache.io/quickstart#installing-pistache
#
echo "Installing Pistache ..."
git clone https://github.com/oktal/pistache.git || true
cd pistache || (echo "Cannot find git clone pistache directory"; exit 1)
git submodule update --init
mkdir -p build
cd build || (echo "Cannot find build directory"; exit 1)
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
meson

View File

@ -1,101 +0,0 @@
/**
* 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 (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "Inline_object.h"
namespace org {
namespace openapitools {
namespace server {
namespace model {
Inline_object::Inline_object()
{
m_Name = "";
m_NameIsSet = false;
m_Status = "";
m_StatusIsSet = false;
}
Inline_object::~Inline_object()
{
}
void Inline_object::validate()
{
// TODO: implement validation
}
void to_json(nlohmann::json& j, const Inline_object& o)
{
j = nlohmann::json();
if(o.nameIsSet())
j["name"] = o.m_Name;
if(o.statusIsSet())
j["status"] = o.m_Status;
}
void from_json(const nlohmann::json& j, Inline_object& o)
{
if(j.find("name") != j.end())
{
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
}
if(j.find("status") != j.end())
{
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
}
}
std::string Inline_object::getName() const
{
return m_Name;
}
void Inline_object::setName(std::string const& value)
{
m_Name = value;
m_NameIsSet = true;
}
bool Inline_object::nameIsSet() const
{
return m_NameIsSet;
}
void Inline_object::unsetName()
{
m_NameIsSet = false;
}
std::string Inline_object::getStatus() const
{
return m_Status;
}
void Inline_object::setStatus(std::string const& value)
{
m_Status = value;
m_StatusIsSet = true;
}
bool Inline_object::statusIsSet() const
{
return m_StatusIsSet;
}
void Inline_object::unsetStatus()
{
m_StatusIsSet = false;
}
}
}
}
}

View File

@ -1,73 +0,0 @@
/**
* 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 (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Inline_object.h
*
*
*/
#ifndef Inline_object_H_
#define Inline_object_H_
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
namespace server {
namespace model {
/// <summary>
///
/// </summary>
class Inline_object
{
public:
Inline_object();
virtual ~Inline_object();
void validate();
/////////////////////////////////////////////
/// Inline_object members
/// <summary>
/// Updated name of the pet
/// </summary>
std::string getName() const;
void setName(std::string const& value);
bool nameIsSet() const;
void unsetName();
/// <summary>
/// Updated status of the pet
/// </summary>
std::string getStatus() const;
void setStatus(std::string const& value);
bool statusIsSet() const;
void unsetStatus();
friend void to_json(nlohmann::json& j, const Inline_object& o);
friend void from_json(const nlohmann::json& j, Inline_object& o);
protected:
std::string m_Name;
bool m_NameIsSet;
std::string m_Status;
bool m_StatusIsSet;
};
}
}
}
}
#endif /* Inline_object_H_ */

View File

@ -1,100 +0,0 @@
/**
* 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 (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "Inline_object_1.h"
namespace org {
namespace openapitools {
namespace server {
namespace model {
Inline_object_1::Inline_object_1()
{
m_AdditionalMetadata = "";
m_AdditionalMetadataIsSet = false;
m_fileIsSet = false;
}
Inline_object_1::~Inline_object_1()
{
}
void Inline_object_1::validate()
{
// TODO: implement validation
}
void to_json(nlohmann::json& j, const Inline_object_1& o)
{
j = nlohmann::json();
if(o.additionalMetadataIsSet())
j["additionalMetadata"] = o.m_AdditionalMetadata;
if(o.fileIsSet())
j["file"] = o.m_file;
}
void from_json(const nlohmann::json& j, Inline_object_1& o)
{
if(j.find("additionalMetadata") != j.end())
{
j.at("additionalMetadata").get_to(o.m_AdditionalMetadata);
o.m_AdditionalMetadataIsSet = true;
}
if(j.find("file") != j.end())
{
j.at("file").get_to(o.m_file);
o.m_fileIsSet = true;
}
}
std::string Inline_object_1::getAdditionalMetadata() const
{
return m_AdditionalMetadata;
}
void Inline_object_1::setAdditionalMetadata(std::string const& value)
{
m_AdditionalMetadata = value;
m_AdditionalMetadataIsSet = true;
}
bool Inline_object_1::additionalMetadataIsSet() const
{
return m_AdditionalMetadataIsSet;
}
void Inline_object_1::unsetAdditionalMetadata()
{
m_AdditionalMetadataIsSet = false;
}
std::string Inline_object_1::getFile() const
{
return m_file;
}
void Inline_object_1::setFile(std::string const& value)
{
m_file = value;
m_fileIsSet = true;
}
bool Inline_object_1::fileIsSet() const
{
return m_fileIsSet;
}
void Inline_object_1::unsetfile()
{
m_fileIsSet = false;
}
}
}
}
}

View File

@ -1,73 +0,0 @@
/**
* 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 (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Inline_object_1.h
*
*
*/
#ifndef Inline_object_1_H_
#define Inline_object_1_H_
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
namespace server {
namespace model {
/// <summary>
///
/// </summary>
class Inline_object_1
{
public:
Inline_object_1();
virtual ~Inline_object_1();
void validate();
/////////////////////////////////////////////
/// Inline_object_1 members
/// <summary>
/// Additional data to pass to server
/// </summary>
std::string getAdditionalMetadata() const;
void setAdditionalMetadata(std::string const& value);
bool additionalMetadataIsSet() const;
void unsetAdditionalMetadata();
/// <summary>
/// file to upload
/// </summary>
std::string getFile() const;
void setFile(std::string const& value);
bool fileIsSet() const;
void unsetfile();
friend void to_json(nlohmann::json& j, const Inline_object_1& o);
friend void from_json(const nlohmann::json& j, Inline_object_1& o);
protected:
std::string m_AdditionalMetadata;
bool m_AdditionalMetadataIsSet;
std::string m_file;
bool m_fileIsSet;
};
}
}
}
}
#endif /* Inline_object_1_H_ */

View File

@ -26,16 +26,6 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>install-pistache</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./install_pistache.sh</executable>
</configuration>
</execution>
<execution>
<id>build-pistache</id>
<phase>integration-test</phase>