openapi_first 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/openapi_first/rack/test.rb +5 -0
- data/lib/openapi_first/ref_resolver.rb +2 -2
- data/lib/openapi_first/request_body_parsers.rb +21 -4
- data/lib/openapi_first/schema/validation_error.rb +1 -1
- data/lib/openapi_first/schema/validation_result.rb +3 -1
- data/lib/openapi_first/test/plain_helpers.rb +7 -2
- data/lib/openapi_first/version.rb +1 -1
- metadata +3 -3
- data/lib/openapi_first/body_parser.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d85c4425401207c7ff52f921d34c77c7ee6c6ee5671ecfbac36ca5619685cdb6
|
4
|
+
data.tar.gz: afcb639314fd7f049b93d29dd89cbb88260abbcb66f1e5a20b8c1c01ade063b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c9e2fadb4ba81ab68026b5b2f6c44daf9710d3e3fc27e32175f9691f885839f6fda6cd1f477c7e347b88ce0d27e933bd30642d1773665301613049df092e7a5
|
7
|
+
data.tar.gz: 493dcfa9384f1462b7ab713dcc8c3c9b7cb2c6f63a4977f0ed3485d65811a3cd0869c2ddc5f8dc9cd5efacaa773836b0290d2be7f88b4af20de9adad2aa7c7b6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.2.4
|
6
|
+
|
7
|
+
- Fix request validation file uploads in multipart/form-data requests with nested fields (https://github.com/ahx/openapi_first/issues/324)
|
8
|
+
- Add more error details to validation result (https://github.com/ahx/openapi_first/pull/322)
|
9
|
+
|
5
10
|
## 2.2.3
|
6
11
|
|
7
12
|
- Respect global JSONSchemer configuration (https://github.com/ahx/openapi_first/pull/318)
|
@@ -55,7 +55,7 @@ module OpenapiFirst
|
|
55
55
|
value = Hana::Pointer.new(pointer[1..]).eval(context)
|
56
56
|
raise "Unknown reference #{pointer} in #{context}" unless value
|
57
57
|
|
58
|
-
return RefResolver.for(value, dir:)
|
58
|
+
return RefResolver.for(value, dir:, context:)
|
59
59
|
end
|
60
60
|
|
61
61
|
relative_path, file_pointer = pointer.split('#')
|
@@ -65,7 +65,7 @@ module OpenapiFirst
|
|
65
65
|
file_contents = FileLoader.load(full_path)
|
66
66
|
new_dir = File.dirname(full_path)
|
67
67
|
value = Hana::Pointer.new(file_pointer).eval(file_contents)
|
68
|
-
RefResolver.for(value, dir: new_dir)
|
68
|
+
RefResolver.for(value, dir: new_dir, context: file_contents)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -36,11 +36,28 @@ module OpenapiFirst
|
|
36
36
|
Failure.fail!(:invalid_body, message: 'Failed to parse request body as JSON')
|
37
37
|
end)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
# Parses multipart/form-data requests and currently puts the contents of a file upload at the parsed hash values.
|
40
|
+
# NOTE: This behavior will probably change in the next major version.
|
41
|
+
# The uploaded file should not be read during request validation.
|
42
|
+
module MultipartBodyParser
|
43
|
+
def self.call(request)
|
44
|
+
request.POST.transform_values do |value|
|
45
|
+
unpack_value(value)
|
46
|
+
end
|
42
47
|
end
|
43
|
-
|
48
|
+
|
49
|
+
def self.unpack_value(value)
|
50
|
+
return value.map { unpack_value(_1) } if value.is_a?(Array)
|
51
|
+
return value unless value.is_a?(Hash)
|
52
|
+
return value[:tempfile]&.read if value.key?(:tempfile)
|
53
|
+
|
54
|
+
value.transform_values do |v|
|
55
|
+
unpack_value(v)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
register('multipart/form-data', MultipartBodyParser)
|
44
61
|
|
45
62
|
register('application/x-www-form-urlencoded', lambda(&:POST))
|
46
63
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OpenapiFirst
|
4
4
|
class Schema
|
5
5
|
# One of multiple validation errors. Returned by Schema::ValidationResult#errors.
|
6
|
-
ValidationError = Data.define(:message, :data_pointer, :schema_pointer, :type, :details) do
|
6
|
+
ValidationError = Data.define(:value, :message, :data_pointer, :schema_pointer, :type, :details, :schema) do
|
7
7
|
# @deprecated Please use {#message} instead
|
8
8
|
def error
|
9
9
|
warn 'OpenapiFirst::Schema::ValidationError#error is deprecated. Use #message instead.'
|
@@ -16,11 +16,13 @@ module OpenapiFirst
|
|
16
16
|
def errors
|
17
17
|
@errors ||= @validation.map do |err|
|
18
18
|
ValidationError.new(
|
19
|
+
value: err['data'],
|
19
20
|
message: err['error'],
|
20
21
|
data_pointer: err['data_pointer'],
|
21
22
|
schema_pointer: err['schema_pointer'],
|
22
23
|
type: err['type'],
|
23
|
-
details: err['details']
|
24
|
+
details: err['details'],
|
25
|
+
schema: err['schema']
|
24
26
|
)
|
25
27
|
end
|
26
28
|
end
|
@@ -18,8 +18,13 @@ module OpenapiFirst
|
|
18
18
|
"from #{request.request_method.upcase} #{request.path}."
|
19
19
|
end
|
20
20
|
|
21
|
-
api.validate_request(request, raise_error:
|
22
|
-
|
21
|
+
validated = api.validate_request(request, raise_error: false)
|
22
|
+
# :nocov:
|
23
|
+
raise validated.error.exception if validated.invalid?
|
24
|
+
|
25
|
+
validated = api.validate_response(request, response, raise_error: false)
|
26
|
+
raise validated.error.exception if validated.invalid?
|
27
|
+
# :nocov:
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi_first
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Haller
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: hana
|
@@ -93,7 +93,6 @@ files:
|
|
93
93
|
- LICENSE.txt
|
94
94
|
- README.md
|
95
95
|
- lib/openapi_first.rb
|
96
|
-
- lib/openapi_first/body_parser.rb
|
97
96
|
- lib/openapi_first/builder.rb
|
98
97
|
- lib/openapi_first/configuration.rb
|
99
98
|
- lib/openapi_first/definition.rb
|
@@ -106,6 +105,7 @@ files:
|
|
106
105
|
- lib/openapi_first/json.rb
|
107
106
|
- lib/openapi_first/middlewares/request_validation.rb
|
108
107
|
- lib/openapi_first/middlewares/response_validation.rb
|
108
|
+
- lib/openapi_first/rack/test.rb
|
109
109
|
- lib/openapi_first/ref_resolver.rb
|
110
110
|
- lib/openapi_first/request.rb
|
111
111
|
- lib/openapi_first/request_body_parsers.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenapiFirst
|
4
|
-
# @!visibility private
|
5
|
-
module BodyParser
|
6
|
-
def self.[](content_type)
|
7
|
-
case content_type
|
8
|
-
when /json/i
|
9
|
-
JsonBodyParser
|
10
|
-
when %r{multipart/form-data}i
|
11
|
-
MultipartBodyParser
|
12
|
-
else
|
13
|
-
DefaultBodyParser
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.read_body(request)
|
18
|
-
body = request.body&.read
|
19
|
-
request.body.rewind if request.body.respond_to?(:rewind)
|
20
|
-
body
|
21
|
-
end
|
22
|
-
|
23
|
-
JsonBodyParser = lambda do |request|
|
24
|
-
body = read_body(request)
|
25
|
-
return if body.nil? || body.empty?
|
26
|
-
|
27
|
-
JSON.parse(body)
|
28
|
-
rescue JSON::ParserError
|
29
|
-
Failure.fail!(:invalid_body, message: 'Failed to parse request body as JSON')
|
30
|
-
end
|
31
|
-
|
32
|
-
MultipartBodyParser = lambda do |request|
|
33
|
-
request.POST.transform_values do |value|
|
34
|
-
value.is_a?(Hash) && value[:tempfile] ? value[:tempfile].read : value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# This returns the post data parsed by rack or the raw body
|
39
|
-
DefaultBodyParser = lambda do |request|
|
40
|
-
return request.POST if request.form_data?
|
41
|
-
|
42
|
-
read_body(request)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|