-
-
Notifications
You must be signed in to change notification settings - Fork 5
Take most schemas as route arguments #823
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,10 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| router.arguments(identifier, [this](const auto &key, const auto &value) { | ||
| if (key == "mode") { | ||
| this->mode_ = static_cast<EvaluateMode>(std::get<std::int64_t>(value)); | ||
| } else if (key == "responseSchema") { | ||
| this->response_schema_ = std::get<std::string_view>(value); | ||
| } else if (key == "errorSchema") { | ||
| this->error_schema_ = std::get<std::string_view>(value); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -64,12 +68,11 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| request, response, sourcemeta::one::STATUS_METHOD_NOT_ALLOWED, | ||
| "no-template", | ||
| "This schema was not precompiled for schema evaluation", | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| this->error_schema_); | ||
| } else { | ||
| sourcemeta::one::json_error( | ||
| request, response, sourcemeta::one::STATUS_NOT_FOUND, "not-found", | ||
| "There is nothing at this URL", | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| "There is nothing at this URL", this->error_schema_); | ||
| } | ||
|
|
||
| return; | ||
|
|
@@ -92,16 +95,14 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| sourcemeta::one::json_error( | ||
| callback_request, callback_response, | ||
| sourcemeta::one::STATUS_INTERNAL_SERVER_ERROR, | ||
| "uncaught-error", exception.what(), | ||
| std::string{this->base_path()} + | ||
| "/self/v1/schemas/api/error"); | ||
| "uncaught-error", exception.what(), this->error_schema_); | ||
| } | ||
| }); | ||
| } else { | ||
| sourcemeta::one::json_error( | ||
| request, response, sourcemeta::one::STATUS_METHOD_NOT_ALLOWED, | ||
| "method-not-allowed", "This HTTP method is invalid for this URL", | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| this->error_schema_); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -314,15 +315,14 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| sourcemeta::one::json_error( | ||
| request, response, sourcemeta::one::STATUS_PAYLOAD_TOO_LARGE, | ||
| "payload-too-large", "The request body is too large", | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| this->error_schema_); | ||
| return; | ||
| } | ||
|
|
||
| if (body.empty()) { | ||
| sourcemeta::one::json_error( | ||
| request, response, sourcemeta::one::STATUS_BAD_REQUEST, "no-instance", | ||
| "You must pass an instance to validate against", | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| "You must pass an instance to validate against", this->error_schema_); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -331,15 +331,7 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| response.write_status(sourcemeta::one::STATUS_OK); | ||
| response.write_header("Content-Type", "application/json"); | ||
| response.write_header("Access-Control-Allow-Origin", "*"); | ||
| if (mode == EvaluateMode::Trace) { | ||
| sourcemeta::one::write_link_header( | ||
| response, std::string{this->base_path()} + | ||
| "/self/v1/schemas/api/schemas/trace/response"); | ||
| } else { | ||
| sourcemeta::one::write_link_header( | ||
| response, std::string{this->base_path()} + | ||
| "/self/v1/schemas/api/schemas/evaluate/response"); | ||
| } | ||
| sourcemeta::one::write_link_header(response, this->response_schema_); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. src/actions/action_jsonschema_evaluate_v1.h:334: Severity: medium Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
|
|
||
| std::ostringstream payload; | ||
| sourcemeta::core::prettify(result, payload); | ||
|
|
@@ -349,12 +341,13 @@ class ActionJSONSchemaEvaluate_v1 : public sourcemeta::one::Action { | |
| } catch (const std::exception &exception) { | ||
| sourcemeta::one::json_error( | ||
| request, response, sourcemeta::one::STATUS_INTERNAL_SERVER_ERROR, | ||
| "evaluation-error", exception.what(), | ||
| std::string{this->base_path()} + "/self/v1/schemas/api/error"); | ||
| "evaluation-error", exception.what(), this->error_schema_); | ||
| } | ||
| } | ||
|
|
||
| EvaluateMode mode_{EvaluateMode::Standard}; | ||
| std::string_view response_schema_; | ||
| std::string_view error_schema_; | ||
| }; | ||
|
|
||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/actions/action_health_check_v1.h:35:
error_schema_is never defaulted, so iferrorSchemaisn't present in the route arguments (for example, an olderroutes.bin),json_errorwill emit an invalidLink: <>; rel="describedby"header. Consider ensuring a non-empty default (like the priorbase_path()+"/self/v1/schemas/api/error") or validating before callingjson_error.Severity: medium
Other Locations
src/actions/action_not_found_v1.h:33src/actions/action_schema_search_v1.h:45src/actions/action_serve_static_v1.h:39src/actions/action_jsonschema_serve_v1.h:85src/actions/action_serve_schema_artifact_v1.h:41🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.