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";
275 std::function<void(nlohmann::json&,
const Endpoint&)>;
312 const std::string& deprecation_version,
const std::string& replacement);
342 const nlohmann::json& j,
343 std::optional<http_status> status = std::nullopt);
362 template <
typename In,
typename Out>
365 if constexpr (!std::is_same_v<In, void>)
370 [](nlohmann::json& document,
const Endpoint& endpoint) {
372 if (!http_verb.has_value())
378 ds::openapi::add_request_body_schema<In>(
387 if constexpr (!std::is_same_v<Out, void>)
394 [](nlohmann::json& document,
const Endpoint& endpoint) {
396 if (!http_verb.has_value())
401 ds::openapi::add_response_schema<Out>(
431 template <
typename T>
434 return set_auto_schema<typename T::In, typename T::Out>(status);
448 template <
typename T>
450 const std::string& param_name,
455 presence](nlohmann::json& document,
const Endpoint& endpoint) {
457 if (!http_verb.has_value())
463 const auto schema_name = ds::json::schema_name<T>();
464 const auto query_schema = ds::json::build_schema<T>();
466 auto parameter = nlohmann::json::object();
467 parameter[
"name"] = param_name;
468 parameter[
"in"] =
"query";
469 parameter[
"required"] =
471 parameter[
"schema"] = ds::openapi::add_schema_to_components(
473 ds::openapi::add_request_parameter_schema(
474 document, endpoint.
full_uri_path, http_verb.value(), parameter);
501struct formatter<
ccf::endpoints::ForwardingRequired>
503 template <
typename ParseContext>
504 constexpr auto parse(ParseContext& ctx)
509 template <
typename FormatContext>
517 return format_to(ctx.out(),
"sometimes");
521 return format_to(ctx.out(),
"always");
525 return format_to(ctx.out(),
"never");
529 throw std::logic_error(fmt::format(
530 "Unhandled value for ForwardingRequired: {}",
531 static_cast<uint8_t
>(v)));
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:736
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:685
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:712
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:811
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:864
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:496
std::function< void(CommandEndpointContext &ctx, const ccf::TxID &txid)> LocallyCommittedEndpointFunction
Definition endpoint_context.h:69
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:66
Definition sha256_hash.h:88
ccf::ByteVector SerialisedEntry
Definition serialised_entry.h:8
Definition app_interface.h:13
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:268
virtual void install(Endpoint &)=0
virtual ~Installer()=default
Definition endpoint.h:259
nlohmann::json result_schema
Definition endpoint.h:282
std::function< void(nlohmann::json &, const Endpoint &)> SchemaBuilderFn
Definition endpoint.h:275
Endpoint & add_query_parameter(const std::string ¶m_name, QueryParamPresence presence=QueryParamPresence::RequiredParameter)
Definition endpoint.h:449
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:281
Endpoint & set_forwarding_required(ForwardingRequired fr)
Definition endpoint.cpp:74
http_status success_status
Definition endpoint.h:280
LocallyCommittedEndpointFunction locally_committed_func
Definition endpoint.h:265
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:432
Endpoint & set_auto_schema(std::optional< http_status > status=std::nullopt)
Definition endpoint.h:363
bool openapi_hidden
Definition endpoint.h:278
Endpoint & set_redirection_strategy(RedirectionStrategy rs)
Definition endpoint.cpp:93
std::optional< std::string > openapi_summary
Definition endpoint.h:284
std::vector< SchemaBuilderFn > schema_builders
Definition endpoint.h:276
Installer * installer
Definition endpoint.h:272
std::optional< bool > openapi_deprecated
Definition endpoint.h:286
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:285
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