18 using URI = std::string;
27 [[nodiscard]] std::string
to_str()
const
44 return {str.begin(), str.end()};
50 std::string str{data.begin(), data.end()};
51 auto i = str.find(
' ');
52 if (i == std::string::npos)
54 throw std::logic_error(
"invalid encoding of endpoint key");
56 auto verb = str.substr(0, i);
57 auto uri_path = str.substr(i + 1);
58 return {uri_path, verb};
161 nlohmann::json& schema,
199 redirection_strategy);
245 static constexpr auto ENDPOINTS =
"public:ccf.gov.endpoints";
273 std::function<void(nlohmann::json&,
const Endpoint&)>;
310 const std::string& deprecation_version,
const std::string& replacement);
340 const nlohmann::json& j,
341 std::optional<http_status> status = std::nullopt);
360 template <
typename In,
typename Out>
363 if constexpr (!std::is_same_v<In, void>)
368 [](nlohmann::json& document,
const Endpoint& endpoint) {
370 if (!http_verb.has_value())
376 ds::openapi::add_request_body_schema<In>(
385 if constexpr (!std::is_same_v<Out, void>)
392 [](nlohmann::json& document,
const Endpoint& endpoint) {
394 if (!http_verb.has_value())
399 ds::openapi::add_response_schema<Out>(
429 template <
typename T>
432 return set_auto_schema<typename T::In, typename T::Out>(status);
446 template <
typename T>
448 const std::string& param_name,
453 presence](nlohmann::json& document,
const Endpoint& endpoint) {
455 if (!http_verb.has_value())
461 const auto schema_name = ds::json::schema_name<T>();
462 const auto query_schema = ds::json::build_schema<T>();
464 auto parameter = nlohmann::json::object();
465 parameter[
"name"] = param_name;
466 parameter[
"in"] =
"query";
467 parameter[
"required"] =
469 parameter[
"schema"] = ds::openapi::add_schema_to_components(
471 ds::openapi::add_request_parameter_schema(
472 document, endpoint.
full_uri_path, http_verb.value(), parameter);
499struct formatter<
ccf::endpoints::ForwardingRequired>
501 template <
typename ParseContext>
502 constexpr auto parse(ParseContext& ctx)
507 template <
typename FormatContext>
511 char const* s =
nullptr;
531 throw std::logic_error(
"Unhandled value for ForwardingRequired");
534 return format_to(ctx.out(),
"{}", s);
Definition rest_verb.h:45
std::optional< llhttp_method > get_http_method() const
Definition rest_verb.h:57
const char * c_str() const
Definition rest_verb.h:62
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:718
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:667
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:694
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:790
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:841
void fill_json_schema(nlohmann::json &schema, const InterpreterReusePolicy *policy)
Definition endpoint.cpp:180
RedirectionStrategy
Definition endpoint.h:95
std::string URI
Definition endpoint.h:18
QueryParamPresence
Definition endpoint.h:121
@ RequiredParameter
Definition endpoint.h:122
@ OptionalParameter
Definition endpoint.h:123
Mode
Definition endpoint.h:114
void from_json(const nlohmann::json &j, InterpreterReusePolicy &grp)
Definition endpoint.cpp:161
OperatorFeature
Definition operator_feature.h:10
ForwardingRequired
Definition endpoint.h:69
std::shared_ptr< const Endpoint > EndpointPtr
Definition endpoint.h:494
std::function< void(CommandEndpointContext &ctx, const ccf::TxID &txid)> LocallyCommittedEndpointFunction
Definition endpoint_context.h:66
std::string schema_name(const InterpreterReusePolicy *policy)
Definition endpoint.cpp:174
void to_json(nlohmann::json &j, const InterpreterReusePolicy &grp)
Definition endpoint.cpp:149
std::shared_ptr< const EndpointDefinition > EndpointDefinitionPtr
Definition endpoint.h:240
std::function< void(EndpointContext &args)> EndpointFunction
Definition endpoint_context.h:63
Definition sha256_hash.h:88
ccf::ByteVector SerialisedEntry
Definition serialised_entry.h:8
Definition app_interface.h:14
std::vector< std::shared_ptr< AuthnPolicy > > AuthnPolicies
Definition authentication_types.h:47
llhttp_status http_status
Definition http_status.h:9
Definition endpoint.h:202
EndpointKey dispatch
Definition endpoint.h:205
URI full_uri_path
Full URI path to endpoint, including method prefix.
Definition endpoint.h:208
EndpointProperties properties
Definition endpoint.h:210
std::set< OperatorFeature > required_operator_features
Definition endpoint.h:237
AuthnPolicies authn_policies
Definition endpoint.h:235
virtual ~EndpointDefinition()=default
URI uri_path
URI path to endpoint.
Definition endpoint.h:23
RESTVerb verb
HTTP Verb.
Definition endpoint.h:25
std::string to_str() const
Definition endpoint.h:27
Definition endpoint.h:165
bool openapi_hidden
Definition endpoint.h:177
nlohmann::json openapi
OpenAPI schema for endpoint.
Definition endpoint.h:175
std::string js_module
JavaScript module.
Definition endpoint.h:179
std::string js_function
JavaScript function name.
Definition endpoint.h:181
std::vector< nlohmann::json > authn_policies
Authentication policies.
Definition endpoint.h:173
std::optional< InterpreterReusePolicy > interpreter_reuse
Definition endpoint.h:185
ForwardingRequired forwarding_required
Endpoint forwarding policy.
Definition endpoint.h:169
RedirectionStrategy redirection_strategy
Endpoint redirection policy.
Definition endpoint.h:171
Mode mode
Endpoint mode.
Definition endpoint.h:167
Definition endpoint.h:266
virtual void install(Endpoint &)=0
virtual ~Installer()=default
Definition endpoint.h:259
nlohmann::json result_schema
Definition endpoint.h:280
std::function< void(nlohmann::json &, const Endpoint &)> SchemaBuilderFn
Definition endpoint.h:273
Endpoint & add_query_parameter(const std::string ¶m_name, QueryParamPresence presence=QueryParamPresence::RequiredParameter)
Definition endpoint.h:447
Endpoint & require_operator_feature(OperatorFeature feature)
Definition endpoint.cpp:16
EndpointFunction func
Definition endpoint.h:261
Endpoint & set_openapi_hidden(bool hidden)
Definition endpoint.cpp:10
Endpoint & set_openapi_deprecated_replaced(const std::string &deprecation_version, const std::string &replacement)
Definition endpoint.cpp:124
Endpoint & set_openapi_description(const std::string &description)
Definition endpoint.cpp:106
Endpoint & set_result_schema(const nlohmann::json &j, std::optional< http_status > status=std::nullopt)
Definition endpoint.cpp:46
Endpoint & set_params_schema(const nlohmann::json &j)
Definition endpoint.cpp:22
void install()
Definition endpoint.cpp:135
nlohmann::json params_schema
Definition endpoint.h:279
Endpoint & set_forwarding_required(ForwardingRequired fr)
Definition endpoint.cpp:74
http_status success_status
Definition endpoint.h:278
LocallyCommittedEndpointFunction locally_committed_func
Definition endpoint.h:263
Endpoint & set_openapi_deprecated(bool is_deprecated)
Definition endpoint.cpp:118
Endpoint & set_auto_schema(std::optional< http_status > status=std::nullopt)
Definition endpoint.h:430
Endpoint & set_auto_schema(std::optional< http_status > status=std::nullopt)
Definition endpoint.h:361
bool openapi_hidden
Definition endpoint.h:276
Endpoint & set_redirection_strategy(RedirectionStrategy rs)
Definition endpoint.cpp:93
std::optional< std::string > openapi_summary
Definition endpoint.h:282
std::vector< SchemaBuilderFn > schema_builders
Definition endpoint.h:274
Installer * installer
Definition endpoint.h:270
std::optional< bool > openapi_deprecated
Definition endpoint.h:284
Endpoint & set_locally_committed_function(const LocallyCommittedEndpointFunction &lcf)
Definition endpoint.cpp:99
Endpoint & set_openapi_summary(const std::string &summary)
Definition endpoint.cpp:112
std::optional< std::string > openapi_description
Definition endpoint.h:283
Definition endpoint.h:145
enum ccf::endpoints::InterpreterReusePolicy::Kind kind
bool operator==(const InterpreterReusePolicy &) const =default
Kind
Definition endpoint.h:147
std::string key
Definition endpoint.h:151
static ccf::endpoints::EndpointKey from_serialised(const SerialisedEntry &data)
Definition endpoint.h:47
static SerialisedEntry to_serialised(const ccf::endpoints::EndpointKey &endpoint_key)
Definition endpoint.h:39
Definition blit_serialiser.h:14