MySQL 8.4.2
Source Code Documentation
json_schema.cc File Reference
#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_validatorcreate_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...
 

Function Documentation

◆ create_json_schema_validator()

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.

Parameters
mem_rootThe MEM_ROOT to allocate the validator on
json_schema_strA pointer to the JSON Schema
json_schema_lengthThe length of the JSON Schema input
function_nameThe function name of the caller (to be used in error reporting)
Return values
nullptron error (my_error has been called)

◆ is_valid_json_schema()

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.

Parameters
document_strA pointer to the JSON document to be validated.
document_lengthThe length of the JSON document to be validated.
json_schema_strA pointer to the JSON Schema.
json_schema_lengthThe length of the JSON Schema.
function_nameThe name of the SQL function calling this function. Used in error reporting.
[out]is_validA variable containing the result of the validation. If true, the JSON document is valid according to the given JSON Schema.
[out]reportA 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.
Return values
trueif anything went wrong (like parsing the JSON inputs). my_error has been called with an appropriate error message.
falseif the validation succeeded. The result of the validation can be found in the output variable "is_valid".

◆ parse_json_schema()

static bool parse_json_schema ( const char *  json_schema_str,
size_t  json_schema_length,
const char *  function_name,
rapidjson::Document *  schema_document 
)
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.

Parameters
json_schema_strA pointer to the JSON Schema input
json_schema_lengthThe length of the JSON Schema input
function_nameThe function name of the caller (to be used in error reporting)
[out]schema_documentAn object where the JSON Schema will be put. This variable MUST be initialized.
Return values
trueon error (my_error has been called)
falseon success. The JSON Schema can be found in the output parameter schema_document.