-
-
Notifications
You must be signed in to change notification settings - Fork 12
Use entry points to support the linter rules for standalone schemas #608
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,32 +49,62 @@ auto ValidExamples::condition( | |
| } | ||
| } | ||
|
|
||
| std::size_t cursor{0}; | ||
|
|
||
| if (frame.standalone()) { | ||
| const auto base{frame.uri(location.pointer)}; | ||
| assert(base.has_value()); | ||
jviotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const auto schema_template{compile(root, walker, resolver, this->compiler_, | ||
| frame, base.value().get(), | ||
| Mode::Exhaustive)}; | ||
|
|
||
| for (const auto &example : schema.at("examples").as_array()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This validation loop (lines 58-82) is identical to the one used later in the function (lines 112-132 in the modified file). This violation of the DRY principle increases maintenance burden and the risk of inconsistent behavior if one loop is updated but the other is not. Consider extracting the loop into a helper lambda or private method that accepts the compiled schema and the optional base pointer. Prompt for AI agents |
||
| SimpleOutput output{example}; | ||
| const auto result{this->evaluator_.validate(schema_template, example, | ||
| std::ref(output))}; | ||
| if (!result) { | ||
| std::ostringstream message; | ||
| message << "Invalid example instance at index " << cursor << "\n"; | ||
| for (const auto &entry : output) { | ||
| message << " " << entry.message << "\n"; | ||
| message << " " | ||
| << " at instance location \""; | ||
| sourcemeta::core::stringify(entry.instance_location, message); | ||
| message << "\"\n"; | ||
| message << " " | ||
| << " at evaluate path \""; | ||
| sourcemeta::core::stringify(entry.evaluate_path, message); | ||
| message << "\"\n"; | ||
| } | ||
|
|
||
| return {{{"examples", cursor}}, std::move(message).str()}; | ||
| } | ||
|
|
||
| cursor += 1; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| const auto &root_base_dialect{ | ||
| frame.traverse(frame.root()).value_or(location).get().base_dialect}; | ||
| std::string_view default_id{location.base}; | ||
| if (!sourcemeta::core::identify(root, root_base_dialect).empty() || | ||
| default_id.empty()) { | ||
| // We want to only set a default identifier if the root schema does not | ||
| // have an explicit identifier. Otherwise, we can get into corner case | ||
| // when wrapping the schema | ||
| default_id = ""; | ||
| } | ||
|
|
||
| sourcemeta::core::WeakPointer base; | ||
| const auto subschema{ | ||
| sourcemeta::core::wrap(root, frame, location, resolver, base)}; | ||
| // To avoid bundling twice in vain | ||
| Tweaks tweaks{.assume_bundled = frame.standalone()}; | ||
| const auto schema_template{compile(subschema, walker, resolver, | ||
| this->compiler_, Mode::Exhaustive, | ||
| location.dialect, default_id, "", tweaks)}; | ||
| location.dialect, default_id)}; | ||
|
|
||
| Evaluator evaluator; | ||
| std::size_t cursor{0}; | ||
| for (const auto &example : schema.at("examples").as_array()) { | ||
| SimpleOutput output{example, base}; | ||
| const auto result{ | ||
| evaluator.validate(schema_template, example, std::ref(output))}; | ||
| this->evaluator_.validate(schema_template, example, std::ref(output))}; | ||
| if (!result) { | ||
| std::ostringstream message; | ||
| message << "Invalid example instance at index " << cursor << "\n"; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.