Class: OpenapiContracts::Doc::Parameter
- Inherits:
-
Object
- Object
- OpenapiContracts::Doc::Parameter
- Defined in:
- lib/openapi_contracts/doc/parameter.rb
Instance Attribute Summary collapse
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #in_path? ⇒ Boolean
- #in_query? ⇒ Boolean
-
#initialize(spec) ⇒ Parameter
constructor
A new instance of Parameter.
- #matches?(value) ⇒ Boolean
- #required? ⇒ Boolean
- #schema_for_validation ⇒ Object
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 = spec.to_h @name = ['name'] @in = ['in'] @required = ['required'] end |
Instance Attribute Details
#in ⇒ Object (readonly)
Returns the value of attribute in.
3 4 5 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 3 def in @in end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 3 def name @name end |
#schema ⇒ Object (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
13 14 15 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 13 def in_path? @in == 'path' end |
#in_query? ⇒ Boolean
17 18 19 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 17 def in_query? @in == 'query' end |
#matches?(value) ⇒ 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
27 28 29 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 27 def required? @required == true end |
#schema_for_validation ⇒ Object
31 32 33 |
# File 'lib/openapi_contracts/doc/parameter.rb', line 31 def schema_for_validation @spec.navigate('schema') end |