openapi_first 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/openapi_first/definition.rb +14 -5
- data/lib/openapi_first/runtime_request.rb +6 -4
- data/lib/openapi_first/runtime_response.rb +9 -4
- data/lib/openapi_first/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b4f5fd99c7b1911b3e1aa17d11a7fe0997266e1047ce7f1c0cf2bb560ce8663
|
4
|
+
data.tar.gz: 459eab2ea15a0b6b247ac16ded90443a9ecd15b663cfdf6c22aab721342ad627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c095aae9904ed9209a321700e356cc896791942ce691fd016c266fd34e6220886ab294e2d8b98b893c0d9572084653515ed143ca38824fe7423b2a62b23fc9e0
|
7
|
+
data.tar.gz: 277b96090ff60cc6b06da02762d27265393aec7b66f8a0132642a644232249514c8e8eb76d5c2a92a393c435f5f0973cf1162c6e28ced0da07eff2aac48791b8
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 1.4.2
|
6
|
+
|
7
|
+
- Fix Rack 2 compatibility
|
8
|
+
|
9
|
+
## 1.4.1
|
10
|
+
|
11
|
+
- Fixed: Don't call deprecated methods in middlewares
|
12
|
+
|
5
13
|
## 1.4.0
|
6
14
|
|
7
15
|
### Changed
|
@@ -15,7 +23,7 @@ Some redundant methods to validate or inspect requests/responses will be removed
|
|
15
23
|
|
16
24
|
## 1.3.6
|
17
25
|
|
18
|
-
-
|
26
|
+
- Fix Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
|
19
27
|
|
20
28
|
## 1.3.5
|
21
29
|
|
@@ -24,9 +24,12 @@ module OpenapiFirst
|
|
24
24
|
# @param raise_error [Boolean] Whether to raise an error if validation fails.
|
25
25
|
# @return [RuntimeRequest] The validated request object.
|
26
26
|
def validate_request(rack_request, raise_error: false)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
runtime_request = request(rack_request)
|
28
|
+
validator = RequestValidation::Validator.new(runtime_request.operation)
|
29
|
+
validation_error = validator.validate(runtime_request)
|
30
|
+
validation_error.raise! if validation_error && raise_error
|
31
|
+
runtime_request.error = validation_error
|
32
|
+
runtime_request
|
30
33
|
end
|
31
34
|
|
32
35
|
# Validates the response against the API description.
|
@@ -35,7 +38,12 @@ module OpenapiFirst
|
|
35
38
|
# @param raise_error [Boolean] Whether to raise an error if validation fails.
|
36
39
|
# @return [RuntimeResponse] The validated response object.
|
37
40
|
def validate_response(rack_request, rack_response, raise_error: false)
|
38
|
-
|
41
|
+
runtime_response = response(rack_request, rack_response)
|
42
|
+
validator = ResponseValidation::Validator.new(runtime_response.operation)
|
43
|
+
validation_error = validator.validate(runtime_response)
|
44
|
+
validation_error.raise! if validation_error && raise_error
|
45
|
+
runtime_response.error = validation_error
|
46
|
+
runtime_response
|
39
47
|
end
|
40
48
|
|
41
49
|
# Builds a RuntimeRequest object based on the Rack request.
|
@@ -57,7 +65,8 @@ module OpenapiFirst
|
|
57
65
|
# @param rack_response [Rack::Response] The Rack response object.
|
58
66
|
# @return [RuntimeResponse] The RuntimeResponse object.
|
59
67
|
def response(rack_request, rack_response)
|
60
|
-
request(rack_request)
|
68
|
+
runtime_request = request(rack_request)
|
69
|
+
RuntimeResponse.new(runtime_request.operation, rack_response)
|
61
70
|
end
|
62
71
|
|
63
72
|
# Gets all the operations defined in the API description.
|
@@ -16,7 +16,6 @@ module OpenapiFirst
|
|
16
16
|
@path_item = path_item
|
17
17
|
@operation = operation
|
18
18
|
@original_path_params = path_params
|
19
|
-
@error = nil
|
20
19
|
@validated = false
|
21
20
|
end
|
22
21
|
|
@@ -34,12 +33,12 @@ module OpenapiFirst
|
|
34
33
|
|
35
34
|
# Returns the error object if validation failed.
|
36
35
|
# @return [Failure, nil]
|
37
|
-
|
36
|
+
attr_accessor :error
|
38
37
|
|
39
38
|
# Checks if the request is valid.
|
40
39
|
# @return [Boolean] true if the request is valid, false otherwise.
|
41
40
|
def valid?
|
42
|
-
validate unless
|
41
|
+
validate unless validated?
|
43
42
|
error.nil?
|
44
43
|
end
|
45
44
|
|
@@ -124,7 +123,6 @@ module OpenapiFirst
|
|
124
123
|
def validate
|
125
124
|
warn '[DEPRECATION] `validate` is deprecated. Please use ' \
|
126
125
|
"`OpenapiFirst.load('openapi.yaml').validate_request(rack_request)` instead."
|
127
|
-
@validated = true
|
128
126
|
@error = RequestValidation::Validator.new(operation).validate(self)
|
129
127
|
end
|
130
128
|
|
@@ -159,6 +157,10 @@ module OpenapiFirst
|
|
159
157
|
|
160
158
|
private
|
161
159
|
|
160
|
+
def validated?
|
161
|
+
defined?(@error)
|
162
|
+
end
|
163
|
+
|
162
164
|
attr_reader :request
|
163
165
|
end
|
164
166
|
end
|
@@ -12,11 +12,13 @@ module OpenapiFirst
|
|
12
12
|
def initialize(operation, rack_response)
|
13
13
|
@operation = operation
|
14
14
|
@rack_response = rack_response
|
15
|
-
@error = nil
|
16
15
|
end
|
17
16
|
|
18
17
|
# @return [Failure, nil] Error object if validation failed.
|
19
|
-
|
18
|
+
attr_accessor :error
|
19
|
+
|
20
|
+
# @visibility private
|
21
|
+
attr_accessor :operation
|
20
22
|
|
21
23
|
# @attr_reader [Integer] status The HTTP status code of this response.
|
22
24
|
# @attr_reader [String] content_type The content_type of the Rack::Response.
|
@@ -30,7 +32,7 @@ module OpenapiFirst
|
|
30
32
|
# Checks if the response is valid. Runs the validation unless it has been run before.
|
31
33
|
# @return [Boolean]
|
32
34
|
def valid?
|
33
|
-
validate unless
|
35
|
+
validate unless validated?
|
34
36
|
@error.nil?
|
35
37
|
end
|
36
38
|
|
@@ -71,7 +73,6 @@ module OpenapiFirst
|
|
71
73
|
def validate
|
72
74
|
warn '[DEPRECATION] `validate` is deprecated. ' \
|
73
75
|
"Please use `OpenapiFirst.load('openapi.yaml').validate_response(rack_request, rack_response)` instead."
|
74
|
-
@validated = true
|
75
76
|
@error = ResponseValidation::Validator.new(@operation).validate(self)
|
76
77
|
end
|
77
78
|
|
@@ -90,6 +91,10 @@ module OpenapiFirst
|
|
90
91
|
|
91
92
|
private
|
92
93
|
|
94
|
+
def validated?
|
95
|
+
defined?(@error)
|
96
|
+
end
|
97
|
+
|
93
98
|
# Usually the body responds to #each, but when using manual response validation without the middleware
|
94
99
|
# in Rails request specs the body is a String. So this code handles both cases.
|
95
100
|
def original_body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi_first
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Haller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hana
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.3.
|
61
|
+
version: 0.3.3
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '2.0'
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 0.3.
|
71
|
+
version: 0.3.3
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '2.0'
|