Added support for JSON schemata for the Reflector type; fixes #509 (#527)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-10-19 18:23:27 +02:00
committed by GitHub
parent 83951fd90b
commit dfcbff981e
3 changed files with 63 additions and 5 deletions
+11 -1
View File
@@ -193,7 +193,9 @@ struct Parser {
} else if constexpr (internal::is_validator_v<U>) {
return make_validated<U>(_definitions);
} else if constexpr (internal::has_reflection_type_v<U>) {
} else if constexpr (internal::has_reflection_type_v<U> ||
internal::has_read_reflector<U> ||
internal::has_write_reflector<U>) {
return make_reference<U>(_definitions);
} else {
@@ -235,13 +237,21 @@ struct Parser {
std::map<std::string, schema::Type>* _definitions) {
using Type = schema::Type;
const auto name = make_type_name<U>();
if (_definitions->find(name) == _definitions->end()) {
(*_definitions)[name] =
Type{Type::Integer{}}; // Placeholder to avoid infinite loop.
if constexpr (internal::has_reflection_type_v<U>) {
(*_definitions)[name] =
Parser<R, W, typename U::ReflectionType, ProcessorsType>::to_schema(
_definitions);
} else if constexpr (internal::has_read_reflector<U> ||
internal::has_write_reflector<U>) {
(*_definitions)[name] = Parser<R, W, typename Reflector<U>::ReflType,
ProcessorsType>::to_schema(_definitions);
} else {
using NamedTupleType = internal::processed_t<U, ProcessorsType>;
(*_definitions)[name] =
+2 -4
View File
@@ -4,8 +4,7 @@
#include "../type_name_t.hpp"
#include "is_tagged_union_wrapper.hpp"
namespace rfl {
namespace parsing {
namespace rfl::parsing {
inline std::string replace_non_alphanumeric(std::string _str) {
for (auto& ch : _str) {
@@ -24,7 +23,6 @@ static std::string make_type_name() {
}
}
} // namespace parsing
} // namespace rfl
} // namespace rfl::parsing
#endif