forked from loafle/openapi-generator-original
Supports: All OpenAPI 3.x data types: primitives, arrays, enums, nullable/optional fields, nested objects All parameter types: path, query, header, cookie, and combinations Schema composition: allOf (inheritance), oneOf (discriminated unions), anyOf (flexible unions) Security schemes: API key and bearer token authentication Discriminator-based polymorphic deserialization and error handling Provides: Error handling for invalid JSON, type mismatches, missing/unknown discriminator, and parameter validation Build system integration (CMake) for easy compilation and linking with required dependencies Clear build and run instructions for local development and testing Enables comprehensive, real-world validation of generated C++ server code against OpenAPI specifications
106 lines
4.3 KiB
C++
106 lines
4.3 KiB
C++
/**
|
|
* This file is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
* https://openapi-generator.tech
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// System headers
|
|
#include <httplib.h>
|
|
#include <memory>
|
|
#include <variant>
|
|
|
|
// Project headers
|
|
#include "models/ErrorResponse.h"
|
|
#include "models/TestApiKeySecurity200Response.h"
|
|
#include "models/TestBasicSecurity200Response.h"
|
|
#include "models/TestBearerSecurity200Response.h"
|
|
#include "models/TestOAuth2Security200Response.h"
|
|
|
|
namespace api {
|
|
class AuthenticationManager;
|
|
class Security {
|
|
public:
|
|
Security() = default;
|
|
virtual ~Security() = default;
|
|
/**
|
|
* @brief Register all routes for this API
|
|
* @param svr The httplib::Server instance to register routes on
|
|
* @param auth The AuthenticationManager for authentication (optional, defaults to nullptr)
|
|
*/
|
|
void registerRoutes(httplib::Server& svr, std::shared_ptr<AuthenticationManager> auth = nullptr);
|
|
|
|
// ==========================
|
|
// ===== Response types =====
|
|
// ==========================
|
|
|
|
/**
|
|
* @brief Response type for handleGetForSecurityapikey.
|
|
*/
|
|
using SecurityapikeyGetResponse = std::variant<
|
|
models::TestApiKeySecurity200Response ,
|
|
models::ErrorResponse >;
|
|
|
|
/**
|
|
* @brief Response type for handleGetForSecuritybasic.
|
|
*/
|
|
using SecuritybasicGetResponse = std::variant<
|
|
models::TestBasicSecurity200Response ,
|
|
models::ErrorResponse >;
|
|
|
|
/**
|
|
* @brief Response type for handleGetForSecuritybearer.
|
|
*/
|
|
using SecuritybearerGetResponse = std::variant<
|
|
models::TestBearerSecurity200Response ,
|
|
models::ErrorResponse >;
|
|
|
|
/**
|
|
* @brief Response type for handleGetForSecurityoauth2.
|
|
*/
|
|
using Securityoauth2getResponse = std::variant<
|
|
models::TestOAuth2Security200Response ,
|
|
models::ErrorResponse >;
|
|
// ============================================================
|
|
// ===== Pure virtual functions to be handled by the user =====
|
|
// ============================================================
|
|
/**
|
|
* @return SecurityapikeyGetResponse The response type returned by the handler.
|
|
*/
|
|
virtual SecurityapikeyGetResponse handleGetForSecurityapikey()=0;
|
|
|
|
/**
|
|
* @return SecuritybasicGetResponse The response type returned by the handler.
|
|
*/
|
|
virtual SecuritybasicGetResponse handleGetForSecuritybasic()=0;
|
|
|
|
/**
|
|
* @return SecuritybearerGetResponse The response type returned by the handler.
|
|
*/
|
|
virtual SecuritybearerGetResponse handleGetForSecuritybearer()=0;
|
|
|
|
/**
|
|
* @return Securityoauth2getResponse The response type returned by the handler.
|
|
*/
|
|
virtual Securityoauth2getResponse handleGetForSecurityoauth2()=0;
|
|
|
|
private:
|
|
// ========================================
|
|
// ===== Helper function declarations =====
|
|
// ========================================
|
|
void handleSecurityapikeyGetRequest(const httplib::Request& req, httplib::Response& res, std::shared_ptr<AuthenticationManager> auth);
|
|
static void handleSecurityapikeyGetResponse(const SecurityapikeyGetResponse& result, httplib::Response& res);
|
|
void handleSecuritybasicGetRequest(const httplib::Request& req, httplib::Response& res, std::shared_ptr<AuthenticationManager> auth);
|
|
static void handleSecuritybasicGetResponse(const SecuritybasicGetResponse& result, httplib::Response& res);
|
|
void handleSecuritybearerGetRequest(const httplib::Request& req, httplib::Response& res, std::shared_ptr<AuthenticationManager> auth);
|
|
static void handleSecuritybearerGetResponse(const SecuritybearerGetResponse& result, httplib::Response& res);
|
|
void handleSecurityoauth2GetRequest(const httplib::Request& req, httplib::Response& res, std::shared_ptr<AuthenticationManager> auth);
|
|
static void handleSecurityoauth2getResponse(const Securityoauth2getResponse& result, httplib::Response& res);
|
|
static bool performAuthentication(
|
|
const httplib::Request& req,
|
|
std::shared_ptr<AuthenticationManager> auth,
|
|
httplib::Response& res);
|
|
};
|
|
|
|
} // namespace api
|