![]() |
MySQL 8.0.43
Source Code Documentation
|
#include "sql/json_schema.h"#include <my_rapidjson_size_t.h>#include <assert.h>#include <rapidjson/document.h>#include <rapidjson/error/error.h>#include <rapidjson/memorystream.h>#include <rapidjson/reader.h>#include <rapidjson/schema.h>#include <rapidjson/stringbuffer.h>#include <string>#include <utility>#include "my_alloc.h"#include "my_inttypes.h"#include "my_sys.h"#include "mysqld_error.h"#include "sql-common/json_syntax_check.h"#include "sql/sql_exception_handler.h"Functions | |
| static bool | parse_json_schema (const char *json_schema_str, size_t json_schema_length, const char *function_name, rapidjson::Document *schema_document) |
| parse_json_schema will parse a JSON input into a JSON Schema. More... | |
| bool | is_valid_json_schema (const char *document_str, size_t document_length, const char *json_schema_str, size_t json_schema_length, const char *function_name, bool *is_valid, Json_schema_validation_report *validation_report) |
| This function will validate a JSON document against a JSON Schema using the validation provided by rapidjson. More... | |
| unique_ptr_destroy_only< const Json_schema_validator > | create_json_schema_validator (MEM_ROOT *mem_root, const char *json_schema_str, size_t json_schema_length, const char *function_name) |
| Create a Json_schema_validator, allocated on a given MEM_ROOT. More... | |
| unique_ptr_destroy_only< const Json_schema_validator > create_json_schema_validator | ( | MEM_ROOT * | mem_root, |
| const char * | json_schema_str, | ||
| size_t | json_schema_length, | ||
| const char * | function_name | ||
| ) |
Create a Json_schema_validator, allocated on a given MEM_ROOT.
| mem_root | The MEM_ROOT to allocate the validator on |
| json_schema_str | A pointer to the JSON Schema |
| json_schema_length | The length of the JSON Schema input |
| function_name | The function name of the caller (to be used in error reporting) |
| nullptr | on error (my_error has been called) |
| bool is_valid_json_schema | ( | const char * | document_str, |
| size_t | document_length, | ||
| const char * | json_schema_str, | ||
| size_t | json_schema_length, | ||
| const char * | function_name, | ||
| bool * | is_valid, | ||
| Json_schema_validation_report * | report | ||
| ) |
This function will validate a JSON document against a JSON Schema using the validation provided by rapidjson.
| document_str | A pointer to the JSON document to be validated. | |
| document_length | The length of the JSON document to be validated. | |
| json_schema_str | A pointer to the JSON Schema. | |
| json_schema_length | The length of the JSON Schema. | |
| function_name | The name of the SQL function calling this function. Used in error reporting. | |
| [out] | is_valid | A variable containing the result of the validation. If true, the JSON document is valid according to the given JSON Schema. |
| [out] | report | A structure containing a detailed report from the validation. Is only populated if is_valid is set to "false". Can be nullptr if a detailed report isn't needed. |
| true | if anything went wrong (like parsing the JSON inputs). my_error has been called with an appropriate error message. |
| false | if the validation succeeded. The result of the validation can be found in the output variable "is_valid". |
|
static |
parse_json_schema will parse a JSON input into a JSON Schema.
If the input isn't a valid JSON, or if the JSON is too deeply nested, an error will be returned to the user.
| json_schema_str | A pointer to the JSON Schema input | |
| json_schema_length | The length of the JSON Schema input | |
| function_name | The function name of the caller (to be used in error reporting) | |
| [out] | schema_document | An object where the JSON Schema will be put. This variable MUST be initialized. |
| true | on error (my_error has been called) |
| false | on success. The JSON Schema can be found in the output parameter schema_document. |