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 +4 -4
- data/docs/annotations.md +4 -4
- data/lib/rails-param-validation/rails/extensions/validation_extension.rb +24 -14
- data/lib/rails-param-validation/rails/rails.rb +5 -0
- data/lib/rails-param-validation/types/types.rb +4 -0
- data/lib/rails-param-validation/validators/custom_type.rb +1 -2
- data/lib/rails-param-validation/version.rb +1 -1
- data/rails-param-validation.gemspec +5 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29564381a128aaceb53b5099cd568cc4cc805545341903fabdde48dfbe54154
|
4
|
+
data.tar.gz: 8374f3dad8e614244d4b2170f8eb218bcc1baf70d965d584d3bc3ce0610c2c0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dd8afd3ab0c862392cad28163f1001394c4ee028dea4acd98ce1dfa48c14cf48d0a5a2ddcdb7dd38f941dd5009aac88b5ccc29f9ff55add900b1ca4b0a63111
|
7
|
+
data.tar.gz: b09a6e69a242dca2fff49df1a11cf3379d53ed0d10aa241c9d2657e1b052889ce93e40013ee15d614841bdd3b69b7ce9d13fd808608cdce9aa90b872cedb5942
|
data/docs/annotations.md
CHANGED
@@ -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](./
|
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](./
|
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](./
|
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](./
|
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 =
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
@@ -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
|
-
|
9
|
+
ValidatorFactory.create(schema.schema).matches? path, data
|
11
10
|
end
|
12
11
|
|
13
12
|
def to_openapi
|
@@ -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 = "
|
10
|
-
spec.description = "
|
11
|
-
spec.homepage = "https://
|
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://
|
19
|
-
spec.metadata["changelog_uri"] = "https://
|
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.
|
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-
|
11
|
+
date: 2020-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
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://
|
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://
|
79
|
-
source_code_uri: https://
|
80
|
-
changelog_uri: https://
|
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:
|
99
|
+
summary: Declarative parameter definition and validation for Rails
|
100
100
|
test_files: []
|