lib/modern/doc_generator/open_api3/schemas.rb in modern-0.4.3 vs lib/modern/doc_generator/open_api3/schemas.rb in modern-0.4.4
- old
+ new
@@ -81,10 +81,12 @@
def _build_schema_value(ret, name_to_class, entry)
registered_type = @type_registry[entry]
if !registered_type.nil?
registered_type
+ elsif entry.is_a?(Class) && entry < Dry::Struct
+ _struct_ref(entry)
elsif entry.is_a?(Dry::Types::Sum::Constrained)
if entry.left.type.primitive == NilClass
# it's a nullable field
_build_schema_value(ret, name_to_class, entry.right).merge(nullable: true)
else
@@ -101,29 +103,29 @@
# TODO: dig deeper into the actual behavior of Constrained (dry-logic)
# This is probably a can of worms. More:
# http://dry-rb.org/gems/dry-types/constraints/
_build_schema_value(ret, name_to_class, entry.type)
- elsif entry.is_a?(Dry::Types::Default)
- # this just unwraps the default value
+ elsif entry.is_a?(Dry::Types::Default) || entry.is_a?(Dry::Struct::Constructor) || entry.is_a?(Dry::Types::Constructor)
+ # this just unwraps the underlying value
_build_schema_value(ret, name_to_class, entry.type)
elsif entry.is_a?(Dry::Types::Definition)
primitive = entry.primitive
- if primitive.ancestors.include?(Dry::Struct)
+ if primitive < Dry::Struct
# TODO: make sure I'm understanding this correctly
# It feels weird to have to oneOf a $ref, but I can't figure out a
# syntax that doesn't require it.
_build_struct(ret, name_to_class, primitive)
{
oneOf: [
_struct_ref(primitive)
]
}
- elsif primitive.ancestors.include?(Hash)
+ elsif primitive < Hash
_build_object_from_schema(ret, name_to_class, entry.member_types)
- elsif primitive.ancestors.include?(Array)
+ elsif primitive < Array
{
type: "array",
items: _build_schema_value(ret, name_to_class, entry.member)
}
else