Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
Editor

A JSON Schema compatibility layer for code editors. More...

Functions

SOURCEMETA_BLAZE_EDITOR_EXPORT auto sourcemeta::blaze::for_editor (sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, std::string_view default_dialect="") -> void

Detailed Description

A JSON Schema compatibility layer for code editors.

This functionality is included as follows:

#include <sourcemeta/blaze/editor.h>

Function Documentation

◆ for_editor()

SOURCEMETA_BLAZE_EDITOR_EXPORT auto sourcemeta::blaze::for_editor ( sourcemeta::core::JSON & schema,
const sourcemeta::core::SchemaWalker & walker,
const sourcemeta::core::SchemaResolver & resolver,
std::string_view default_dialect = "" )->void

This function aims to transform the schema (in potentially non-strictly compliant manners) to workaround JSON Schema limitations of popular code editors.

Keep in mind that this is not a real solution, but a workaround, and there might be edge cases that we cannot cover. The real solution is for popular editors to fix their JSON Schema language support.

Note that the input schema is expected to be already bundled. Meta-schema declarations may remain external, as this function rewrites those to the base dialect in force at the subschema that declares them.

#include <sourcemeta/core/json.h>
#include <sourcemeta/core/jsonschema.h>
#include <sourcemeta/blaze/editor.h>
// A custom resolver that knows about the referenced schema
static auto test_resolver(std::string_view identifier)
-> sourcemeta::core::SchemaResolverResult {
if (identifier == "https://www.example.com/another") {
return sourcemeta::core::parse_json(R"JSON({
"$id": "https://www.example.com/another",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
})JSON");
} else {
return sourcemeta::core::schema_resolver(identifier);
}
}
auto schema = sourcemeta::core::parse_json(R"JSON({
"$id": "https://www.example.com/schema",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "another"
})JSON");
sourcemeta::core::schema_bundle(schema,
sourcemeta::core::schema_walker, test_resolver);
sourcemeta::core::schema_walker, test_resolver);
SOURCEMETA_BLAZE_EDITOR_EXPORT auto for_editor(sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, std::string_view default_dialect="") -> void