From 6f5cbf48c5b51ac9fdd8c316cfb826c7500451a4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 19 Jul 2024 15:06:42 -0400 Subject: [PATCH] Print types for every frame entry in the `frame` command Signed-off-by: Juan Cruz Viotti --- docs/frame.markdown | 14 ++++++++------ src/command_frame.cc | 28 +++++++++++++++++++++++++++- test/frame/pass.sh | 19 +++++++++++++------ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/docs/frame.markdown b/docs/frame.markdown index 4a0e3844..4e3634c7 100644 --- a/docs/frame.markdown +++ b/docs/frame.markdown @@ -32,17 +32,19 @@ reference: ``` ... -(LOCATION) URI: https://example.com#/$defs/string/type - Schema : https://example.com +(POINTER) URI: https://example.com#/$defs/string/type + Type : Static + Root : https://example.com Pointer : /$defs/string/type - Base URI : https://example.com + Base : https://example.com Relative Pointer : /$defs/string/type Dialect : https://json-schema.org/draft/2020-12/schema ... -(LOCATION) URI: https://example.com#/$ref - Schema : https://example.com +(POINTER) URI: https://example.com#/$ref + Type : Static + Root : https://example.com Pointer : /$ref - Base URI : https://example.com + Base : https://example.com Relative Pointer : /$ref Dialect : https://json-schema.org/draft/2020-12/schema ... diff --git a/src/command_frame.cc b/src/command_frame.cc index 96a96df3..03b65fd4 100644 --- a/src/command_frame.cc +++ b/src/command_frame.cc @@ -28,8 +28,34 @@ auto intelligence::jsonschema::cli::frame( .wait(); for (const auto &[key, entry] : frame) { - std::cout << "(LOCATION) URI: "; + switch (entry.type) { + case sourcemeta::jsontoolkit::ReferenceEntryType::Resource: + std::cout << "(LOCATION)"; + break; + case sourcemeta::jsontoolkit::ReferenceEntryType::Anchor: + std::cout << "(ANCHOR)"; + break; + case sourcemeta::jsontoolkit::ReferenceEntryType::Pointer: + std::cout << "(POINTER)"; + break; + default: + // We should never get here + assert(false); + std::cout << "(UNKNOWN)"; + break; + } + + std::cout << " URI: "; std::cout << key.second << "\n"; + + std::cout << " Type : "; + if (key.first == sourcemeta::jsontoolkit::ReferenceType::Dynamic) { + std::cout << "Dynamic"; + } else { + std::cout << "Static"; + } + std::cout << "\n"; + std::cout << " Root : " << entry.root.value_or("") << "\n"; std::cout << " Pointer :"; diff --git a/test/frame/pass.sh b/test/frame/pass.sh index 3554dc92..acf2653f 100755 --- a/test/frame/pass.sh +++ b/test/frame/pass.sh @@ -22,42 +22,49 @@ EOF cat << 'EOF' > "$TMP/expected.txt" (LOCATION) URI: https://example.com + Type : Static Root : https://example.com Pointer : Base : https://example.com Relative Pointer : Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$defs +(POINTER) URI: https://example.com#/$defs + Type : Static Root : https://example.com Pointer : /$defs Base : https://example.com Relative Pointer : /$defs Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$defs/string +(POINTER) URI: https://example.com#/$defs/string + Type : Static Root : https://example.com Pointer : /$defs/string Base : https://example.com Relative Pointer : /$defs/string Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$defs/string/type +(POINTER) URI: https://example.com#/$defs/string/type + Type : Static Root : https://example.com Pointer : /$defs/string/type Base : https://example.com Relative Pointer : /$defs/string/type Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$id +(POINTER) URI: https://example.com#/$id + Type : Static Root : https://example.com Pointer : /$id Base : https://example.com Relative Pointer : /$id Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$ref +(POINTER) URI: https://example.com#/$ref + Type : Static Root : https://example.com Pointer : /$ref Base : https://example.com Relative Pointer : /$ref Dialect : https://json-schema.org/draft/2020-12/schema -(LOCATION) URI: https://example.com#/$schema +(POINTER) URI: https://example.com#/$schema + Type : Static Root : https://example.com Pointer : /$schema Base : https://example.com