mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-13 10:32:58 +01:00
Rename json_reference namespace to json_pointer and move unrelated functionality back into SchemaParser class
This commit is contained in:
parent
669b1729c8
commit
c43c8568f5
@ -40,7 +40,7 @@ add_executable(external_schema
|
||||
add_executable(test_suite
|
||||
tests/test_adapter_comparison.cpp
|
||||
tests/test_fetch_document_callback.cpp
|
||||
tests/test_json_reference.cpp
|
||||
tests/test_json_pointer.cpp
|
||||
tests/test_jsoncpp_adapter.cpp
|
||||
tests/test_property_tree_adapter.cpp
|
||||
tests/test_rapidjson_adapter.cpp
|
||||
|
@ -9,7 +9,9 @@
|
||||
|
||||
#include <valijson/adapters/adapter.hpp>
|
||||
|
||||
namespace {
|
||||
namespace valijson {
|
||||
namespace internal {
|
||||
namespace json_pointer {
|
||||
|
||||
/**
|
||||
* @brief Recursively locate the value referenced by a JSON Pointer
|
||||
@ -112,35 +114,6 @@ inline AdapterType resolveJsonPointer(
|
||||
std::string(jsonPointerNext, jsonPointerEnd));
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
namespace valijson {
|
||||
namespace internal {
|
||||
namespace json_reference {
|
||||
|
||||
/**
|
||||
* @brief Extract JSON Pointer portion of a JSON Reference
|
||||
*
|
||||
* @param jsonRef JSON Reference to extract from
|
||||
*
|
||||
* @return string containing JSON Pointer
|
||||
*
|
||||
* @throw std::runtime_error if the string does not contain a JSON Pointer
|
||||
*/
|
||||
inline std::string getJsonReferencePointer(const std::string &jsonRef)
|
||||
{
|
||||
// Attempt to extract JSON Pointer if '#' character is present. Note
|
||||
// that a valid pointer would contain at least a leading forward
|
||||
// slash character.
|
||||
const size_t ptrPos = jsonRef.find("#");
|
||||
if (ptrPos != std::string::npos) {
|
||||
return jsonRef.substr(ptrPos + 1);
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"JSON Reference value does not contain a valid JSON Pointer");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the JSON Value referenced by a JSON Pointer
|
||||
*
|
||||
@ -154,7 +127,7 @@ inline AdapterType resolveJsonPointer(
|
||||
const AdapterType &rootNode,
|
||||
const std::string &jsonPointer)
|
||||
{
|
||||
return ::resolveJsonPointer(rootNode, jsonPointer, jsonPointer.begin());
|
||||
return resolveJsonPointer(rootNode, jsonPointer, jsonPointer.begin());
|
||||
}
|
||||
|
||||
} // namespace json_reference
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <valijson/adapters/adapter.hpp>
|
||||
#include <valijson/constraints/concrete_constraints.hpp>
|
||||
#include <valijson/internal/json_reference.hpp>
|
||||
#include <valijson/internal/json_pointer.hpp>
|
||||
#include <valijson/schema.hpp>
|
||||
|
||||
namespace valijson {
|
||||
@ -288,6 +288,29 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extract JSON Pointer portion of a JSON Reference
|
||||
*
|
||||
* @param jsonRef JSON Reference to extract from
|
||||
*
|
||||
* @return string containing JSON Pointer
|
||||
*
|
||||
* @throw std::runtime_error if the string does not contain a JSON Pointer
|
||||
*/
|
||||
inline std::string getJsonReferencePointer(const std::string &jsonRef)
|
||||
{
|
||||
// Attempt to extract JSON Pointer if '#' character is present. Note
|
||||
// that a valid pointer would contain at least a leading forward
|
||||
// slash character.
|
||||
const size_t ptrPos = jsonRef.find("#");
|
||||
if (ptrPos != std::string::npos) {
|
||||
return jsonRef.substr(ptrPos + 1);
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"JSON Reference value does not contain a valid JSON Pointer");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Populate a schema using a JSON Reference
|
||||
*
|
||||
@ -319,8 +342,7 @@ private:
|
||||
getJsonReferenceUri(jsonRef, schema);
|
||||
|
||||
// Extract JSON Pointer from JSON Reference
|
||||
const std::string jsonPointer =
|
||||
internal::json_reference::getJsonReferencePointer(jsonRef);
|
||||
const std::string jsonPointer = getJsonReferencePointer(jsonRef);
|
||||
|
||||
if (documentUri) {
|
||||
// Resolve reference against remote document
|
||||
@ -342,7 +364,7 @@ private:
|
||||
}
|
||||
|
||||
const AdapterType &ref =
|
||||
internal::json_reference::resolveJsonPointer(*docPtr,
|
||||
internal::json_pointer::resolveJsonPointer(*docPtr,
|
||||
jsonPointer);
|
||||
|
||||
// Resolve reference against retrieved document
|
||||
@ -351,7 +373,7 @@ private:
|
||||
|
||||
} else {
|
||||
const AdapterType &ref =
|
||||
internal::json_reference::resolveJsonPointer(node,
|
||||
internal::json_pointer::resolveJsonPointer(node,
|
||||
jsonPointer);
|
||||
|
||||
// Resolve reference against current document
|
||||
|
@ -3,17 +3,17 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <valijson/internal/json_reference.hpp>
|
||||
#include <valijson/internal/json_pointer.hpp>
|
||||
|
||||
#include <valijson/adapters/rapidjson_adapter.hpp>
|
||||
|
||||
using valijson::adapters::RapidJsonAdapter;
|
||||
using valijson::internal::json_reference::resolveJsonPointer;
|
||||
using valijson::internal::json_pointer::resolveJsonPointer;
|
||||
|
||||
typedef rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>
|
||||
RapidJsonCrtAllocator;
|
||||
|
||||
class TestJsonReference : public testing::Test
|
||||
class TestJsonPointer : public testing::Test
|
||||
{
|
||||
|
||||
};
|
||||
@ -107,7 +107,7 @@ std::vector<boost::shared_ptr<JsonPointerTestCase> >
|
||||
return testCases;
|
||||
}
|
||||
|
||||
TEST_F(TestJsonReference, JsonPointerTestCases)
|
||||
TEST_F(TestJsonPointer, JsonPointerTestCases)
|
||||
{
|
||||
typedef std::vector<boost::shared_ptr<JsonPointerTestCase> > TestCases;
|
||||
|
@ -9,7 +9,7 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
6A477F8517D6BCBB0013571C /* libboost_regex-mt.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A477F8417D6BCBB0013571C /* libboost_regex-mt.dylib */; };
|
||||
6A477F8617D6EA000013571C /* libboost_regex-mt.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A477F8417D6BCBB0013571C /* libboost_regex-mt.dylib */; };
|
||||
6A506D201AF88E5D00C2C818 /* test_json_reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A506D1F1AF88E5D00C2C818 /* test_json_reference.cpp */; };
|
||||
6A506D201AF88E5D00C2C818 /* test_json_pointer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A506D1F1AF88E5D00C2C818 /* test_json_pointer.cpp */; };
|
||||
6A725F4517F61D7000D6B2FF /* test_validation_errors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A725F4317F61B5100D6B2FF /* test_validation_errors.cpp */; };
|
||||
6A725F4617F6404100D6B2FF /* test_adapter_comparison.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6AB8FEB117E6DF9A0028E147 /* test_adapter_comparison.cpp */; };
|
||||
6A725F4717F6404100D6B2FF /* test_jsoncpp_adapter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6AB8FE9217E6BE770028E147 /* test_jsoncpp_adapter.cpp */; };
|
||||
@ -51,8 +51,8 @@
|
||||
6A506D1A1AF884E100C2C818 /* rfc3986-uri.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "rfc3986-uri.txt"; sourceTree = "<group>"; };
|
||||
6A506D1B1AF884E100C2C818 /* rfc4627-json.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "rfc4627-json.txt"; sourceTree = "<group>"; };
|
||||
6A506D1C1AF884E100C2C818 /* rfc6901-json-pointer.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "rfc6901-json-pointer.txt"; sourceTree = "<group>"; };
|
||||
6A506D1E1AF88D8700C2C818 /* json_reference.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = json_reference.hpp; path = internal/json_reference.hpp; sourceTree = "<group>"; };
|
||||
6A506D1F1AF88E5D00C2C818 /* test_json_reference.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_json_reference.cpp; sourceTree = "<group>"; };
|
||||
6A506D1E1AF88D8700C2C818 /* json_pointer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = json_pointer.hpp; path = internal/json_pointer.hpp; sourceTree = "<group>"; };
|
||||
6A506D1F1AF88E5D00C2C818 /* test_json_pointer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_json_pointer.cpp; sourceTree = "<group>"; };
|
||||
6A725F3617F61A4400D6B2FF /* array_doubles_10_20_30_40.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = array_doubles_10_20_30_40.json; sourceTree = "<group>"; };
|
||||
6A725F3717F61A4400D6B2FF /* array_doubles_1_2_3.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = array_doubles_1_2_3.json; sourceTree = "<group>"; };
|
||||
6A725F3817F61A4400D6B2FF /* array_doubles_1_2_3_4.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = array_doubles_1_2_3_4.json; sourceTree = "<group>"; };
|
||||
@ -324,7 +324,7 @@
|
||||
6A506D1D1AF88D5E00C2C818 /* internal */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6A506D1E1AF88D8700C2C818 /* json_reference.hpp */,
|
||||
6A506D1E1AF88D8700C2C818 /* json_pointer.hpp */,
|
||||
);
|
||||
name = internal;
|
||||
sourceTree = "<group>";
|
||||
@ -668,7 +668,7 @@
|
||||
6AB8FEB417E6E53D0028E147 /* data */,
|
||||
6AB8FEB117E6DF9A0028E147 /* test_adapter_comparison.cpp */,
|
||||
6AA8A5DA17F8BDCA002728A0 /* test_fetch_document_callback.cpp */,
|
||||
6A506D1F1AF88E5D00C2C818 /* test_json_reference.cpp */,
|
||||
6A506D1F1AF88E5D00C2C818 /* test_json_pointer.cpp */,
|
||||
6AB8FE9217E6BE770028E147 /* test_jsoncpp_adapter.cpp */,
|
||||
6AB8FEC417E92B100028E147 /* test_property_tree_adapter.cpp */,
|
||||
6AC18D3917CC874100FE0EC9 /* test_rapidjson_adapter.cpp */,
|
||||
@ -969,7 +969,7 @@
|
||||
6A725F4717F6404100D6B2FF /* test_jsoncpp_adapter.cpp in Sources */,
|
||||
6A725F4817F6404100D6B2FF /* test_property_tree_adapter.cpp in Sources */,
|
||||
6AD3490118FF56FB004BDEE7 /* gtest_main.cc in Sources */,
|
||||
6A506D201AF88E5D00C2C818 /* test_json_reference.cpp in Sources */,
|
||||
6A506D201AF88E5D00C2C818 /* test_json_pointer.cpp in Sources */,
|
||||
6A725F4917F6404100D6B2FF /* test_rapidjson_adapter.cpp in Sources */,
|
||||
6A725F4A17F6404100D6B2FF /* test_validator.cpp in Sources */,
|
||||
6A725F4D17F8964B00D6B2FF /* test_uri_resolution.cpp in Sources */,
|
||||
|
Loading…
Reference in New Issue
Block a user