rails-param-validation 0.1.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78a64263517a4c6d2d0c0e649cc7a3e4708f4ed1abb96beffb8a52b2acc2f8a0
4
- data.tar.gz: dfd6039f8ce21dd31c7f96a93daf9c6b10a490107a4f96be6ceaa33f26e1a7fd
3
+ metadata.gz: b29564381a128aaceb53b5099cd568cc4cc805545341903fabdde48dfbe54154
4
+ data.tar.gz: 8374f3dad8e614244d4b2170f8eb218bcc1baf70d965d584d3bc3ce0610c2c0f
5
5
  SHA512:
6
- metadata.gz: c4862edac9546192dddce87b4d0e846443611db3426ad4b91eb5c3827ddbc72cc7e283dfef1f3ed624ee18fcce52db21a4aa04b5ef359dcf85ea5f707dba5caf
7
- data.tar.gz: d0606f8d37a4f2bf9e822c410779be3efbefec1e81c505179d3ecc26780202c0961e6f412bd1d4503a354d5b6c8395dd14ba6027f35840783574ad1a75bd642a
6
+ metadata.gz: 0dd8afd3ab0c862392cad28163f1001394c4ee028dea4acd98ce1dfa48c14cf48d0a5a2ddcdb7dd38f941dd5009aac88b5ccc29f9ff55add900b1ca4b0a63111
7
+ data.tar.gz: b09a6e69a242dca2fff49df1a11cf3379d53ed0d10aa241c9d2657e1b052889ce93e40013ee15d614841bdd3b69b7ce9d13fd808608cdce9aa90b872cedb5942
@@ -24,15 +24,15 @@ end
24
24
 
25
25
  **query_param**
26
26
 
27
- Parameter passed via query string, e.g. `http://localhost/my_action?parameter=value`. The first value is the parameter name (which must be a symbol), the second is the [type definition](./docs/type-definition.md). The last (optional) parameter to this call is the description.
27
+ Parameter passed via query string, e.g. `http://localhost/my_action?parameter=value`. The first value is the parameter name (which must be a symbol), the second is the [type definition](./type-definition.md). The last (optional) parameter to this call is the description.
28
28
 
29
29
  **path_param**
30
30
 
31
- Parameter passed as part of the actions route, e.g. `http://localhost/my_action/value` where the route definition is something like `get '/my_action/:parameter, to: 'my_controller#my_action'`. The first value is the parameter name (which must be a symbol), the second is the [type definition](./docs/type-definition.md). The last (optional) parameter to this call is the description.
31
+ Parameter passed as part of the actions route, e.g. `http://localhost/my_action/value` where the route definition is something like `get '/my_action/:parameter, to: 'my_controller#my_action'`. The first value is the parameter name (which must be a symbol), the second is the [type definition](./type-definition.md). The last (optional) parameter to this call is the description.
32
32
 
33
33
  **body_param**
34
34
 
35
- Parameter as part of a JSON body in a POST/PUT/PATCH operation. The first value is the parameter name (which must be a symbol) as the JSON body must be a JSON object which has a key named like the parameter. The second parameter is the [type definition](./docs/type-definition.md). The last (optional) parameter to this call is the description.
35
+ Parameter as part of a JSON body in a POST/PUT/PATCH operation. The first value is the parameter name (which must be a symbol) as the JSON body must be a JSON object which has a key named like the parameter. The second parameter is the [type definition](./type-definition.md). The last (optional) parameter to this call is the description.
36
36
 
37
37
  Example body:
38
38
 
@@ -55,7 +55,7 @@ end
55
55
 
56
56
  **response**
57
57
 
58
- The response annotation defines the possible responses the action can generate, where the first parameter is the HTTP status code, the second is the [type definition](./docs/type-definition.md). The last (optional) parameter to this call is the description.
58
+ The response annotation defines the possible responses the action can generate, where the first parameter is the HTTP status code, the second is the [type definition](./type-definition.md). The last (optional) parameter to this call is the description.
59
59
 
60
60
  **accept_all_params**
61
61
 
@@ -38,7 +38,9 @@ module RailsParamValidation
38
38
 
39
39
  if result.matches?
40
40
  # Copy the parameters if the validation succeeded
41
- @validated_parameters = result.value
41
+ @validated_parameters = ActiveSupport::HashWithIndifferentAccess.new(
42
+ result.value.merge(action: action, controller: controller)
43
+ )
42
44
  else
43
45
  # Render an appropriate error message
44
46
  _render_invalid_param_response result
@@ -50,22 +52,30 @@ module RailsParamValidation
50
52
  end
51
53
 
52
54
  def _render_invalid_param_response(result)
53
- # Depending on the accept header, choose the way to answer
54
- respond_to do |format|
55
- format.html do
56
- if RailsParamValidation.config.use_default_html_response
57
- _create_html_error result
58
- else
59
- raise ParamValidationFailedError.new(result)
55
+ if respond_to? :respond_to
56
+ # Depending on the accept header, choose the way to answer
57
+ respond_to do |format|
58
+ format.html do
59
+ if RailsParamValidation.config.use_default_html_response
60
+ _create_html_error result
61
+ else
62
+ raise ParamValidationFailedError.new(result)
63
+ end
60
64
  end
