Class: Dry::Doc::Value

Inherits:
Struct
  • Object
show all
Defined in:
lib/dry/doc/value.rb

Defined Under Namespace

Modules: Types

Constant Summary collapse

T =
::Dry::Types.module

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.as_open_apiObject



40
41
42
# File 'lib/dry/doc/value.rb', line 40

def as_open_api
  doc.as_json
end

.attribute(name, type = nil, opts = {}, &nested) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dry/doc/value.rb', line 48

def attribute name, type=nil, opts={}, &nested
  if nested
    opts = type || {}
    inline_class = build_type :"#{self.name}::#{name}", &nested
    ::Dry::Doc::Value::Types::Inlines.add inline_class
    type = types.instance inline_class
    type = type.optional if opts[:optional]
  end

  doc.register name, type, 
    description: opts.delete(:description)
  super name, type
end

.docObject



32
33
34
# File 'lib/dry/doc/value.rb', line 32

def doc
  @_doc ||= ::Dry::Doc::Schema.new self
end

.inspectObject



62
63
64
# File 'lib/dry/doc/value.rb', line 62

def inspect
  "<#{name}>"
end

.refObject



44
45
46
# File 'lib/dry/doc/value.rb', line 44

def ref
  "#/definitions/#{@ref}" if @ref
end

.typesObject



36
37
38
# File 'lib/dry/doc/value.rb', line 36

def types
  ::Dry::Doc::Value::Types
end

Instance Method Details

#as_json(*_) ⇒ Object



76
77
78
# File 'lib/dry/doc/value.rb', line 76

def as_json *_
  to_h
end