Commit ac629ba5 authored by octal's avatar octal

Router::initFromDescription now checking if a given path has been bound to a handler

parent f33fae22
...@@ -40,7 +40,7 @@ public: ...@@ -40,7 +40,7 @@ public:
Rest::Swagger swagger(desc); Rest::Swagger swagger(desc);
swagger swagger
.uiPath("/doc") .uiPath("/doc")
.uiDirectory("/home/octal/code/web/swagger-ui-2.1.4/dist/") .uiDirectory("/home/octal/code/web/swagger-ui-2.1.4/dist")
.apiPath("/banker-api.json") .apiPath("/banker-api.json")
.install(router); .install(router);
......
...@@ -276,6 +276,10 @@ struct Path { ...@@ -276,6 +276,10 @@ struct Path {
static std::string swaggerFormat(const std::string& path); static std::string swaggerFormat(const std::string& path);
bool isBound() const {
return handler != nullptr;
}
template<typename Writer> template<typename Writer>
void serialize(Writer& writer) const { void serialize(Writer& writer) const {
auto serializeMimes = [&](const char* name, const std::vector<Http::Mime::MediaType>& mimes) { auto serializeMimes = [&](const char* name, const std::vector<Http::Mime::MediaType>& mimes) {
......
...@@ -243,6 +243,12 @@ Router::initFromDescription(const Rest::Description& desc) { ...@@ -243,6 +243,12 @@ Router::initFromDescription(const Rest::Description& desc) {
for (auto it = paths.flatBegin(), end = paths.flatEnd(); it != end; ++it) { for (auto it = paths.flatBegin(), end = paths.flatEnd(); it != end; ++it) {
const auto& paths = *it; const auto& paths = *it;
for (const auto& path: paths) { for (const auto& path: paths) {
if (!path.isBound()) {
std::ostringstream oss;
oss << "Path '" << path.value << "' is not bound";
throw std::runtime_error(oss.str());
}
addRoute(path.method, std::move(path.value), std::move(path.handler)); addRoute(path.method, std::move(path.value), std::move(path.handler));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment