23#include <seastar/json/json_elements.hh>
24#include <seastar/json/formatter.hh>
25#include <seastar/http/routes.hh>
26#include <seastar/http/transformers.hh>
28#include <seastar/util/noncopyable_function.hh>
38 void register_params() {
40 add(&description,
"description");
51 description = e.description;
54 api_doc& operator=(
const T& e) {
56 description = e.description;
61 description = e.description;
71 void register_params() {
72 add(&apiVersion,
"apiVersion");
73 add(&swaggerVersion,
"swaggerVersion");
79 swaggerVersion =
"1.2";
83 : apiVersion{e.apiVersion}
84 , swaggerVersion{e.swaggerVersion}
103 sstring _file_directory;
108 const sstring& base_path)
109 : _base_path(base_path), _file_directory(file_directory), _routes(
114 _routes.
put(GET, _base_path, h);
123 const sstring& base_path)
129 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep)
override {
130 rep->_content = json::formatter::to_json(_docs);
132 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
135 void reg(
const sstring& api,
const sstring& description,
136 const sstring& alternative_path =
"") {
138 doc.description = description;
139 doc.path =
"/" + api;
140 _docs.apis.push(doc);
142 (alternative_path ==
"") ?
143 _file_directory + api +
".json" : alternative_path;
146 _routes.
put(GET, _base_path +
"/" + api, index);
152 sstring _file_directory;
154 static const sstring DEFAULT_DIR;
155 static const sstring DEFAULT_PATH;
158 const sstring& base_path = DEFAULT_PATH)
159 : _file_directory(file_directory), _base_path(base_path) {
166 const sstring& base_path = DEFAULT_PATH)
170 void set_api_doc(
routes& r) {
174 void register_function(
routes& r,
const sstring& api,
175 const sstring& description,
const sstring& alternative_path =
"") {
180 static_cast<api_registry*
>(h)->reg(api, description, alternative_path);
191doc_entry get_file_reader(sstring file_name);
236 std::vector<doc_entry> _apis;
238 std::vector<doc_entry> _definitions;
244 _apis.emplace_back(std::move(f));
248 _definitions.emplace_back(std::move(f));
256 const sstring& base_path)
262 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep)
override {
264 return _docs.write(std::move(os), std::move(req));
266 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
270 _docs.add_api(std::move(f));
273 virtual void add_definition(doc_entry&& f) {
274 _docs.add_definition(std::move(f));
291 const sstring& base_path = DEFAULT_PATH)
295 void set_api_doc(
routes& r) {
305 auto h = get_register_base(r);
307 h->reg(std::move(f));
322 auto h = get_register_base(r);
324 h->add_definition(std::move(f));
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
An api doc that support swagger version 2.0.
Definition: api_docs.hh:235
Definition: api_docs.hh:252
future< std::unique_ptr< http::reply > > handle(const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
Definition: api_docs.hh:261
Definition: api_docs.hh:100
Definition: api_docs.hh:278
void add_definitions_file(routes &r, const sstring &file)
Definition: api_docs.hh:332
void register_api_file(routes &r, const sstring &api)
register an API
Definition: api_docs.hh:313
void register_function(routes &r, doc_entry &&f)
register a doc_entry This doc_entry can be used to either take the definition from a file or generate...
Definition: api_docs.hh:304
void add_definition(routes &r, doc_entry &&f)
Definition: api_docs.hh:321
Definition: api_docs.hh:150
Definition: api_docs.hh:163
Definition: api_docs.hh:119
future< std::unique_ptr< http::reply > > handle(const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
Definition: api_docs.hh:128
Definition: transformers.hh:44
Definition: file_handler.hh:150
Definition: handlers.hh:42
handler_base * get_exact_match(operation_type type, const sstring &url) const
Definition: routes.hh:161
routes & put(operation_type type, const sstring &url, handler_base *handler)
Definition: json_elements.hh:160
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: noncopyable_function.hh:37
Definition: api_docs.hh:34
Definition: api_docs.hh:66
Definition: json_elements.hh:228
virtual void add(json_base_element *element, std::string name, bool mandatory=false)