request_handler 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +12 -13
- data/CHANGELOG.md +14 -0
- data/README.md +4 -2
- data/lib/request_handler/base.rb +16 -1
- data/lib/request_handler/builder/fieldsets_resource_builder.rb +1 -1
- data/lib/request_handler/builder/headers_builder.rb +23 -0
- data/lib/request_handler/builder/options_builder.rb +10 -1
- data/lib/request_handler/fieldsets_parser.rb +3 -3
- data/lib/request_handler/filter_parser.rb +1 -1
- data/lib/request_handler/header_parser.rb +30 -3
- data/lib/request_handler/include_option_parser.rb +1 -1
- data/lib/request_handler/page_parser.rb +1 -1
- data/lib/request_handler/query_parser.rb +1 -1
- data/lib/request_handler/sort_option_parser.rb +1 -1
- data/lib/request_handler/validation/definition_engine.rb +1 -1
- data/lib/request_handler/version.rb +1 -1
- data/request_handler.gemspec +2 -2
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84a7da676c652eb23c13f36d57e89b8808909c404a6874fb76b2f7c56a72b8f7
|
4
|
+
data.tar.gz: 8aeea4b06cfacba6ef4553974c07e705b6482753cd49bb3322d18c1a86faeb1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9ac556ccfe78a670a5733cae9cb1ca2b3030119150feab16b73953336621e25657f6f9598c8e50d93cd9fcae05c633d65a9c96f6002c6fd09d3789706a92b24
|
7
|
+
data.tar.gz: f1d9f617c904954c7029d3d065ddeb2ab19f6a232b9f54bc2e03d528f0be02e77edec90971002c003bad1bfbd8fc4f01094c562526c3baa80c7bc54ea8fcb2f0
|
data/.circleci/config.yml
CHANGED
@@ -19,7 +19,6 @@ common_steps: &common_steps
|
|
19
19
|
- vendor/bundle
|
20
20
|
|
21
21
|
- run: ruby -v
|
22
|
-
- run: bundle exec danger
|
23
22
|
- run:
|
24
23
|
name: run tests
|
25
24
|
command: |
|
@@ -42,24 +41,24 @@ common_steps: &common_steps
|
|
42
41
|
|
43
42
|
version: 2
|
44
43
|
jobs:
|
45
|
-
ruby-2.
|
44
|
+
ruby-2.6:
|
46
45
|
docker:
|
47
|
-
- image: circleci/ruby:2.
|
46
|
+
- image: circleci/ruby:2.6
|
48
47
|
steps:
|
49
48
|
*common_steps
|
50
|
-
ruby-2.
|
49
|
+
ruby-2.7:
|
51
50
|
docker:
|
52
|
-
- image: circleci/ruby:2.
|
51
|
+
- image: circleci/ruby:2.7
|
53
52
|
steps:
|
54
53
|
*common_steps
|
55
|
-
jruby-9.
|
54
|
+
jruby-9.3:
|
56
55
|
docker:
|
57
|
-
- image: circleci/jruby:9.
|
56
|
+
- image: circleci/jruby:9.3
|
58
57
|
steps:
|
59
58
|
*common_steps
|
60
|
-
jruby-9.
|
59
|
+
jruby-9.3-indy:
|
61
60
|
docker:
|
62
|
-
- image: circleci/jruby:9.
|
61
|
+
- image: circleci/jruby:9.3
|
63
62
|
environment:
|
64
63
|
JRUBY_OPTS: '-Xcompile.invokedynamic=true'
|
65
64
|
steps:
|
@@ -69,7 +68,7 @@ workflows:
|
|
69
68
|
version: 2
|
70
69
|
build:
|
71
70
|
jobs:
|
72
|
-
- ruby-2.
|
73
|
-
- ruby-2.
|
74
|
-
- jruby-9.
|
75
|
-
- jruby-9.
|
71
|
+
- ruby-2.6
|
72
|
+
- ruby-2.7
|
73
|
+
- jruby-9.3
|
74
|
+
- jruby-9.3-indy
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [2.2.0] - 2022-02-25
|
10
|
+
### Changed
|
11
|
+
- The definition engine now makes use of the translated error messages to return more useful messages
|
12
|
+
|
13
|
+
## [2.1.1] - 2021-06-14
|
14
|
+
### Fixed
|
15
|
+
- Change error object's source attribute from `param` to `parameters` to align with JSONAPI specification
|
16
|
+
|
17
|
+
## [2.1.0] - 2020-04-01
|
18
|
+
### Added
|
19
|
+
- Headers validation
|
20
|
+
|
7
21
|
## [2.0.0] - 2019-11-19
|
8
22
|
### Changed
|
9
23
|
- BREAKING: Required configuration of validation engine
|
data/README.md
CHANGED
@@ -82,7 +82,7 @@ the abstract class `RequestHandler::Validation::Engine`
|
|
82
82
|
To set up a handler, you need create a class which inherits from
|
83
83
|
`RequestHandler::Base`, providing at least the options block and a `to_dto`
|
84
84
|
method with the parts you want to use. To use it, create a new instance of the
|
85
|
-
handler passing in the request, after that you can use the handler.
|
85
|
+
handler passing in the request, after that you can use the handler.to_dto method to
|
86
86
|
process and access the data. Here is a short example, check
|
87
87
|
`spec/integration/request_handler_spec.rb` for a detailed one.
|
88
88
|
|
@@ -249,7 +249,7 @@ class CreateQuestionHandler < RequestHandler::Base
|
|
249
249
|
end
|
250
250
|
```
|
251
251
|
|
252
|
-
Assuming that the request consists of a json file `question.json` containing
|
252
|
+
Assuming that the request consists of a json file `question.json` containing
|
253
253
|
``` json
|
254
254
|
{
|
255
255
|
"id": "1",
|
@@ -472,6 +472,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/runtas
|
|
472
472
|
This project is intended to be a safe, welcoming space for collaboration, and
|
473
473
|
contributors are expected to adhere to the [code of conduct][cc].
|
474
474
|
|
475
|
+
Check out our [career page](https://www.runtastic.com/career/) if you'd like to work with us.
|
476
|
+
|
475
477
|
## License
|
476
478
|
The gem is available as open source under [the terms of the MIT License][mit].
|
477
479
|
|
data/lib/request_handler/base.rb
CHANGED
@@ -51,7 +51,7 @@ module RequestHandler
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def headers
|
54
|
-
@headers ||=
|
54
|
+
@headers ||= parse_headers
|
55
55
|
end
|
56
56
|
|
57
57
|
def body_params
|
@@ -105,6 +105,21 @@ module RequestHandler
|
|
105
105
|
result.empty? ? defaults : result
|
106
106
|
end
|
107
107
|
|
108
|
+
def parse_headers
|
109
|
+
HeaderParser.new(header_parser_params).run
|
110
|
+
end
|
111
|
+
|
112
|
+
def header_parser_params
|
113
|
+
params = { env: request.env }
|
114
|
+
|
115
|
+
return params if config.nil?
|
116
|
+
|
117
|
+
params.merge(
|
118
|
+
schema: config.lookup('headers.schema'),
|
119
|
+
schema_options: execute_options(config.lookup('headers.options'))
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
108
123
|
def parse_body_params
|
109
124
|
BodyParser.new(
|
110
125
|
request: request,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'request_handler/builder/base'
|
4
|
+
|
5
|
+
module RequestHandler
|
6
|
+
module Builder
|
7
|
+
class HeadersBuilder < Base
|
8
|
+
Headers = Struct.new(:schema, :options)
|
9
|
+
|
10
|
+
def create_klass_struct
|
11
|
+
@result = Headers.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def schema(value)
|
15
|
+
@result.schema = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def options(value)
|
19
|
+
@result.options = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'request_handler/builder/base'
|
4
|
+
require 'request_handler/builder/headers_builder'
|
4
5
|
require 'request_handler/builder/page_builder'
|
5
6
|
require 'request_handler/builder/include_options_builder'
|
6
7
|
require 'request_handler/builder/sort_options_builder'
|
@@ -14,7 +15,7 @@ module RequestHandler
|
|
14
15
|
module Builder
|
15
16
|
class OptionsBuilder < Base
|
16
17
|
Options = Struct.new(:page, :include_options, :sort_options, :filter, :query, :body,
|
17
|
-
:multipart, :fieldsets)
|
18
|
+
:multipart, :fieldsets, :headers)
|
18
19
|
|
19
20
|
def create_klass_struct
|
20
21
|
@result = Options.new
|
@@ -52,6 +53,10 @@ module RequestHandler
|
|
52
53
|
@result.fieldsets = build_fieldsets(&block)
|
53
54
|
end
|
54
55
|
|
56
|
+
def headers(&block)
|
57
|
+
@result.headers = build_headers(&block)
|
58
|
+
end
|
59
|
+
|
55
60
|
def build_page(&block)
|
56
61
|
Docile.dsl_eval(PageBuilder.new, &block).build
|
57
62
|
end
|
@@ -83,6 +88,10 @@ module RequestHandler
|
|
83
88
|
def build_fieldsets(&block)
|
84
89
|
Docile.dsl_eval(FieldsetsBuilder.new, &block).build
|
85
90
|
end
|
91
|
+
|
92
|
+
def build_headers(&block)
|
93
|
+
Docile.dsl_eval(HeadersBuilder.new, &block).build
|
94
|
+
end
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
@@ -46,7 +46,7 @@ module RequestHandler
|
|
46
46
|
raise FieldsetsParamsError, [{ code: 'INVALID_QUERY_PARAMETER',
|
47
47
|
status: '400',
|
48
48
|
detail: "allowed fieldset does not include '#{option}'",
|
49
|
-
source: {
|
49
|
+
source: { parameter: "fields[#{type}]" } }]
|
50
50
|
end
|
51
51
|
|
52
52
|
def check_required_fieldsets_types(fieldsets)
|
@@ -62,7 +62,7 @@ module RequestHandler
|
|
62
62
|
code: 'INVALID_QUERY_PARAMETER',
|
63
63
|
status: '400',
|
64
64
|
detail: "fieldset for '#{type}' not allowed",
|
65
|
-
source: {
|
65
|
+
source: { parameter: "fields[#{type}]" }
|
66
66
|
}
|
67
67
|
]
|
68
68
|
end
|
@@ -77,7 +77,7 @@ module RequestHandler
|
|
77
77
|
{
|
78
78
|
code: 'MISSING_QUERY_PARAMETER',
|
79
79
|
status: '400',
|
80
|
-
source: {
|
80
|
+
source: { parameter: '' },
|
81
81
|
detail: "missing required parameter fields[#{type}]"
|
82
82
|
}
|
83
83
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'request_handler/schema_parser'
|
3
4
|
require 'request_handler/error'
|
5
|
+
|
4
6
|
module RequestHandler
|
5
|
-
class HeaderParser
|
6
|
-
def initialize(env:)
|
7
|
+
class HeaderParser < SchemaParser
|
8
|
+
def initialize(env:, schema: nil, schema_options: {})
|
9
|
+
super(schema: schema, schema_options: schema_options) unless schema.nil?
|
10
|
+
|
7
11
|
raise MissingArgumentError, env: 'is missing' if env.nil?
|
8
12
|
@headers = Helper.deep_transform_keys_in_object(env.select { |k, _v| k.start_with?('HTTP_') }) do |k|
|
9
13
|
k[5..-1].downcase.to_sym
|
@@ -11,11 +15,34 @@ module RequestHandler
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def run
|
14
|
-
headers
|
18
|
+
return headers if schema.nil?
|
19
|
+
|
20
|
+
validate_headers!
|
15
21
|
end
|
16
22
|
|
17
23
|
private
|
18
24
|
|
25
|
+
def validate_headers!
|
26
|
+
validate_schema(headers)
|
27
|
+
rescue SchemaValidationError => e
|
28
|
+
raise ExternalArgumentError, external_argument_error_params(e)
|
29
|
+
end
|
30
|
+
|
31
|
+
def external_argument_error_params(error)
|
32
|
+
error.errors.map do |schema_error|
|
33
|
+
header = schema_error[:source][:pointer]
|
34
|
+
{
|
35
|
+
status: '400',
|
36
|
+
code: "#{headers[header.to_sym] ? 'INVALID' : 'MISSING'}_HEADER",
|
37
|
+
detail: "#{format_header_name(header)} #{schema_error[:detail]}"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_header_name(name)
|
43
|
+
name.split('_').map(&:capitalize).join('-')
|
44
|
+
end
|
45
|
+
|
19
46
|
attr_reader :headers
|
20
47
|
end
|
21
48
|
end
|
data/request_handler.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.description = 'shared base for request_handler using dry-* gems'
|
15
15
|
spec.homepage = 'https://github.com/runtastic/request_handler'
|
16
16
|
spec.license = 'MIT'
|
17
|
-
spec.required_ruby_version = '~> 2.
|
17
|
+
spec.required_ruby_version = '~> 2.6'
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
20
|
f.match(%r{^(test|spec|features)/})
|
@@ -44,5 +44,5 @@ Gem::Specification.new do |spec|
|
|
44
44
|
|
45
45
|
spec.add_development_dependency 'rack'
|
46
46
|
|
47
|
-
spec.add_development_dependency 'definition', '~> 0.
|
47
|
+
spec.add_development_dependency 'definition', '~> 0.7'
|
48
48
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Eger
|
8
8
|
- Dominik Goltermann
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: docile
|
@@ -241,14 +241,14 @@ dependencies:
|
|
241
241
|
requirements:
|
242
242
|
- - "~>"
|
243
243
|
- !ruby/object:Gem::Version
|
244
|
-
version: '0.
|
244
|
+
version: '0.7'
|
245
245
|
type: :development
|
246
246
|
prerelease: false
|
247
247
|
version_requirements: !ruby/object:Gem::Requirement
|
248
248
|
requirements:
|
249
249
|
- - "~>"
|
250
250
|
- !ruby/object:Gem::Version
|
251
|
-
version: '0.
|
251
|
+
version: '0.7'
|
252
252
|
description: shared base for request_handler using dry-* gems
|
253
253
|
email:
|
254
254
|
- andreas.eger@runtastic.com
|
@@ -281,6 +281,7 @@ files:
|
|
281
281
|
- lib/request_handler/builder/fieldsets_builder.rb
|
282
282
|
- lib/request_handler/builder/fieldsets_resource_builder.rb
|
283
283
|
- lib/request_handler/builder/filter_builder.rb
|
284
|
+
- lib/request_handler/builder/headers_builder.rb
|
284
285
|
- lib/request_handler/builder/include_options_builder.rb
|
285
286
|
- lib/request_handler/builder/multipart_builder.rb
|
286
287
|
- lib/request_handler/builder/multipart_resource_builder.rb
|
@@ -318,7 +319,7 @@ homepage: https://github.com/runtastic/request_handler
|
|
318
319
|
licenses:
|
319
320
|
- MIT
|
320
321
|
metadata: {}
|
321
|
-
post_install_message:
|
322
|
+
post_install_message:
|
322
323
|
rdoc_options: []
|
323
324
|
require_paths:
|
324
325
|
- lib
|
@@ -326,15 +327,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
326
327
|
requirements:
|
327
328
|
- - "~>"
|
328
329
|
- !ruby/object:Gem::Version
|
329
|
-
version: '2.
|
330
|
+
version: '2.6'
|
330
331
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
331
332
|
requirements:
|
332
333
|
- - ">="
|
333
334
|
- !ruby/object:Gem::Version
|
334
335
|
version: '0'
|
335
336
|
requirements: []
|
336
|
-
rubygems_version: 3.
|
337
|
-
signing_key:
|
337
|
+
rubygems_version: 3.1.2
|
338
|
+
signing_key:
|
338
339
|
specification_version: 4
|
339
340
|
summary: shared base for request_handler using dry-* gems
|
340
341
|
test_files: []
|