Class: OpenapiContracts::Doc::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/doc/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Parameter

Returns a new instance of Parameter.



5
6
7
8
9
10
11
# File 'lib/openapi_contracts/doc/parameter.rb', line 5

def initialize(spec)
  @spec = spec
  options = spec.to_h
  @name = options['name']
  @in = options['in']
  @required = options['required']
end

Instance Attribute Details

#inObject (readonly)

Returns the value of attribute in.



3
4
5
# File 'lib/openapi_contracts/doc/parameter.rb', line 3

def in
  @in
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/openapi_contracts/doc/parameter.rb', line 3

def name
  @name
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'lib/openapi_contracts/doc/parameter.rb', line 3

def schema
  @schema
end

Instance Method Details

#in_path?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/openapi_contracts/doc/parameter.rb', line 13

def in_path?
  @in == 'path'
end

#matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/openapi_contracts/doc/parameter.rb', line 17

def matches?(value)
  case @spec.dig('schema', 'type')
  when 'integer'
    integer_parameter_matches?(value)
  when 'number'
    number_parameter_matches?(value)
  else
    schemer.valid?(value)
  end
end