forked from loafle/openapi-generator-original
* [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (#2769) Should handle Object.h, AnyType.h correctly. Set.h also tested. - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues - object had an invalid syntax: ':' instead of '::' in types with namespace - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp> - nlohmann::json is excluded from model namespace Tested with custom petstore played, with suggested openapi specs coming from issues #2769, #10266, #14234 ```bash rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel ``` * - Adding to samples/server/petstore cpp-pistache-everything * - .md and FILES missing
107 lines
3.8 KiB
C++
107 lines
3.8 KiB
C++
/**
|
|
* 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.
|
|
*/
|
|
/*
|
|
* 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 "Order.h"
|
|
#include <map>
|
|
#include <string>
|
|
|
|
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 delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
|
void get_inventory_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
|
void get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
|
void place_order_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>
|
|
/// Delete purchase order by ID
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
|
/// </remarks>
|
|
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
|
virtual void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
|
/// <summary>
|
|
/// Returns pet inventories by status
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Returns a map of status codes to quantities
|
|
/// </remarks>
|
|
virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0;
|
|
/// <summary>
|
|
/// Find purchase order by ID
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
|
/// </remarks>
|
|
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
|
virtual void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
|
/// <summary>
|
|
/// Place an order for a pet
|
|
/// </summary>
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// <param name="order">order placed for purchasing the pet</param>
|
|
virtual void place_order(const org::openapitools::server::model::Order &order, Pistache::Http::ResponseWriter &response) = 0;
|
|
|
|
};
|
|
|
|
} // namespace org::openapitools::server::api
|
|
|
|
#endif /* StoreApi_H_ */
|
|
|