1616
1717class ActionDefault_v1 : public sourcemeta ::one::Action {
1818public:
19- ActionDefault_v1 (const std::filesystem::path &base,
20- const sourcemeta::core::URITemplateRouterView &router,
21- const sourcemeta::core::URITemplateRouter::Identifier)
22- : sourcemeta::one::Action{base, router.base_path ()} {}
19+ ActionDefault_v1 (
20+ const std::filesystem::path &base,
21+ const sourcemeta::core::URITemplateRouterView &router,
22+ const sourcemeta::core::URITemplateRouter::Identifier identifier)
23+ : sourcemeta::one::Action{base, router.base_path ()} {
24+ // TODO: This implies the API is mounted
25+ this ->error_schema_ =
26+ std::string{this ->base_path ()} + " /self/v1/schemas/api/error" ;
27+
28+ router.arguments (identifier, [this ](const auto &key, const auto &value) {
29+ if (key == " errorSchema" ) {
30+ this ->error_schema_ = std::get<std::string_view>(value);
31+ }
32+ });
33+ }
2334
2435 auto run (const std::span<std::string_view>,
2536 sourcemeta::one::HTTPRequest &request,
@@ -31,8 +42,7 @@ class ActionDefault_v1 : public sourcemeta::one::Action {
3142 path[this ->base_path ().size ()] != ' /' )) {
3243 sourcemeta::one::json_error (
3344 request, response, sourcemeta::one::STATUS_NOT_FOUND, " not-found" ,
34- " There is nothing at this URL" ,
35- std::string{this ->base_path ()} + " /self/v1/schemas/api/error" );
45+ " There is nothing at this URL" , this ->error_schema_ );
3646 return ;
3747 }
3848
@@ -48,27 +58,26 @@ class ActionDefault_v1 : public sourcemeta::one::Action {
4858 ActionServeMetapackFile_v1::serve (
4959 this ->base () / " explorer" / " %" / " directory-html.metapack" ,
5060 sourcemeta::one::STATUS_OK, false , {}, {}, request, response,
51- this ->base_path () );
61+ this ->error_schema_ );
5262 return ;
5363 } else if (request.method () == " get" || request.method () == " head" ) {
5464 sourcemeta::one::json_error (
5565 request, response, sourcemeta::one::STATUS_NOT_FOUND, " not-found" ,
56- " There is nothing at this URL" ,
57- std::string{this ->base_path ()} + " /self/v1/schemas/api/error" );
66+ " There is nothing at this URL" , this ->error_schema_ );
5867 return ;
5968 } else {
6069 sourcemeta::one::json_error (
6170 request, response, sourcemeta::one::STATUS_METHOD_NOT_ALLOWED,
6271 " method-not-allowed" , " This HTTP method is invalid for this URL" ,
63- std::string{ this ->base_path ()} + " /self/v1/schemas/api/error " );
72+ this ->error_schema_ );
6473 return ;
6574 }
6675 }
6776
6877 if (path.ends_with (" .json" )) {
6978 ActionJSONSchemaServe_v1::serve (this ->base (),
7079 path.substr (0 , path.size () - 5 ), request,
71- response, this ->base_path () );
80+ response, this ->error_schema_ );
7281 return ;
7382 }
7483
@@ -80,31 +89,34 @@ class ActionDefault_v1 : public sourcemeta::one::Action {
8089 ActionServeMetapackFile_v1::serve (
8190 explorer_path / " schema-html.metapack" ,
8291 sourcemeta::one::STATUS_OK, false , {}, {}, request, response,
83- this ->base_path () );
92+ this ->error_schema_ );
8493 } else {
8594 explorer_path /= " directory-html.metapack" ;
8695 if (std::filesystem::exists (explorer_path)) {
8796 ActionServeMetapackFile_v1::serve (
8897 explorer_path, sourcemeta::one::STATUS_OK, false , {}, {},
89- request, response, this ->base_path () );
98+ request, response, this ->error_schema_ );
9099 } else {
91100 ActionServeMetapackFile_v1::serve (
92101 this ->base () / " explorer" / " %" / " 404.metapack" ,
93102 sourcemeta::one::STATUS_NOT_FOUND, false , {}, {}, request,
94- response, this ->base_path () );
103+ response, this ->error_schema_ );
95104 }
96105 }
97106 } else {
98107 ActionJSONSchemaServe_v1::serve (this ->base (), path, request, response,
99- this ->base_path () );
108+ this ->error_schema_ );
100109 }
101110 } else {
102111 sourcemeta::one::json_error (
103112 request, response, sourcemeta::one::STATUS_NOT_FOUND, " not-found" ,
104- " There is nothing at this URL" ,
105- std::string{this ->base_path ()} + " /self/v1/schemas/api/error" );
113+ " There is nothing at this URL" , this ->error_schema_ );
106114 }
107115 }
116+
117+ private:
118+ // TODO: This should be a string view
119+ std::string error_schema_;
108120};
109121
110122#endif
0 commit comments