Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement build_api in DynamicJSEndpointRegistry #6247

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ccf/js/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace ccf::js
ccf::endpoints::EndpointDefinitionPtr e,
ccf::endpoints::CommandEndpointContext& endpoint_ctx,
const ccf::TxID& tx_id) override;

void build_api(nlohmann::json& document, kv::ReadOnlyTx& tx) override;
///@}
};
}
38 changes: 38 additions & 0 deletions src/js/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,42 @@ namespace ccf::js
ccf::endpoints::EndpointRegistry::execute_endpoint_locally_committed(
e, endpoint_ctx, tx_id);
}

// Since we do our own dispatch (overriding find_endpoint), make sure we
// describe those operations in the auto-generated OpenAPI
void DynamicJSEndpointRegistry::build_api(
nlohmann::json& document, kv::ReadOnlyTx& tx)
{
ccf::UserEndpointRegistry::build_api(document, tx);

auto endpoints = tx.ro<ccf::endpoints::EndpointsMap>(metadata_map);

endpoints->foreach([&document](const auto& key, const auto& properties) {
const auto http_verb = key.verb.get_http_method();
if (!http_verb.has_value())
{
return true;
}

if (!properties.openapi_hidden)
{
auto& path_op = ds::openapi::path_operation(
ds::openapi::path(
document,
fmt::format(
"/{}{}",
ccf::get_actor_prefix(ccf::ActorsType::users),
key.uri_path)),
http_verb.value(),
false);
if (!properties.openapi.empty())
{
path_op.insert(
properties.openapi.cbegin(), properties.openapi.cend());
}
}

return true;
});
}
}