Class: Lutaml::Hal::EndpointParameter
- Inherits:
-
Object
- Object
- Lutaml::Hal::EndpointParameter
- Defined in:
- lib/lutaml/hal/endpoint_parameter.rb
Overview
OpenAPI-inspired parameter definition for HAL endpoints
Defined Under Namespace
Classes: Schema
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#example ⇒ Object
readonly
Returns the value of attribute example.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
- .cookie(name, **options) ⇒ Object
- .header(name, **options) ⇒ Object
-
.path(name, **options) ⇒ Object
Convenience constructors for different parameter types.
- .query(name, **options) ⇒ Object
Instance Method Summary collapse
- #cookie_parameter? ⇒ Boolean
-
#default_value ⇒ Object
Get the default value for this parameter.
- #header_parameter? ⇒ Boolean
-
#initialize(name:, in:, required: nil, schema: {}, description: nil, example: nil) ⇒ EndpointParameter
constructor
A new instance of EndpointParameter.
-
#path_parameter? ⇒ Boolean
Parameter type checks.
- #query_parameter? ⇒ Boolean
- #validate! ⇒ Object
-
#validate_value(value) ⇒ Object
Validate a parameter value against this parameter’s schema.
Constructor Details
#initialize(name:, in:, required: nil, schema: {}, description: nil, example: nil) ⇒ EndpointParameter
Returns a new instance of EndpointParameter.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 9 def initialize(name:, in:, required: nil, schema: {}, description: nil, example: nil) @name = name.to_s @location = validate_location(binding.local_variable_get(:in)) @required = determine_required(required, @location) @schema = Schema.new(schema) @description = description @example = example validate! end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def description @description end |
#example ⇒ Object (readonly)
Returns the value of attribute example.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def example @example end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def required @required end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 7 def schema @schema end |
Class Method Details
.cookie(name, **options) ⇒ Object
33 34 35 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 33 def self.(name, **) new(name: name, in: :cookie, **) end |
.header(name, **options) ⇒ Object
29 30 31 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 29 def self.header(name, **) new(name: name, in: :header, **) end |
.path(name, **options) ⇒ Object
Convenience constructors for different parameter types
21 22 23 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 21 def self.path(name, **) new(name: name, in: :path, **) end |
.query(name, **options) ⇒ Object
25 26 27 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 25 def self.query(name, **) new(name: name, in: :query, **) end |
Instance Method Details
#cookie_parameter? ⇒ Boolean
50 51 52 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 50 def @location == :cookie end |
#default_value ⇒ Object
Get the default value for this parameter
60 61 62 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 60 def default_value @schema.default end |
#header_parameter? ⇒ Boolean
46 47 48 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 46 def header_parameter? @location == :header end |
#path_parameter? ⇒ Boolean
Parameter type checks
38 39 40 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 38 def path_parameter? @location == :path end |
#query_parameter? ⇒ Boolean
42 43 44 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 42 def query_parameter? @location == :query end |
#validate! ⇒ Object
64 65 66 67 68 69 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 64 def validate! # Path parameters must be required raise ArgumentError, 'Path parameters must be required' if path_parameter? && !@required @schema.validate_definition! end |
#validate_value(value) ⇒ Object
Validate a parameter value against this parameter’s schema
55 56 57 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 55 def validate_value(value) @schema.validate(value) end |