MySQL 9.0.0
Source Code Documentation
json_schema.cc File Reference
#include "sql-common/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 "sql-common/json_syntax_check.h"

Classes

class  Json_schema_validator_impl
 Json_schema_validator_impl is an object that contains a JSON Schema that can be re-used multiple times. More...
 
class  Json_schema_validator_impl::My_remote_schema_document_provider
 This object acts as a handler/callback for the JSON schema validator and is called whenever a schema reference is encountered in the JSON document. More...
 

Functions

static bool parse_json_schema (const char *json_schema_str, size_t json_schema_length, const JsonSchemaErrorHandler &error_handler, const JsonErrorHandler &depth_handler, 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 JsonSchemaErrorHandler &error_handler, const JsonErrorHandler &depth_handler, 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...
 

Function Documentation

◆ 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 JsonSchemaErrorHandler error_handler,
const JsonErrorHandler depth_handler,
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.
error_handlerError handlers to be called when parsing errors occur.
depth_handlerPointer to a function that should handle error occurred when depth is exceeded.
[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 JsonSchemaErrorHandler error_handler,
const JsonErrorHandler depth_handler,
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
error_handlerError handlers to be called when parsing errors occur.
depth_handlerPointer to a function that should handle error occurred when depth is exceeded.
[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.