]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/http/api_docs.cc
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright 2015 Cloudius Systems
22 #include <seastar/http/api_docs.hh>
23 #include <seastar/http/handlers.hh>
24 #include <seastar/json/formatter.hh>
25 #include <seastar/http/transformers.hh>
26 #include <seastar/core/fstream.hh>
27 #include <seastar/core/seastar.hh>
28 #include <seastar/http/transformers.hh>
29 #include <seastar/core/loop.hh>
37 const sstring
api_registry_builder_base::DEFAULT_PATH
= "/api-doc";
38 const sstring
api_registry_builder_base::DEFAULT_DIR
= ".";
40 doc_entry
get_file_reader(sstring file_name
) {
41 return [file_name
] (output_stream
<char>& os
) {
42 return open_file_dma(file_name
, open_flags::ro
).then([&os
] (file f
) mutable {
43 return do_with(input_stream
<char>(make_file_input_stream(std::move(f
))), [&os
](input_stream
<char>& is
) {
44 return copy(is
, os
).then([&is
] {
52 future
<> api_docs_20::write(output_stream
<char>&& os
, std::unique_ptr
<request
> req
) {
53 return do_with(output_stream
<char>(_transform
.transform(std::move(req
), "", std::move(os
))), [this] (output_stream
<char>& os
) {
54 return do_for_each(_apis
, [&os
](doc_entry
& api
) {
57 return os
.write("},\"definitions\": {");
59 return do_for_each(_definitions
, [&os
](doc_entry
& api
) {
63 return os
.write("}}");