Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rfl/json/schema/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct Type {
rfl::Flatten<Annotations> annotations{};
rfl::Object<Type> properties{};
std::vector<std::string> required{};
std::shared_ptr<Type> additionalProperties{};
rfl::Variant<bool, std::shared_ptr<Type>> additionalProperties{};
};

struct OneOf {
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/parsing/NamedTupleParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../internal/is_default_val_v.hpp"
#include "../internal/is_extra_fields.hpp"
#include "../internal/is_skip.hpp"
#include "../internal/no_extra_fields_v.hpp"
#include "../internal/nth_element_t.hpp"
#include "../internal/ptr_cast.hpp"
#include "../to_view.hpp"
Expand Down Expand Up @@ -284,6 +285,9 @@ struct NamedTupleParser {
using U = std::remove_cvref_t<typename ExtraFieldsType::Type>;
_schema->additional_properties_ = std::make_shared<schema::Type>(
Parser<R, W, U, ProcessorsType>::to_schema(_definitions));
} else if constexpr (internal::no_extra_fields_v<ProcessorsType> &&
!_no_field_names) {
_schema->additional_properties_ = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/schema/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct RFL_API Type {

struct Object {
rfl::Object<Type> types_;
std::shared_ptr<Type> additional_properties_;
rfl::Variant<bool, std::shared_ptr<Type>> additional_properties_;
};

/// All values are assumed to be required unless explicitly stated otherwise
Expand Down
18 changes: 13 additions & 5 deletions src/rfl/json/to_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,19 @@ schema::Type type_to_json_schema_type(const parsing::schema::Type& _type,
required.push_back(k);
}
}
auto additional_properties =
_t.additional_properties_
? std::make_shared<schema::Type>(type_to_json_schema_type(
*_t.additional_properties_, _no_required))
: std::shared_ptr<schema::Type>();
auto additional_properties = rfl::visit(
[&](const auto& _a)
-> rfl::Variant<bool, std::shared_ptr<schema::Type>> {
using A = std::remove_cvref_t<decltype(_a)>;
if constexpr (std::is_same<A, bool>()) {
return _a;
} else {
return _a ? std::make_shared<schema::Type>(
type_to_json_schema_type(*_a, _no_required))
: std::shared_ptr<schema::Type>();
}
},
_t.additional_properties_);
return schema::Type{.value = schema::Type::Object{
.properties = properties,
.required = required,
Expand Down
Loading