Method: Modern::DocGenerator::OpenAPI3::Schemas#_build_struct

Defined in:
lib/modern/doc_generator/open_api3/schemas.rb

#_build_struct(ret, name_to_class, structclass) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/modern/doc_generator/open_api3/schemas.rb', line 50

def _build_struct(ret, name_to_class, structclass)
  # TODO: allow overriding the name of the struct in #/components/schemas
  #       This is actually trickier than it looks, because we need to also
  #       make it referenceable in responses/contents. It probably means an
  #       indirect mapping of classes to names and back again.

  raise "not actually a Dry::Struct class" \
    unless structclass.ancestors.include?(Dry::Struct)

  name = structclass.name.split("::").last

  if name_to_class[name] == structclass
    name
  else
    if !name_to_class[name].nil?
      raise "Duplicate schema name: '#{name}'. Only one class, regardless " \
            "of namespace, can be called this."
    end

    ret[name] = _build_object_from_schema(ret, name_to_class, structclass.schema)
  end

  name # necessary for recursive calls in _build_schema_value
end