Class: Committee::Middleware::Options::RequestValidation

Inherits:
Base
  • Object
show all
Defined in:
lib/committee/middleware/options/request_validation.rb

Constant Summary collapse

DEFAULTS =

Default values

{ strict: false, coerce_recursive: true, allow_get_body: false, check_content_type: true, check_header: true, optimistic_json: false, allow_form_params: true, allow_query_params: true, allow_non_get_query_params: false, allow_blank_structures: false, allow_empty_date_and_datetime: false, parameter_overwrite_by_rails_rule: true, request_body_hash_key: "committee.request_body_hash", query_hash_key: "committee.query_hash", path_hash_key: "committee.path_hash", headers_key: "committee.headers", params_key: "committee.params" }.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#accept_request_filter, #error_class, #error_handler, #ignore_error, #prefix, #raise_error, #schema, #schema_path, #strict_reference_validation

Instance Method Summary collapse

Methods inherited from Base

#[], #fetch, from, #to_h

Constructor Details

#initialize(options = {}) ⇒ RequestValidation

Returns a new instance of RequestValidation.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/committee/middleware/options/request_validation.rb', line 34

def initialize(options = {})
  super(options)

  # Validation related
  @strict = options.fetch(:strict, DEFAULTS[:strict])
  @check_content_type = options.fetch(:check_content_type, DEFAULTS[:check_content_type])
  @check_header = options.fetch(:check_header, DEFAULTS[:check_header])
  @optimistic_json = options.fetch(:optimistic_json, DEFAULTS[:optimistic_json])

  # Type coercion related
  @coerce_date_times = options[:coerce_date_times]
  @coerce_recursive = options.fetch(:coerce_recursive, DEFAULTS[:coerce_recursive])
  @coerce_form_params = options[:coerce_form_params]
  @coerce_path_params = options[:coerce_path_params]
  @coerce_query_params = options[:coerce_query_params]

  # Parameter permission related
  @allow_form_params = options.fetch(:allow_form_params, DEFAULTS[:allow_form_params])
  @allow_query_params = options.fetch(:allow_query_params, DEFAULTS[:allow_query_params])
  @allow_get_body = options.fetch(:allow_get_body, DEFAULTS[:allow_get_body])
  @allow_non_get_query_params = options.fetch(:allow_non_get_query_params, DEFAULTS[:allow_non_get_query_params])
  @allow_blank_structures = options.fetch(:allow_blank_structures, DEFAULTS[:allow_blank_structures])
  @allow_empty_date_and_datetime = options.fetch(:allow_empty_date_and_datetime, DEFAULTS[:allow_empty_date_and_datetime])

  # Rails compatibility
  @parameter_overwrite_by_rails_rule = options.fetch(:parameter_overwrite_by_rails_rule, DEFAULTS[:parameter_overwrite_by_rails_rule])

  # Deserialization
  @deserialize_parameters = options[:deserialize_parameters]

  # Hash keys
  @request_body_hash_key = options.fetch(:request_body_hash_key, DEFAULTS[:request_body_hash_key])
  @query_hash_key = options.fetch(:query_hash_key, DEFAULTS[:query_hash_key])
  @path_hash_key = options.fetch(:path_hash_key, DEFAULTS[:path_hash_key])
  @headers_key = options.fetch(:headers_key, DEFAULTS[:headers_key])
  @params_key = options.fetch(:params_key, DEFAULTS[:params_key])
end

Instance Attribute Details

#allow_blank_structuresObject (readonly)

Returns the value of attribute allow_blank_structures.



26
27
28
# File 'lib/committee/middleware/options/request_validation.rb', line 26

def allow_blank_structures
  @allow_blank_structures
end

#allow_empty_date_and_datetimeObject (readonly)

Returns the value of attribute allow_empty_date_and_datetime.



27
28
29
# File 'lib/committee/middleware/options/request_validation.rb', line 27

def allow_empty_date_and_datetime
  @allow_empty_date_and_datetime
end

#allow_form_paramsObject (readonly)

Returns the value of attribute allow_form_params.



14
15
16
# File 'lib/committee/middleware/options/request_validation.rb', line 14

def allow_form_params
  @allow_form_params
end

