openapi_first 1.3.6 → 1.4.0

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: 221362a78a788c449a8c11af9c40fc91bf307c82ee79d0931c94f39bb22901bc
4
- data.tar.gz: d9b806ed56371199552b4081d2b6b220279b925b9fdbdaa90ce47623c86e4bff
3
+ metadata.gz: 1a462473bc1c585914983760dc3023fda2a375276f2703712ec1f8e7d8ef4950
4
+ data.tar.gz: 46c6cb68fc175a55525595ed90a4cf599af36d117a80dff8078fecf24aca79d7
5
5
  SHA512:
6
- metadata.gz: 5c5ceac8c85f7d074983e5d237febe8ecf9ec3414a5ecb1a5bd8af43259eb2c83621ac867ca9b1d5420a3dda7518e131ed2ac1f08b86d71fa6fdfccbf76e1885
7
- data.tar.gz: 92c44316bf96d31841a959898efcd20e08bc223f233e26af253cc3575dbf29680b13e27ab628eb9bb9544371c08c0d7aea42b5aaf8bef75d369299067e6eb0ca
6
+ metadata.gz: c51b30bf959533eeee109cea59fdce2c1f0057e1c40eec6a961b0360000665e940ff1366125db655b1d2026f7bf8767ba62cd8358b6a31b9ac7128f4f129c497
7
+ data.tar.gz: d639e00db05a01a1e2f8bdb57c1e95c72ee71c5bcc317d53b1130a915124075d0b8e922cb0c3340ba02b709a1c7e06142024f64d1de264abaa631caf7522b563
data/CHANGELOG.md CHANGED
@@ -2,9 +2,20 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.4.0
6
+
7
+ ### Changed
8
+
9
+ Some redundant methods to validate or inspect requests/responses will be removed in 2.0. So this release deprecates these methods.
10
+
11
+ - Deprecate `OpenapiFirst::RuntimeRequest#validate`, `#validate!`, `#validate_response`, `#response`.
12
+ Use `OpenapiFirst.load('openapi.yaml').validate_request(rack_request, raise_error: true/false)` instead
13
+ - Deprecate `OpenapiFirst::RuntimeResponse#validate`.
14
+ Use `OpenapiFirst.load('openapi.yaml').validate_response(rack_request, rack_response, raise_error: true/false)` instead.
15
+
5
16
  ## 1.3.6
6
17
 
7
- - Fix Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
18
+ - FIx Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
8
19
 
9
20
  ## 1.3.5
10
21
 
@@ -26,11 +26,9 @@ module OpenapiFirst
26
26
  attr_reader :app
27
27
 
28
28
  def call(env)
29
- request = find_request(env)
30
- return @app.call(env) unless request
31
-
32
- failure = request.validate
33
- failure.raise! if failure && @raise
29
+ validated = @definition.validate_request(Rack::Request.new(env), raise_error: @raise)
30
+ env[REQUEST] ||= validated
31
+ failure = validated.error
34
32
  return @error_response_class.new(failure:).render if failure
35
33
 
36
34
  @app.call(env)
@@ -38,10 +36,6 @@ module OpenapiFirst
38
36
 
39
37
  private
40
38
 
41
- def find_request(env)
42
- env[REQUEST] ||= @definition.request(Rack::Request.new(env))
43
- end
44
-
45
39
  def error_response(mod)
46
40
  return OpenapiFirst.find_plugin(mod)::ErrorResponse if mod.is_a?(Symbol)
47
41
 
@@ -22,10 +22,10 @@ module OpenapiFirst
22
22
  attr_reader :app
23
23
 
24
24
  def call(env)
25
- request = find_request(env)
26
25
  status, headers, body = @app.call(env)
27
26
  body = read_body(body)
28
- request.validate_response(Rack::Response[status, headers, body], raise_error: true)
27
+ @definition.validate_response(Rack::Request.new(env), Rack::Response[status, headers, body], raise_error: true)
28
+ env[REQUEST] ||= @definition.request(Rack::Request.new(env))
29
29
  [status, headers, body]
30
30
  end
31
31
 
@@ -38,10 +38,6 @@ module OpenapiFirst
38
38
  body.each { |part| result << part }
39
39
  result
40
40
  end
41
-
42
- def find_request(env)
43
- env[REQUEST] ||= @definition.request(Rack::Request.new(env))
44
- end
45
41
  end
46
42
  end
47
43
  end
@@ -120,13 +120,18 @@ module OpenapiFirst
120
120
 
121
121
  # Validates the request.
122
122
  # @return [Failure, nil] The Failure object if validation failed.
123
+ # @deprecated Please use {Definition#validate_request} instead
123
124
  def validate
125
+ warn '[DEPRECATION] `validate` is deprecated. Please use ' \
126
+ "`OpenapiFirst.load('openapi.yaml').validate_request(rack_request)` instead."
124
127
  @validated = true
125
128
  @error = RequestValidation::Validator.new(operation).validate(self)
126
129
  end
127
130
 
128
131
  # Validates the request and raises an error if validation fails.
129
132
  def validate!
133
+ warn '[DEPRECATION] `validate!` is deprecated. Please use ' \
134
+ "`OpenapiFirst.load('openapi.yaml').validate_request(rack_request, raise_error: true)` instead."
130
135
  error = validate
131
136
  error&.raise!
132
137
  end
@@ -136,6 +141,8 @@ module OpenapiFirst
136
141
  # @param raise_error [Boolean] Whether to raise an error if validation fails.
137
142
  # @return [RuntimeResponse] The validated response object.
138
143
  def validate_response(rack_response, raise_error: false)
144
+ warn '[DEPRECATION] `validate_response!` is deprecated. Please use ' \
145
+ "`OpenapiFirst.load('openapi.yaml').validate_response(request, response, raise_error: false)` instead."
139
146
  validated = response(rack_response).tap(&:validate)
140
147
  validated.error&.raise! if raise_error
141
148
  validated
@@ -145,6 +152,8 @@ module OpenapiFirst
145
152
  # @param rack_response [Rack::Response] The rack response object.
146
153
  # @return [RuntimeResponse] The RuntimeResponse object.
147
154
  def response(rack_response)
155
+ warn '[DEPRECATION] `response` is deprecated. Please use ' \
156
+ "`OpenapiFirst.load('openapi.yaml').validate_response(request, response, raise_error: false)` instead."
148
157
  RuntimeResponse.new(operation, rack_response)
149
158
  end
150
159
 
@@ -67,7 +67,10 @@ module OpenapiFirst
67
67
 
68
68
  # Validates the response.
69
69
  # @return [Failure, nil] Returns the validation error, or nil if the response is valid.
70
+ # @deprecated Please use {Definition#validate_response} instead
70
71
  def validate
72
+ warn '[DEPRECATION] `validate` is deprecated. ' \
73
+ "Please use `OpenapiFirst.load('openapi.yaml').validate_response(rack_request, rack_response)` instead."
71
74
  @validated = true
72
75
  @error = ResponseValidation::Validator.new(@operation).validate(self)
73
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '1.3.6'
4
+ VERSION = '1.4.0'
5
5
  end
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.3.6
4
+ version: 1.4.0
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-03-22 00:00:00.000000000 Z
11
+ date: 2024-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hana