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

#in_query?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/openapi_contracts/doc/parameter.rb', line 17

def in_query?
  @in == 'query'
end

#matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/openapi_contracts/doc/parameter.rb', line 21

def matches?(value)
  errors = schemer.validate(convert_value(value))
  # debug errors.to_a here
  errors.none?
end

#required?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/openapi_contracts/doc/parameter.rb', line 27

def required?
  @required == true
end

#schema_for_validationObject



31
32
33
# File 'lib/openapi_contracts/doc/parameter.rb', line 31

def schema_for_validation
  @spec.navigate('schema')
end