Skip to content

Commit

Permalink
[WIP] Implement a function to turn absolute schema references into re…
Browse files Browse the repository at this point in the history
…lative

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jan 7, 2025
1 parent 30bdbfd commit 7bc681b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jsonschema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ noa_library(NAMESPACE sourcemeta PROJECT jsontoolkit NAME jsonschema
PRIVATE_HEADERS anchor.h bundle.h resolver.h
walker.h reference.h frame.h error.h unevaluated.h keywords.h
SOURCES jsonschema.cc default_walker.cc frame.cc
anchor.cc resolver.cc walker.cc bundle.cc unevaluated.cc
anchor.cc resolver.cc walker.cc bundle.cc
unevaluated.cc relativize.cc
"${CMAKE_CURRENT_BINARY_DIR}/official_resolver.cc")

if(JSONTOOLKIT_INSTALL)
Expand Down
6 changes: 6 additions & 0 deletions src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto schema_format_compare(const JSON::String &left, const JSON::String &right)
-> bool;

// TODO: Test & document
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto relativize(
JSON &schema, const SchemaWalker &walker, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect = std::nullopt) -> void;

} // namespace sourcemeta::jsontoolkit

#endif
17 changes: 17 additions & 0 deletions src/jsonschema/relativize.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <sourcemeta/jsontoolkit/jsonschema.h>

#include <iostream> // TODO DEBUG

namespace sourcemeta::jsontoolkit {

auto relativize(JSON &schema, const SchemaWalker &walker,
const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect) -> void {
for (const auto &subschema :
SchemaIterator{schema, walker, resolver, default_dialect}) {
sourcemeta::jsontoolkit::stringify(subschema.pointer, std::cerr);
std::cerr << "\n";
}
}

} // namespace sourcemeta::jsontoolkit

0 comments on commit 7bc681b

Please sign in to comment.