mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Change back to tomlplusplus (#401)
For a long time, tomlplusplus did generate a config.cmake file, which made it difficult to use on vcpkg. As a fix, we switched to toml11. But this has now finally been added to vcpkg, and since tomlplusplus is faster than toml11 in terms of compile time and runtime, we are changing back.
This commit is contained in:
+3
-3
@@ -194,10 +194,10 @@ if (REFLECTCPP_TOML)
|
|||||||
list(APPEND REFLECT_CPP_SOURCES
|
list(APPEND REFLECT_CPP_SOURCES
|
||||||
src/reflectcpp_toml.cpp
|
src/reflectcpp_toml.cpp
|
||||||
)
|
)
|
||||||
if (NOT TARGET toml11)
|
if (NOT TARGET tomlplusplus)
|
||||||
find_package(toml11 CONFIG REQUIRED)
|
find_package(tomlplusplus)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(reflectcpp PUBLIC toml11::toml11)
|
target_link_libraries(reflectcpp PUBLIC tomlplusplus::tomlplusplus)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (REFLECTCPP_UBJSON)
|
if (REFLECTCPP_UBJSON)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ The following table lists the serialization formats currently supported by refle
|
|||||||
| CBOR | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format |
|
| CBOR | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format |
|
||||||
| flexbuffers | [flatbuffers](https://github.com/google/flatbuffers) | >= 23.5.26 | Apache 2.0 | Schema-less version of flatbuffers, binary format |
|
| flexbuffers | [flatbuffers](https://github.com/google/flatbuffers) | >= 23.5.26 | Apache 2.0 | Schema-less version of flatbuffers, binary format |
|
||||||
| msgpack | [msgpack-c](https://github.com/msgpack/msgpack-c) | >= 6.0.0 | BSL 1.0 | JSON-like binary format |
|
| msgpack | [msgpack-c](https://github.com/msgpack/msgpack-c) | >= 6.0.0 | BSL 1.0 | JSON-like binary format |
|
||||||
| TOML | [toml11](https://github.com/ToruNiina/toml11) | >= 4.2.0 | MIT | Textual format with an emphasis on readability |
|
| TOML | [toml++](https://github.com/marzer/tomlplusplus) | >= 3.4.0 | MIT | Textual format with an emphasis on readability |
|
||||||
| UBJSON | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format |
|
| UBJSON | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format |
|
||||||
| XML | [pugixml](https://github.com/zeux/pugixml) | >= 1.14 | MIT | Textual format used in many legacy projects |
|
| XML | [pugixml](https://github.com/zeux/pugixml) | >= 1.14 | MIT | Textual format used in many legacy projects |
|
||||||
| YAML | [yaml-cpp](https://github.com/jbeder/yaml-cpp) | >= 0.8.0 | MIT | Textual format with an emphasis on readability |
|
| YAML | [yaml-cpp](https://github.com/jbeder/yaml-cpp) | >= 0.8.0 | MIT | Textual format with an emphasis on readability |
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ class ReflectCppConan(ConanFile):
|
|||||||
if self.options.with_msgpack:
|
if self.options.with_msgpack:
|
||||||
self.requires("msgpack-c/6.0.0", transitive_headers=True)
|
self.requires("msgpack-c/6.0.0", transitive_headers=True)
|
||||||
if self.options.with_toml:
|
if self.options.with_toml:
|
||||||
self.requires("toml11/4.4.0", transitive_headers=True)
|
self.requires("tomlplusplus/3.4.0", transitive_headers=True)
|
||||||
if self.options.with_xml:
|
if self.options.with_xml:
|
||||||
self.requires("pugixml/1.14", transitive_headers=True)
|
self.requires("pugixml/1.14", transitive_headers=True)
|
||||||
if self.options.with_yaml:
|
if self.options.with_yaml:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# TOML
|
# TOML
|
||||||
|
|
||||||
For TOML support, you must also include the header `<rfl/toml.hpp>` and include the [toml11](https://github.com/ToruNiina/toml11) library.
|
For TOML support, you must also include the header `<rfl/toml.hpp>` and include the [toml++](https://github.com/marzer/tomlplusplus) library.
|
||||||
Furthermore, when compiling reflect-cpp, you need to pass `-DREFLECTCPP_TOML=ON` to cmake. If you are using vcpkg or Conan, there
|
Furthermore, when compiling reflect-cpp, you need to pass `-DREFLECTCPP_TOML=ON` to cmake. If you are using vcpkg or Conan, there
|
||||||
should be an appropriate feature (vcpkg) or option (Conan) that will abstract this away for you.
|
should be an appropriate feature (vcpkg) or option (Conan) that will abstract this away for you.
|
||||||
|
|
||||||
|
|||||||
+40
-41
@@ -9,24 +9,20 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <toml++/toml.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
|
||||||
#include <toml.hpp>
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
#include "../Result.hpp"
|
#include "../Result.hpp"
|
||||||
#include "../always_false.hpp"
|
#include "../always_false.hpp"
|
||||||
|
|
||||||
namespace rfl::toml {
|
namespace rfl::toml {
|
||||||
|
|
||||||
struct Reader {
|
struct Reader {
|
||||||
using InputArrayType = const ::toml::array*;
|
using InputArrayType = ::toml::array*;
|
||||||
using InputObjectType = const ::toml::table*;
|
using InputObjectType = ::toml::table*;
|
||||||
using InputVarType = const ::toml::value*;
|
using InputVarType = ::toml::node*;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static constexpr bool has_custom_constructor =
|
static constexpr bool has_custom_constructor =
|
||||||
@@ -37,64 +33,66 @@ struct Reader {
|
|||||||
if (_idx >= _arr->size()) {
|
if (_idx >= _arr->size()) {
|
||||||
return error("Index " + std::to_string(_idx) + " of of bounds.");
|
return error("Index " + std::to_string(_idx) + " of of bounds.");
|
||||||
}
|
}
|
||||||
return &(*_arr)[_idx];
|
return _arr->get(_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
rfl::Result<InputVarType> get_field_from_object(
|
rfl::Result<InputVarType> get_field_from_object(
|
||||||
const std::string& _name, const InputObjectType _obj) const noexcept {
|
const std::string& _name, const InputObjectType& _obj) const noexcept {
|
||||||
const auto it = _obj->find(_name);
|
auto var = (*_obj)[_name];
|
||||||
if (it == _obj->end()) {
|
if (!var) {
|
||||||
return error("Object contains no field named '" + _name + "'.");
|
return error("Object contains no field named '" + _name + "'.");
|
||||||
}
|
}
|
||||||
return &it->second;
|
return var.node();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_empty(const InputVarType _var) const noexcept {
|
bool is_empty(const InputVarType& _var) const noexcept {
|
||||||
return _var->is_empty();
|
return !_var && true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
rfl::Result<T> to_basic_type(const InputVarType _var) const noexcept {
|
rfl::Result<T> to_basic_type(const InputVarType& _var) const noexcept {
|
||||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||||
if (!_var->is_string()) {
|
const auto ptr = _var->as<std::string>();
|
||||||
return error("Could not cast to std::string!");
|
if (!ptr) {
|
||||||
|
return error("Could not cast the node to std::string!");
|
||||||
}
|
}
|
||||||
return _var->as_string();
|
return **ptr;
|
||||||
|
|
||||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||||
if (!_var->is_boolean()) {
|
const auto ptr = _var->as<bool>();
|
||||||
return error("Could not cast to bool!");
|
if (!ptr) {
|
||||||
|
return error("Could not cast the node to bool!");
|
||||||
}
|
}
|
||||||
return _var->as_boolean();
|
return **ptr;
|
||||||
|
|
||||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||||
if (!_var->is_floating()) {
|
const auto ptr = _var->as<double>();
|
||||||
return error("Could not cast to double!");
|
if (!ptr) {
|
||||||
|
return error("Could not cast the node to double!");
|
||||||
}
|
}
|
||||||
return static_cast<std::remove_cvref_t<T>>(_var->as_floating());
|
return static_cast<std::remove_cvref_t<T>>(**ptr);
|
||||||
|
|
||||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||||
if (!_var->is_integer()) {
|
const auto ptr = _var->as<int64_t>();
|
||||||
return error("Could not cast to int64_t!");
|
if (!ptr) {
|
||||||
|
return error("Could not cast the node to int64_t!");
|
||||||
}
|
}
|
||||||
return static_cast<std::remove_cvref_t<T>>(_var->as_integer());
|
return static_cast<std::remove_cvref_t<T>>(**ptr);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rfl::Result<InputArrayType> to_array(const InputVarType _var) const noexcept {
|
rfl::Result<InputArrayType> to_array(
|
||||||
if (!_var->is_array()) {
|
const InputVarType& _var) const noexcept {
|
||||||
|
const auto ptr = _var->as_array();
|
||||||
|
if (!ptr) {
|
||||||
return error("Could not cast to an array!");
|
return error("Could not cast to an array!");
|
||||||
}
|
}
|
||||||
return &_var->as_array();
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ArrayReader>
|
template <class ArrayReader>
|
||||||
std::optional<Error> read_array(const ArrayReader& _array_reader,
|
std::optional<Error> read_array(const ArrayReader& _array_reader,
|
||||||
const InputArrayType _arr) const noexcept {
|
const InputArrayType& _arr) const noexcept {
|
||||||
for (const auto& node : *_arr) {
|
for (auto& node : *_arr) {
|
||||||
const auto err = _array_reader.read(&node);
|
const auto err = _array_reader.read(&node);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -106,18 +104,19 @@ struct Reader {
|
|||||||
template <class ObjectReader>
|
template <class ObjectReader>
|
||||||
std::optional<Error> read_object(const ObjectReader& _object_reader,
|
std::optional<Error> read_object(const ObjectReader& _object_reader,
|
||||||
InputObjectType _obj) const noexcept {
|
InputObjectType _obj) const noexcept {
|
||||||
for (const auto& [k, v] : *_obj) {
|
for (auto& [k, v] : *_obj) {
|
||||||
_object_reader.read(std::string_view(k), &v);
|
_object_reader.read(std::string_view(k), &v);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
rfl::Result<InputObjectType> to_object(
|
rfl::Result<InputObjectType> to_object(
|
||||||
const InputVarType _var) const noexcept {
|
const InputVarType& _var) const noexcept {
|
||||||
if (!_var->is_table()) {
|
const auto ptr = _var->as_table();
|
||||||
|
if (!ptr) {
|
||||||
return error("Could not cast to a table!");
|
return error("Could not cast to a table!");
|
||||||
}
|
}
|
||||||
return &_var->as_table();
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
@@ -7,14 +7,10 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <toml++/toml.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
|
||||||
#include <toml.hpp>
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
#include "../Ref.hpp"
|
#include "../Ref.hpp"
|
||||||
#include "../Result.hpp"
|
#include "../Result.hpp"
|
||||||
#include "../always_false.hpp"
|
#include "../always_false.hpp"
|
||||||
@@ -80,7 +76,7 @@ class Writer {
|
|||||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||||
const T& _var,
|
const T& _var,
|
||||||
OutputObjectType* _parent) const noexcept {
|
OutputObjectType* _parent) const noexcept {
|
||||||
(*_parent->val_)[std::string(_name)] = ::toml::value(_var);
|
_parent->val_->emplace(_name, ::toml::value(_var));
|
||||||
return OutputVarType{};
|
return OutputVarType{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,7 @@
|
|||||||
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <toml++/toml.hpp>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
|
||||||
#include <toml.hpp>
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
#include "../Processors.hpp"
|
#include "../Processors.hpp"
|
||||||
#include "../internal/wrap_in_rfl_array_t.hpp"
|
#include "../internal/wrap_in_rfl_array_t.hpp"
|
||||||
@@ -33,12 +28,8 @@ auto read(InputVarType _var) {
|
|||||||
/// Reads a TOML string.
|
/// Reads a TOML string.
|
||||||
template <class T, class... Ps>
|
template <class T, class... Ps>
|
||||||
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _toml_str) {
|
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _toml_str) {
|
||||||
auto res = ::toml::try_parse_str(_toml_str);
|
auto table = ::toml::parse(_toml_str);
|
||||||
if (res.is_ok()) {
|
return read<T, Ps...>(&table);
|
||||||
return read<T, Ps...>(&res.unwrap());
|
|
||||||
} else {
|
|
||||||
return error(::toml::format_error(res.unwrap_err().at(0)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a TOML string.
|
/// Reads a TOML string.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <toml.hpp>
|
#include <toml++/toml.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "../Processors.hpp"
|
#include "../Processors.hpp"
|
||||||
@@ -13,6 +13,22 @@
|
|||||||
|
|
||||||
namespace rfl::toml {
|
namespace rfl::toml {
|
||||||
|
|
||||||
|
/// Writes a TOML into an ostream.
|
||||||
|
template <class... Ps>
|
||||||
|
std::ostream& write(const auto& _obj, std::ostream& _stream) {
|
||||||
|
using T = std::remove_cvref_t<decltype(_obj)>;
|
||||||
|
using ParentType = parsing::Parent<Writer>;
|
||||||
|
::toml::table root;
|
||||||
|
auto w = Writer(&root);
|
||||||
|
using ProcessorsType = Processors<Ps...>;
|
||||||
|
static_assert(!ProcessorsType::no_field_names_,
|
||||||
|
"The NoFieldNames processor is not supported for BSON, XML, "
|
||||||
|
"TOML, or YAML.");
|
||||||
|
Parser<T, ProcessorsType>::write(w, _obj, typename ParentType::Root{});
|
||||||
|
_stream << root;
|
||||||
|
return _stream;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a TOML string.
|
/// Returns a TOML string.
|
||||||
template <class... Ps>
|
template <class... Ps>
|
||||||
std::string write(const auto& _obj) {
|
std::string write(const auto& _obj) {
|
||||||
@@ -26,14 +42,8 @@ std::string write(const auto& _obj) {
|
|||||||
"The NoFieldNames processor is not supported for BSON, XML, "
|
"The NoFieldNames processor is not supported for BSON, XML, "
|
||||||
"TOML, or YAML.");
|
"TOML, or YAML.");
|
||||||
Parser<T, ProcessorsType>::write(w, _obj, typename ParentType::Root{});
|
Parser<T, ProcessorsType>::write(w, _obj, typename ParentType::Root{});
|
||||||
return ::toml::format(::toml::value(root));
|
sstream << root;
|
||||||
}
|
return sstream.str();
|
||||||
|
|
||||||
/// Writes a TOML into an ostream.
|
|
||||||
template <class... Ps>
|
|
||||||
std::ostream& write(const auto& _obj, std::ostream& _stream) {
|
|
||||||
_stream << write(_obj);
|
|
||||||
return _stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rfl::toml
|
} // namespace rfl::toml
|
||||||
|
|||||||
@@ -17,28 +17,30 @@ Writer::OutputVarType Writer::null_as_root() const noexcept {
|
|||||||
|
|
||||||
Writer::OutputArrayType Writer::add_array_to_array(
|
Writer::OutputArrayType Writer::add_array_to_array(
|
||||||
const size_t _size, OutputArrayType* _parent) const noexcept {
|
const size_t _size, OutputArrayType* _parent) const noexcept {
|
||||||
|
const auto i = _parent->val_->size();
|
||||||
_parent->val_->push_back(::toml::array());
|
_parent->val_->push_back(::toml::array());
|
||||||
return OutputArrayType{&_parent->val_->back().as_array()};
|
return OutputArrayType{_parent->val_->at(i).as_array()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputArrayType Writer::add_array_to_object(
|
Writer::OutputArrayType Writer::add_array_to_object(
|
||||||
const std::string_view& _name, const size_t _size,
|
const std::string_view& _name, const size_t _size,
|
||||||
OutputObjectType* _parent) const noexcept {
|
OutputObjectType* _parent) const noexcept {
|
||||||
_parent->val_->emplace(_name, ::toml::array());
|
_parent->val_->emplace(_name, ::toml::array());
|
||||||
return OutputArrayType{&(*_parent->val_)[std::string(_name)].as_array()};
|
return OutputArrayType{_parent->val_->at_path(_name).as_array()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputObjectType Writer::add_object_to_array(
|
Writer::OutputObjectType Writer::add_object_to_array(
|
||||||
const size_t _size, OutputArrayType* _parent) const noexcept {
|
const size_t _size, OutputArrayType* _parent) const noexcept {
|
||||||
|
const auto i = _parent->val_->size();
|
||||||
_parent->val_->push_back(::toml::table());
|
_parent->val_->push_back(::toml::table());
|
||||||
return OutputObjectType{&_parent->val_->back().as_table()};
|
return OutputObjectType{_parent->val_->at(i).as_table()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputObjectType Writer::add_object_to_object(
|
Writer::OutputObjectType Writer::add_object_to_object(
|
||||||
const std::string_view& _name, const size_t _size,
|
const std::string_view& _name, const size_t _size,
|
||||||
OutputObjectType* _parent) const noexcept {
|
OutputObjectType* _parent) const noexcept {
|
||||||
_parent->val_->emplace(_name, ::toml::table());
|
_parent->val_->emplace(_name, ::toml::table());
|
||||||
return OutputObjectType{&(*_parent->val_)[std::string(_name)].as_table()};
|
return OutputObjectType{_parent->val_->at_path(_name).as_table()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputVarType Writer::add_null_to_array(
|
Writer::OutputVarType Writer::add_null_to_array(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "write_and_read.hpp"
|
#include "write_and_read.hpp"
|
||||||
|
|
||||||
namespace test_json_schema {
|
namespace test_json_schema4 {
|
||||||
|
|
||||||
enum class Color { red, green, blue };
|
enum class Color { red, green, blue };
|
||||||
|
|
||||||
@@ -66,8 +66,8 @@ TEST(json, test_json_schema4) {
|
|||||||
rfl::json::to_schema<Person, rfl::DefaultIfMissing>();
|
rfl::json::to_schema<Person, rfl::DefaultIfMissing>();
|
||||||
|
|
||||||
const std::string expected =
|
const std::string expected =
|
||||||
R"({"$schema":"https://json-schema.org/draft/2020-12/schema","$ref":"#/definitions/test_json_schema__Person","definitions":{"rfl__Generic":{"anyOf":[{"anyOf":[{"type":"boolean"},{"type":"integer"},{"type":"number"},{"type":"string"},{"type":"object","additionalProperties":{"$ref":"#/definitions/rfl__Generic"}},{"type":"array","items":{"$ref":"#/definitions/rfl__Generic"}}]},{"type":"null"}]},"test_json_schema__Circle":{"type":"object","properties":{"radius":{"type":"number"}},"required":[]},"test_json_schema__Circle__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Circle"]},"radius":{"type":"number"}},"required":[]},"test_json_schema__Person":{"type":"object","properties":{"firstName":{"type":"string"},"lastName":{"type":"string"},"email":{"type":"string","description":"Must be a proper email in the form xxx@xxx.xxx.","pattern":"^[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}$"},"town":{"type":"string"},"color":{"type":"string","enum":["red","green","blue"]},"age":{"allOf":[{"minimum":0,"type":"integer"},{"maximum":130,"type":"integer"}]},"salary":{"type":"number"},"children":{"type":"array","description":"The person's children. Pass an empty array for no children.","items":{"$ref":"#/definitions/test_json_schema__Person"}},"variant":{"anyOf":[{"type":"string","enum":["red","green","blue"]},{"type":"array","items":{"$ref":"#/definitions/test_json_schema__Person"}},{"type":"integer"}]},"tuple":{"type":"array","prefixItems":[{"type":"string","enum":["red","green","blue"]},{"type":"array","items":{"$ref":"#/definitions/test_json_schema__Person"}},{"type":"integer"}],"items":false},"taggedUnion":{"anyOf":[{"$ref":"#/definitions/test_json_schema__Rectangle__tagged"},{"$ref":"#/definitions/test_json_schema__Square__tagged"},{"$ref":"#/definitions/test_json_schema__Circle__tagged"}]},"fieldVariant":{"anyOf":[{"type":"object","properties":{"rectangle":{"$ref":"#/definitions/test_json_schema__Rectangle"}},"required":[]},{"type":"object","properties":{"square":{"$ref":"#/definitions/test_json_schema__Square"}},"required":[]},{"type":"object","properties":{"circle":{"$ref":"#/definitions/test_json_schema__Circle"}},"required":[]}]},"generic":{"$ref":"#/definitions/rfl__Generic"},"with_extra_fields":{"$ref":"#/definitions/test_json_schema__WithExtraFields"}},"required":[]},"test_json_schema__Rectangle":{"type":"object","properties":{"width":{"type":"number"},"height":{"type":"number"}},"required":[]},"test_json_schema__Rectangle__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Rectangle"]},"width":{"type":"number"},"height":{"type":"number"}},"required":[]},"test_json_schema__Square":{"type":"object","properties":{"width":{"type":"number"}},"required":[]},"test_json_schema__Square__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Square"]},"width":{"type":"number"}},"required":[]},"test_json_schema__WithExtraFields":{"type":"object","properties":{"f1":{"type":"string"},"f2":{"type":"string"}},"required":[],"additionalProperties":{"type":"string"}}}})";
|
R"({"$schema":"https://json-schema.org/draft/2020-12/schema","$ref":"#/definitions/test_json_schema4__Person","definitions":{"rfl__Generic":{"anyOf":[{"anyOf":[{"type":"boolean"},{"type":"integer"},{"type":"number"},{"type":"string"},{"type":"object","additionalProperties":{"$ref":"#/definitions/rfl__Generic"}},{"type":"array","items":{"$ref":"#/definitions/rfl__Generic"}}]},{"type":"null"}]},"test_json_schema4__Circle":{"type":"object","properties":{"radius":{"type":"number"}},"required":[]},"test_json_schema4__Circle__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Circle"]},"radius":{"type":"number"}},"required":[]},"test_json_schema4__Person":{"type":"object","properties":{"firstName":{"type":"string"},"lastName":{"type":"string"},"email":{"type":"string","description":"Must be a proper email in the form xxx@xxx.xxx.","pattern":"^[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}$"},"town":{"type":"string"},"color":{"type":"string","enum":["red","green","blue"]},"age":{"allOf":[{"minimum":0,"type":"integer"},{"maximum":130,"type":"integer"}]},"salary":{"type":"number"},"children":{"type":"array","description":"The person's children. Pass an empty array for no children.","items":{"$ref":"#/definitions/test_json_schema4__Person"}},"variant":{"anyOf":[{"type":"string","enum":["red","green","blue"]},{"type":"array","items":{"$ref":"#/definitions/test_json_schema4__Person"}},{"type":"integer"}]},"tuple":{"type":"array","prefixItems":[{"type":"string","enum":["red","green","blue"]},{"type":"array","items":{"$ref":"#/definitions/test_json_schema4__Person"}},{"type":"integer"}],"items":false},"taggedUnion":{"anyOf":[{"$ref":"#/definitions/test_json_schema4__Rectangle__tagged"},{"$ref":"#/definitions/test_json_schema4__Square__tagged"},{"$ref":"#/definitions/test_json_schema4__Circle__tagged"}]},"fieldVariant":{"anyOf":[{"type":"object","properties":{"rectangle":{"$ref":"#/definitions/test_json_schema4__Rectangle"}},"required":[]},{"type":"object","properties":{"square":{"$ref":"#/definitions/test_json_schema4__Square"}},"required":[]},{"type":"object","properties":{"circle":{"$ref":"#/definitions/test_json_schema4__Circle"}},"required":[]}]},"generic":{"$ref":"#/definitions/rfl__Generic"},"with_extra_fields":{"$ref":"#/definitions/test_json_schema4__WithExtraFields"}},"required":[]},"test_json_schema4__Rectangle":{"type":"object","properties":{"width":{"type":"number"},"height":{"type":"number"}},"required":[]},"test_json_schema4__Rectangle__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Rectangle"]},"width":{"type":"number"},"height":{"type":"number"}},"required":[]},"test_json_schema4__Square":{"type":"object","properties":{"width":{"type":"number"}},"required":[]},"test_json_schema4__Square__tagged":{"type":"object","properties":{"shape":{"type":"string","enum":["Square"]},"width":{"type":"number"}},"required":[]},"test_json_schema4__WithExtraFields":{"type":"object","properties":{"f1":{"type":"string"},"f2":{"type":"string"}},"required":[],"additionalProperties":{"type":"string"}}}})";
|
||||||
|
|
||||||
EXPECT_EQ(json_schema, expected);
|
EXPECT_EQ(json_schema, expected);
|
||||||
}
|
}
|
||||||
} // namespace test_json_schema
|
} // namespace test_json_schema4
|
||||||
|
|||||||
+1
-1
Submodule vcpkg updated: cd124b84fe...e113942454
+3
-3
@@ -48,8 +48,8 @@
|
|||||||
"version>=": "3.9.3"
|
"version>=": "3.9.3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "toml11",
|
"name": "tomlplusplus",
|
||||||
"version>=": "4.2.0"
|
"version>=": "3.4.0#1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "yaml-cpp",
|
"name": "yaml-cpp",
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
"version>=": "2022-02-06#1"
|
"version>=": "2022-02-06#1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"vcpkg-pkgconfig-get-modules",
|
"name": "vcpkg-pkgconfig-get-modules",
|
||||||
"version>=": "2024-04-03"
|
"version>=": "2024-04-03"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user