#allow_get_bodyObject (readonly)

Returns the value of attribute allow_get_body.



16
17
18
# File 'lib/committee/middleware/options/request_validation.rb', line 16

def allow_get_body
  @allow_get_body
end

#allow_non_get_query_paramsObject (readonly)

Returns the value of attribute allow_non_get_query_params.



17
18
19
# File 'lib/committee/middleware/options/request_validation.rb', line 17

def allow_non_get_query_params
  @allow_non_get_query_params
end

#allow_query_paramsObject (readonly)

Returns the value of attribute allow_query_params.



15
16
17
# File 'lib/committee/middleware/options/request_validation.rb', line 15

def allow_query_params
  @allow_query_params
end

#check_content_typeObject (readonly)

Returns the value of attribute check_content_type.



18
19
20
# File 'lib/committee/middleware/options/request_validation.rb', line 18

def check_content_type
  @check_content_type
end

#check_headerObject (readonly)

Returns the value of attribute check_header.



19
20
21
# File 'lib/committee/middleware/options/request_validation.rb', line 19

def check_header
  @check_header
end

#coerce_date_timesObject (readonly)

Returns the value of attribute coerce_date_times.



9
10
11
# File 'lib/committee/middleware/options/request_validation.rb', line 9

def coerce_date_times
  @coerce_date_times
end

#coerce_form_paramsObject (readonly)

Returns the value of attribute coerce_form_params.



11
12
13
# File 'lib/committee/middleware/options/request_validation.rb', line 11

def coerce_form_params
  @coerce_form_params
end

#coerce_path_paramsObject (readonly)

Returns the value of attribute coerce_path_params.



12
13
14
# File 'lib/committee/middleware/options/request_validation.rb', line 12

def coerce_path_params
  @coerce_path_params
end

#coerce_query_paramsObject (readonly)

Returns the value of attribute coerce_query_params.



13
14
15
# File 'lib/committee/middleware/options/request_validation.rb', line 13

def coerce_query_params
  @coerce_query_params
end

#coerce_recursiveObject (readonly)

Returns the value of attribute coerce_recursive.



10
11
12
# File 'lib/committee/middleware/options/request_validation.rb', line 10

def coerce_recursive
  @coerce_recursive
end

#deserialize_parametersObject (readonly)

Returns the value of attribute deserialize_parameters.



29
30
31
# File 'lib/committee/middleware/options/request_validation.rb', line 29

def deserialize_parameters
  @deserialize_parameters
end

#headers_keyObject (readonly)

Returns the value of attribute headers_key.



24
25
26
# File 'lib/committee/middleware/options/request_validation.rb', line 24

def headers_key
  @headers_key
end

#optimistic_jsonObject (readonly)

Returns the value of attribute optimistic_json.



20
21
22
# File 'lib/committee/middleware/options/request_validation.rb', line 20

def optimistic_json
  @optimistic_json
end

#parameter_overwrite_by_rails_ruleObject (readonly)

Returns the value of attribute parameter_overwrite_by_rails_rule.



28
29
30
# File 'lib/committee/middleware/options/request_validation.rb', line 28

def parameter_overwrite_by_rails_rule
  @parameter_overwrite_by_rails_rule
end

#params_keyObject (readonly)

Returns the value of attribute params_key.



25
26
27
# File 'lib/committee/middleware/options/request_validation.rb', line 25

def params_key
  @params_key
end

#path_hash_keyObject (readonly)

Returns the value of attribute path_hash_key.



23
24
25
# File 'lib/committee/middleware/options/request_validation.rb', line 23

def path_hash_key
  @path_hash_key
end

#query_hash_keyObject (readonly)

Returns the value of attribute query_hash_key.



22
23
24
# File 'lib/committee/middleware/options/request_validation.rb', line 22

def query_hash_key
  @query_hash_key
end

#request_body_hash_keyObject (readonly)

Returns the value of attribute request_body_hash_key.



21
22
23
# File 'lib/committee/middleware/options/request_validation.rb', line 21

def request_body_hash_key
  @request_body_hash_key
end

#strictObject (readonly)

RequestValidation specific options



8
9
10
# File 'lib/committee/middleware/options/request_validation.rb', line 8

def strict
  @strict
end