61
- end
62
- format.json do
63
- if RailsParamValidation.config.use_default_json_response
64
- _create_json_error result
65
- else
66
- raise ParamValidationFailedError.new(result)
65
+ format.json do
66
+ if RailsParamValidation.config.use_default_json_response
67
+ _create_json_error result
68
+ else
69
+ raise ParamValidationFailedError.new(result)
70
+ end
67
71
  end
68
72
  end
73
+ else
74
+ if RailsParamValidation.config.use_default_json_response
75
+ _create_json_error result
76
+ else
77
+ raise ParamValidationFailedError.new(result)
78
+ end
69
79
  end
70
80
  end
71
81
 
@@ -20,6 +20,11 @@ module RailsParamValidation
20
20
  ActionController::Base.send :include, AnnotationExtension
21
21
  ActionController::Base.send :include, CustomTypesExtension
22
22
  ActionController::Base.send :extend, RailsParamValidation::Types
23
+
24
+ ActionController::API.send :include, ActionControllerExtension
25
+ ActionController::API.send :include, AnnotationExtension
26
+ ActionController::API.send :include, CustomTypesExtension
27
+ ActionController::API.send :extend, RailsParamValidation::Types
23
28
  end
24
29
 
25
30
  rake_tasks do
@@ -1,5 +1,9 @@
1
1
  module RailsParamValidation
2
2
 
3
+ def self.register(type, schema)
4
+ AnnotationTypes::CustomT.register type, schema
5
+ end
6
+
3
7
  module AnnotationTypes
4
8
  class AnnotationT
5
9
  attr_reader :inner_type
@@ -3,11 +3,10 @@ module RailsParamValidation
3
3
  class CustomTypeValidator < Validator
4
4
  def initialize(type)
5
5
  super type
6
- @validator = ValidatorFactory.create type.schema
7
6
  end
8
7
 
9
8
  def matches?(path, data)
10
- @validator.matches? path, data
9
+ ValidatorFactory.create(schema.schema).matches? path, data
11
10
  end
12
11
 
13
12
  def to_openapi
@@ -1,3 +1,3 @@
1
1
  module RailsParamValidation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -6,17 +6,17 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Oskar Kirmis"]
7
7
  spec.email = ["oskar.kirmis@posteo.de"]
8
8
 
9
- spec.summary = "Automatically validate rails parameter types"
10
- spec.description = "Automatically validate rails parameter types"
11
- spec.homepage = "https://git.iftrue.de/okirmis/rails-param-validation"
9
+ spec.summary = "Declarative parameter definition and validation for Rails"
10
+ spec.description = "Declarative parameter definition and validation for Rails"
11
+ spec.homepage = "https://okirmis.github.io/rails-param-validation"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://git.iftrue.de/okirmis/rails-param-validation"
19
- spec.metadata["changelog_uri"] = "https://git.iftrue.de/okirmis/rails-param-validation"
18
+ spec.metadata["source_code_uri"] = "https://github.com/okirmis/rails-param-validation"
19
+ spec.metadata["changelog_uri"] = "https://github.com/okirmis/rails-param-validation"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-param-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oskar Kirmis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-08 00:00:00.000000000 Z
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Automatically validate rails parameter types
13
+ description: Declarative parameter definition and validation for Rails
14
14
  email:
15
15
  - oskar.kirmis@posteo.de
16
16
  executables:
@@ -70,14 +70,14 @@ files:
70
70
  - lib/rails-param-validation/validators/uuid.rb
71
71
  - lib/rails-param-validation/version.rb
72
72
  - rails-param-validation.gemspec
73
- homepage: https://git.iftrue.de/okirmis/rails-param-validation
73
+ homepage: https://okirmis.github.io/rails-param-validation
74
74
  licenses:
75
75
  - MIT
76
76
  metadata:
77
77
  allowed_push_host: https://rubygems.org
78
- homepage_uri: https://git.iftrue.de/okirmis/rails-param-validation
79
- source_code_uri: https://git.iftrue.de/okirmis/rails-param-validation
80
- changelog_uri: https://git.iftrue.de/okirmis/rails-param-validation
78
+ homepage_uri: https://okirmis.github.io/rails-param-validation
79
+ source_code_uri: https://github.com/okirmis/rails-param-validation
80
+ changelog_uri: https://github.com/okirmis/rails-param-validation
81
81
  post_install_message:
82
82
  rdoc_options: []
83
83
  require_paths:
@@ -96,5 +96,5 @@ requirements: []
96
96
  rubygems_version: 3.0.1
97
97
  signing_key:
98
98
  specification_version: 4
99
- summary: Automatically validate rails parameter types
99
+ summary: Declarative parameter definition and validation for Rails
100
100
  test_files: []