Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print types for every frame entry in the frame command #130

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/frame.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
Expand Down
28 changes: 27 additions & 1 deletion src/command_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ANONYMOUS>")
<< "\n";
std::cout << " Pointer :";
Expand Down
19 changes: 13 additions & 6 deletions test/frame/pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down