Skip to content

Commit

Permalink
jsoncons::utility::uri -> jsoncons::uri
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 4, 2024
1 parent 63cfd74 commit 1335609
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 87 deletions.
3 changes: 1 addition & 2 deletions doc/ref/jsonschema/make_json_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Returns a [json_schema<Json>](json_schema.md) that represents a compiled JSON Sc
<td>resolve</td>
<td>A function object with the signature of <code>resolve</code> being equivalent to
<pre>
Json fun(const jsoncons::uri& uri) (until 0.178.0)
Json fun(const jsoncons::utility::uri& uri) (since 1.0.0)
Json fun(const jsoncons::uri& uri)
</pre>
If unable to resolve the resource, it should return <code>Json::null()</code>.
</td>
Expand Down
11 changes: 3 additions & 8 deletions include/jsoncons/utility/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <jsoncons/detail/write_number.hpp>
#include <iostream>

namespace jsoncons { namespace utility {
namespace jsoncons {

enum class uri_errc
{
Expand Down Expand Up @@ -61,17 +61,16 @@ namespace jsoncons { namespace utility {
return std::error_code(static_cast<int>(result), uri_error_category());
}

} // namespace utility
} // namespace jsoncons

namespace std {
template<>
struct is_error_code_enum<jsoncons::utility::uri_errc> : public true_type
struct is_error_code_enum<jsoncons::uri_errc> : public true_type
{
};
} // namespace std

namespace jsoncons { namespace utility {
namespace jsoncons {

struct uri_fragment_part_t
{
Expand Down Expand Up @@ -1235,10 +1234,6 @@ namespace jsoncons { namespace utility {
}
};

} // namespace utility

using uri = utility::uri;

} // namespace jsoncons

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace jsonschema {
return base_uri_.uri();
}

jsoncons::utility::uri make_schema_location(const std::string& keyword) const
jsoncons::uri make_schema_location(const std::string& keyword) const
{
for (auto it = uris_.rbegin(); it != uris_.rend(); ++it)
{
Expand All @@ -79,14 +79,14 @@ namespace jsonschema {
return uri{"#"};
}

static jsoncons::utility::uri make_random_uri()
static jsoncons::uri make_random_uri()
{
std::random_device dev;
std::mt19937 gen{ dev() };
std::uniform_int_distribution<std::mt19937::result_type> dist(1, 10000);

std::string str = "https:://jsoncons.com/" + std::to_string(dist(gen));
jsoncons::utility::uri uri{str};
jsoncons::uri uri{str};
return uri;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace jsonschema {

void set_referred_schema(const schema_validator<Json>* target) final { tentative_target_ = target; }

const jsoncons::utility::uri& value() const { return value_.uri(); }
const jsoncons::uri& value() const { return value_.uri(); }

uri get_base_uri() const
{
Expand Down
10 changes: 5 additions & 5 deletions include/jsoncons_ext/jsonschema/common/schema_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace jsoncons {
namespace jsonschema {

template <typename Json>
using schema_resolver = std::function<Json(const jsoncons::utility::uri & /*id*/)>;
using schema_resolver = std::function<Json(const jsoncons::uri & /*id*/)>;

template <typename Json>
class schema_builder
{
public:
using schema_store_type = std::map<jsoncons::utility::uri, schema_validator<Json>*>;
using schema_store_type = std::map<jsoncons::uri, schema_validator<Json>*>;
using schema_builder_factory_type = std::function<std::unique_ptr<schema_builder<Json>>(const Json&,
const evaluation_options&,schema_store_type*,const std::vector<schema_resolver<Json>>&,
const std::unordered_map<std::string,bool>&)>;
Expand All @@ -46,8 +46,8 @@ namespace jsonschema {
// Owns external schemas
std::vector<schema_validator_type> schema_validators_;
public:
std::vector<std::pair<jsoncons::utility::uri, ref_type*>> unresolved_refs_;
std::map<jsoncons::utility::uri, Json> unknown_keywords_;
std::vector<std::pair<jsoncons::uri, ref_type*>> unresolved_refs_;
std::map<jsoncons::uri, Json> unknown_keywords_;

public:

Expand Down Expand Up @@ -195,7 +195,7 @@ namespace jsonschema {
{
// is there a reference looking for this unknown-keyword, which is thus no longer a unknown keyword but a schema
auto unresolved_refs = std::find_if(this->unresolved_refs_.begin(), this->unresolved_refs_.end(),
[new_uri](const std::pair<jsoncons::utility::uri,ref<Json>*>& pr) {return pr.first == new_uri.uri();});
[new_uri](const std::pair<jsoncons::uri,ref<Json>*>& pr) {return pr.first == new_uri.uri();});
if (unresolved_refs != this->unresolved_refs_.end())
{
anchor_uri_map_type anchor_dict2;
Expand Down
28 changes: 14 additions & 14 deletions include/jsoncons_ext/jsonschema/common/schema_validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ namespace jsonschema {
return schema_val_->recursive_anchor();
}

const jsoncons::optional<jsoncons::utility::uri>& id() const final
const jsoncons::optional<jsoncons::uri>& id() const final
{
return schema_val_->id();
}

const jsoncons::optional<jsoncons::utility::uri>& dynamic_anchor() const final
const jsoncons::optional<jsoncons::uri>& dynamic_anchor() const final
{
return schema_val_->dynamic_anchor();
}
Expand Down Expand Up @@ -119,9 +119,9 @@ namespace jsonschema {
uri schema_location_;
bool value_;

jsoncons::optional<jsoncons::utility::uri> id_;
jsoncons::optional<jsoncons::uri> id_;

jsoncons::optional<jsoncons::utility::uri> dynamic_anchor_;
jsoncons::optional<jsoncons::uri> dynamic_anchor_;

public:
boolean_schema_validator(const boolean_schema_validator&) = delete;
Expand All @@ -148,12 +148,12 @@ namespace jsonschema {
return false;
}

const jsoncons::optional<jsoncons::utility::uri>& id() const final
const jsoncons::optional<jsoncons::uri>& id() const final
{
return id_;
}

const jsoncons::optional<jsoncons::utility::uri>& dynamic_anchor() const final
const jsoncons::optional<jsoncons::uri>& dynamic_anchor() const final
{
return dynamic_anchor_;
}
Expand Down Expand Up @@ -209,14 +209,14 @@ namespace jsonschema {
using walk_reporter_type = typename json_schema_traits<Json>::walk_reporter_type;

uri schema_location_;
jsoncons::optional<jsoncons::utility::uri> id_;
jsoncons::optional<jsoncons::uri> id_;
std::vector<keyword_validator_type> validators_;
std::unique_ptr<unevaluated_properties_validator<Json>> unevaluated_properties_val_;
std::unique_ptr<unevaluated_items_validator<Json>> unevaluated_items_val_;
std::map<std::string,schema_validator_type> defs_;
Json default_value_;
bool recursive_anchor_;
jsoncons::optional<jsoncons::utility::uri> dynamic_anchor_;
jsoncons::optional<jsoncons::uri> dynamic_anchor_;
anchor_schema_map_type anchor_dict_;
bool always_succeeds_;
bool always_fails_;
Expand All @@ -227,7 +227,7 @@ namespace jsonschema {
object_schema_validator(object_schema_validator&&) = default;
object_schema_validator& operator=(object_schema_validator&&) = default;
object_schema_validator(const uri& schema_location,
const jsoncons::optional<jsoncons::utility::uri>& id,
const jsoncons::optional<jsoncons::uri>& id,
std::vector<keyword_validator_type>&& validators,
std::map<std::string,schema_validator_type>&& defs,
Json&& default_value)
Expand All @@ -242,7 +242,7 @@ namespace jsonschema {
init();
}
object_schema_validator(const uri& schema_location,
const jsoncons::optional<jsoncons::utility::uri>& id,
const jsoncons::optional<jsoncons::uri>& id,
std::vector<keyword_validator_type>&& validators,
std::unique_ptr<unevaluated_properties_validator<Json>>&& unevaluated_properties_val,
std::unique_ptr<unevaluated_items_validator<Json>>&& unevaluated_items_val,
Expand All @@ -261,13 +261,13 @@ namespace jsonschema {
init();
}
object_schema_validator(const uri& schema_location,
const jsoncons::optional<jsoncons::utility::uri>& id,
const jsoncons::optional<jsoncons::uri>& id,
std::vector<keyword_validator_type>&& validators,
std::unique_ptr<unevaluated_properties_validator<Json>>&& unevaluated_properties_val,
std::unique_ptr<unevaluated_items_validator<Json>>&& unevaluated_items_val,
std::map<std::string,schema_validator_type>&& defs,
Json&& default_value,
jsoncons::optional<jsoncons::utility::uri>&& dynamic_anchor,
jsoncons::optional<jsoncons::uri>&& dynamic_anchor,
anchor_schema_map_type&& anchor_dict)
: schema_location_(schema_location),
id_(std::move(id)),
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace jsonschema {
return recursive_anchor_;
}

const jsoncons::optional<jsoncons::utility::uri>& id() const final
const jsoncons::optional<jsoncons::uri>& id() const final
{
return id_;
}
Expand All @@ -310,7 +310,7 @@ namespace jsonschema {
return (it == anchor_dict_.end()) ? nullptr : it->second->referred_schema();
}

const jsoncons::optional<jsoncons::utility::uri>& dynamic_anchor() const final
const jsoncons::optional<jsoncons::uri>& dynamic_anchor() const final
{
return dynamic_anchor_;
}
Expand Down
14 changes: 7 additions & 7 deletions include/jsoncons_ext/jsonschema/common/uri_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace jsonschema {

class uri_wrapper
{
jsoncons::utility::uri uri_;
jsoncons::uri uri_;
std::string identifier_;
bool has_plain_name_fragment_;
public:
Expand All @@ -29,7 +29,7 @@ namespace jsonschema {

explicit uri_wrapper(const std::string& uri)
{
uri_ = jsoncons::utility::uri(uri);
uri_ = jsoncons::uri(uri);
if (!uri_.encoded_fragment().empty())
{
identifier_ = uri_.fragment();
Expand All @@ -46,7 +46,7 @@ namespace jsonschema {
explicit uri_wrapper(const uri& uri)
: uri_{uri}
{
uri_ = jsoncons::utility::uri(uri);
uri_ = jsoncons::uri(uri);
if (!uri_.encoded_fragment().empty())
{
identifier_ = uri_.fragment();
Expand All @@ -60,7 +60,7 @@ namespace jsonschema {
}
}

const jsoncons::utility::uri& uri() const
const jsoncons::uri& uri() const
{
return uri_;
}
Expand All @@ -75,7 +75,7 @@ namespace jsonschema {
return has_plain_name_fragment_;
}

jsoncons::utility::uri base() const
jsoncons::uri base() const
{
return uri_.base();
}
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace jsonschema {
jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.encoded_fragment()));
pointer /= field;

jsoncons::utility::uri new_uri(uri_, utility::uri_fragment_part, pointer.to_string());
jsoncons::uri new_uri(uri_, uri_fragment_part, pointer.to_string());

return uri_wrapper(std::move(new_uri));
}
Expand All @@ -131,7 +131,7 @@ namespace jsonschema {
jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.encoded_fragment()));
pointer /= index;

jsoncons::utility::uri new_uri(uri_, utility::uri_fragment_part, pointer.to_string());
jsoncons::uri new_uri(uri_, uri_fragment_part, pointer.to_string());

return uri_wrapper(std::move(new_uri));
}
Expand Down
4 changes: 2 additions & 2 deletions include/jsoncons_ext/jsonschema/common/validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ namespace jsonschema {

virtual bool recursive_anchor() const = 0;

virtual const jsoncons::optional<jsoncons::utility::uri>& id() const = 0;
virtual const jsoncons::optional<jsoncons::uri>& id() const = 0;

virtual const schema_validator<Json>* get_schema_for_dynamic_anchor(const std::string& anchor) const = 0;

virtual const jsoncons::optional<jsoncons::utility::uri>& dynamic_anchor() const = 0;
virtual const jsoncons::optional<jsoncons::uri>& dynamic_anchor() const = 0;
};

} // namespace jsonschema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace draft201909 {
schema_validator_type make_object_schema_validator(
const compilation_context& context, const Json& sch, anchor_uri_map_type& anchor_dict)
{
jsoncons::optional<jsoncons::utility::uri> id = context.id();
jsoncons::optional<jsoncons::uri> id = context.id();
Json default_value{ jsoncons::null_type()};
std::vector<keyword_validator_type> validators;
std::unique_ptr<unevaluated_properties_validator<Json>> unevaluated_properties_val;
Expand Down Expand Up @@ -523,8 +523,8 @@ namespace draft201909 {
{
JSONCONS_THROW(schema_error("Invalid $anchor " + anchor));
}
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::utility::uri{"#"};
jsoncons::utility::uri new_uri(uri, utility::uri_fragment_part, anchor);
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::uri{"#"};
jsoncons::uri new_uri(uri, uri_fragment_part, anchor);
uri_wrapper identifier{ new_uri };
if (std::find(new_uris.begin(), new_uris.end(), identifier) == new_uris.end())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,21 @@ namespace draft202012 {
schema_validator_type make_object_schema_validator(const compilation_context& context,
const Json& sch, anchor_uri_map_type& anchor_dict)
{
jsoncons::optional<jsoncons::utility::uri> id = context.id();
jsoncons::optional<jsoncons::uri> id = context.id();
Json default_value{jsoncons::null_type()};
std::vector<keyword_validator_type> validators;
std::unique_ptr<unevaluated_properties_validator<Json>> unevaluated_properties_val;
std::unique_ptr<unevaluated_items_validator<Json>> unevaluated_items_val;
jsoncons::optional<jsoncons::utility::uri> dynamic_anchor;
jsoncons::optional<jsoncons::uri> dynamic_anchor;
std::map<std::string,schema_validator_type> defs;
anchor_uri_map_type local_anchor_dict;

auto it = sch.find("$dynamicAnchor");
if (it != sch.object_range().end())
{
std::string value = it->value().template as<std::string>();
jsoncons::utility::uri new_uri(context.get_base_uri(), utility::uri_fragment_part, value);
dynamic_anchor = jsoncons::optional<jsoncons::utility::uri>(new_uri);
jsoncons::uri new_uri(context.get_base_uri(), uri_fragment_part, value);
dynamic_anchor = jsoncons::optional<jsoncons::uri>(new_uri);
local_anchor_dict.emplace(value, context.get_base_uri());
}

Expand Down Expand Up @@ -578,8 +578,8 @@ namespace draft202012 {
{
JSONCONS_THROW(schema_error("Invalid $anchor " + anchor));
}
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::utility::uri{"#"};
jsoncons::utility::uri new_uri(uri, utility::uri_fragment_part, anchor);
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::uri{"#"};
jsoncons::uri new_uri(uri, uri_fragment_part, anchor);
uri_wrapper identifier{ new_uri };
if (std::find(new_uris.begin(), new_uris.end(), identifier) == new_uris.end())
{
Expand All @@ -594,8 +594,8 @@ namespace draft202012 {
{
JSONCONS_THROW(schema_error("Invalid $dynamicAnchor " + anchor));
}
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::utility::uri{"#"};
jsoncons::utility::uri new_uri(uri, utility::uri_fragment_part, anchor);
auto uri = !new_uris.empty() ? new_uris.back().uri() : jsoncons::uri{"#"};
jsoncons::uri new_uri(uri, uri_fragment_part, anchor);
uri_wrapper identifier{ new_uri };
if (std::find(new_uris.begin(), new_uris.end(), identifier) == new_uris.end())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace draft4 {
schema_validator_type make_object_schema_validator(const compilation_context& context,
const Json& sch, anchor_uri_map_type& anchor_dict)
{
jsoncons::optional<jsoncons::utility::uri> id = context.id();
jsoncons::optional<jsoncons::uri> id = context.id();
Json default_value{ jsoncons::null_type() };
std::vector<keyword_validator_type> validators;
std::map<std::string,schema_validator_type> defs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace draft6 {
schema_validator_type make_object_schema_validator(const compilation_context& context,
const Json& sch, anchor_uri_map_type& anchor_dict)
{
jsoncons::optional<jsoncons::utility::uri> id = context.id();
jsoncons::optional<jsoncons::uri> id = context.id();
Json default_value{ jsoncons::null_type() };
std::vector<keyword_validator_type> validators;
std::map<std::string,schema_validator_type> defs;
Expand Down
Loading

0 comments on commit 1335609

Please sign in to comment.