17 using URI = std::string;
49 std::string str{data.begin(), data.end()};
50 auto i = str.find(
' ');
51 if (i == std::string::npos)
53 throw std::logic_error(
"invalid encoding of endpoint key");
55 auto verb = str.substr(0, i);
56 auto uri_path = str.substr(i + 1);
57 return {uri_path, verb};
195 redirection_strategy);
239 static constexpr auto ENDPOINTS =
"public:ccf.gov.endpoints";
266 std::function<void(nlohmann::json&,
const Endpoint&)>;
303 const std::string& deprecation_version,
const std::string& replacement);
325 const nlohmann::json& j,
326 std::optional<http_status> status = std::nullopt);
344 template <
typename In,
typename Out>
347 if constexpr (!std::is_same_v<In, void>)
352 [](nlohmann::json& document,
const Endpoint& endpoint) {
354 if (!http_verb.has_value())
360 ds::openapi::add_request_body_schema<In>(
369 if constexpr (!std::is_same_v<Out, void>)
376 [](nlohmann::json& document,
const Endpoint& endpoint) {
378 if (!http_verb.has_value())
383 ds::openapi::add_response_schema<Out>(
413 template <
typename T>
416 return set_auto_schema<typename T::In, typename T::Out>(status);
430 template <
typename T>
432 const std::string& param_name,
437 presence](nlohmann::json& document,
const Endpoint& endpoint) {
439 if (!http_verb.has_value())
445 const auto schema_name = ds::json::schema_name<T>();
446 const auto query_schema = ds::json::build_schema<T>();
448 auto parameter = nlohmann::json::object();
449 parameter[
"name"] = param_name;
450 parameter[
"in"] =
"query";
452 parameter[
"schema"] = ds::openapi::add_schema_to_components(
454 ds::openapi::add_request_parameter_schema(
455 document, endpoint.
full_uri_path, http_verb.value(), parameter);
479struct formatter<
ccf::endpoints::ForwardingRequired>
481 template <
typename ParseContext>
482 constexpr auto parse(ParseContext& ctx)
487 template <
typename FormatContext>
511 throw std::logic_error(
"Unhandled value for ForwardingRequired");
514 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:714
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:663
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:690
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:786
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:837
std::string URI
Definition endpoint.h:17
std::string schema_name(const InterpreterReusePolicy *)
Definition endpoint.cpp:161
QueryParamPresence
Definition endpoint.h:120
@ RequiredParameter
Definition endpoint.h:121
@ OptionalParameter
Definition endpoint.h:122
Mode
Definition endpoint.h:113
void from_json(const nlohmann::json &j, InterpreterReusePolicy &grp)
Definition endpoint.cpp:148
std::shared_ptr< const Endpoint > EndpointPtr
Definition endpoint.h:474
void fill_json_schema(nlohmann::json &schema, const InterpreterReusePolicy *)
Definition endpoint.cpp:167
RedirectionStrategy
Definition endpoint.h:94
std::function< void(CommandEndpointContext &ctx, const ccf::TxID &txid)> LocallyCommittedEndpointFunction
Definition endpoint_context.h:66
void to_json(nlohmann::json &j, const InterpreterReusePolicy &grp)
Definition endpoint.cpp:136
std::shared_ptr< const EndpointDefinition > EndpointDefinitionPtr
Definition endpoint.h:234
std::function< void(EndpointContext &args)> EndpointFunction
Definition endpoint_context.h:63
ForwardingRequired
Definition endpoint.h:68
Definition sha256_hash.h:80
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:198
EndpointKey dispatch
Definition endpoint.h:201
URI full_uri_path
Full URI path to endpoint, including method prefix.
Definition endpoint.h:204
EndpointProperties properties
Definition endpoint.h:206
AuthnPolicies authn_policies
Definition endpoint.h:231
virtual ~EndpointDefinition()=default
URI uri_path
URI path to endpoint.
Definition endpoint.h:22
RESTVerb verb
HTTP Verb.
Definition endpoint.h:24
std::string to_str() const
Definition endpoint.h:26
Definition endpoint.h:161
bool openapi_hidden
Definition endpoint.h:173
nlohmann::json openapi
OpenAPI schema for endpoint.
Definition endpoint.h:171
std::string js_module
JavaScript module.
Definition endpoint.h:175
std::string js_function
JavaScript function name.
Definition endpoint.h:177
std::vector< nlohmann::json > authn_policies
Authentication policies.
Definition endpoint.h:169
std::optional< InterpreterReusePolicy > interpreter_reuse
Definition endpoint.h:181
ForwardingRequired forwarding_required
Endpoint forwarding policy.
Definition endpoint.h:165
RedirectionStrategy redirection_strategy
Endpoint redirection policy.
Definition endpoint.h:167
Mode mode
Endpoint mode.
Definition endpoint.h:163
Definition endpoint.h:260
virtual void install(Endpoint &)=0
Definition endpoint.h:253
nlohmann::json result_schema
Definition endpoint.h:273
std::function< void(nlohmann::json &, const Endpoint &)> SchemaBuilderFn
Definition endpoint.h:266
Endpoint & add_query_parameter(const std::string ¶m_name, QueryParamPresence presence=RequiredParameter)
Definition endpoint.h:431
EndpointFunction func
Definition endpoint.h:255
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:111
Endpoint & set_openapi_description(const std::string &description)
Definition endpoint.cpp:93
Endpoint & set_result_schema(const nlohmann::json &j, std::optional< http_status > status=std::nullopt)
Definition endpoint.cpp:40
Endpoint & set_params_schema(const nlohmann::json &j)
Definition endpoint.cpp:16
void install()
Definition endpoint.cpp:122
nlohmann::json params_schema
Definition endpoint.h:272
Endpoint & set_forwarding_required(ForwardingRequired fr)
Definition endpoint.cpp:68
http_status success_status
Definition endpoint.h:271
LocallyCommittedEndpointFunction locally_committed_func
Definition endpoint.h:257
Endpoint & set_openapi_deprecated(bool is_deprecated)
Definition endpoint.cpp:105
Endpoint & set_auto_schema(std::optional< http_status > status=std::nullopt)
Definition endpoint.h:414
Endpoint & set_auto_schema(std::optional< http_status > status=std::nullopt)
Definition endpoint.h:345
bool openapi_hidden
Definition endpoint.h:269
Endpoint & set_redirection_strategy(RedirectionStrategy rs)
Definition endpoint.cpp:87
std::optional< std::string > openapi_summary
Definition endpoint.h:275
std::vector< SchemaBuilderFn > schema_builders
Definition endpoint.h:267
Installer * installer
Definition endpoint.h:263
std::optional< bool > openapi_deprecated
Definition endpoint.h:277
Endpoint & set_openapi_summary(const std::string &summary)
Definition endpoint.cpp:99
std::optional< std::string > openapi_description
Definition endpoint.h:276
Definition endpoint.h:144
bool operator==(const InterpreterReusePolicy &) const =default
@ KeyBased
Definition endpoint.h:147
enum ccf::endpoints::InterpreterReusePolicy::@0 kind
std::string key
Definition endpoint.h:150
static ccf::endpoints::EndpointKey from_serialised(const SerialisedEntry &data)
Definition endpoint.h:46
static SerialisedEntry to_serialised(const ccf::endpoints::EndpointKey &endpoint_key)
Definition endpoint.h:38
Definition blit_serialiser.h:14