ORE Studio 0.0.4
Loading...
Searching...
No Matches
endpoint_registry.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_HTTP_OPENAPI_ENDPOINT_REGISTRY_HPP
21#define ORES_HTTP_OPENAPI_ENDPOINT_REGISTRY_HPP
22
23#include <string>
24#include <vector>
25#include "ores.http.api/domain/route.hpp"
26#include "ores.logging/make_logger.hpp"
27
28namespace ores::http::openapi {
29
33struct api_info final {
34 std::string title = "OreStudio HTTP API";
35 std::string description = "RESTful API for OreStudio";
36 std::string version = "1.0.0";
37 std::string contact_name;
38 std::string contact_email;
39 std::string license_name = "GPL-3.0";
40 std::string license_url;
41};
42
46struct server_info final {
47 std::string url;
48 std::string description;
49};
50
54class endpoint_registry final {
55public:
57
61 void set_info(const api_info& info);
62
66 void add_server(const server_info& server);
67
71 void register_route(const domain::route& route);
72
76 std::string generate_openapi_json() const;
77
81 std::string generate_swagger_ui_html(const std::string& spec_url = "/openapi.json") const;
82
83private:
84 inline static std::string_view logger_name = "ores.http.openapi.endpoint_registry";
85
86 static auto& lg() {
87 using namespace ores::logging;
88 static auto instance = make_logger(logger_name);
89 return instance;
90 }
91
92 std::string method_to_string(domain::http_method method) const;
93
94 api_info info_;
95 std::vector<server_info> servers_;
96 std::vector<domain::route> routes_;
97};
98
99}
100
101#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Represents a registered route with pattern matching.
Definition route.hpp:83
API information for OpenAPI spec.
Definition endpoint_registry.hpp:33
Server information for OpenAPI spec.
Definition endpoint_registry.hpp:46
Registry for API endpoints that generates OpenAPI specification.
Definition endpoint_registry.hpp:54
void add_server(const server_info &server)
Adds a server to the spec.
std::string generate_swagger_ui_html(const std::string &spec_url="/openapi.json") const
Generates a minimal Swagger UI HTML page.
std::string generate_openapi_json() const
Generates the OpenAPI 3.0 JSON specification.
void set_info(const api_info &info)
Sets the API information.
void register_route(const domain::route &route)
Registers a route for documentation.