Top Level Namespace

Defined Under Namespace

Modules: Global, RrxDev, Spec Classes: SwaggerConfig

Instance Method Summary collapse

Instance Method Details

#array(type, description = nil) ⇒ Object



38
39
40
# File 'lib/rrx_dev/rswag.rb', line 38

def array(type, description = nil)
  prop_type :array, description, items: type
end

#boolean(description = nil) ⇒ Object



34
35
36
# File 'lib/rrx_dev/rswag.rb', line 34

def boolean(description = nil)
  prop_type :boolean, description
end

#date_time(description = nil) ⇒ Object



30
31
32
# File 'lib/rrx_dev/rswag.rb', line 30

def date_time(description = nil)
  string description, format: :dateTime
end

#enum(vals, description = nil) ⇒ Object



42
43
44
# File 'lib/rrx_dev/rswag.rb', line 42

def enum(vals, description = nil)
  string description, enum: vals
end

#integer(description = nil) ⇒ Object



22
23
24
# File 'lib/rrx_dev/rswag.rb', line 22

def integer(description = nil)
  prop_type :integer, description
end

#object(optional: {}, additional: false, **properties) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/rrx_dev/rswag.rb', line 7

def object(optional: {}, additional: false, **properties)
  {
    type:                 :object,
    required:             properties.keys.map(&:to_s),
    properties:           properties.update(optional),
    additionalProperties: additional
  }.freeze
end

#prop_type(type, description = nil, **options) ⇒ Object



16
17
18
19
20
# File 'lib/rrx_dev/rswag.rb', line 16

def prop_type(type, description = nil, **options)
  t = { type: }.update(options)
  t[:description] = description if description
  t.freeze
end

#ref(to) ⇒ Object

Rswag schema helpers



3
4
5
# File 'lib/rrx_dev/rswag.rb', line 3

def ref(to)
  { '$ref': "#/components/schemas/#{to}" }
end

#string(description = nil, **options) ⇒ Object



26
27
28
# File 'lib/rrx_dev/rswag.rb', line 26

def string(description = nil, **options)
  prop_type :string, description, **options
end

#swagger(&block) ⇒ Object



71
72
73
74
75
# File 'lib/rrx_dev/rswag.rb', line 71

def swagger(&block)
  swagger_config = SwaggerConfig.new
  swagger_config.instance_exec(&block)
  swagger_config.config
end