openapi_first 1.3.5 → 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: 631b8fea22128020990af7edb3605d0e842d04b0f876affb4277b3f81b571921
4
- data.tar.gz: 3fc61f1ca41bb0d380c188681bad5477c36c6cbeeeec5fabf1700d468987aae5
3
+ metadata.gz: 1a462473bc1c585914983760dc3023fda2a375276f2703712ec1f8e7d8ef4950
4
+ data.tar.gz: 46c6cb68fc175a55525595ed90a4cf599af36d117a80dff8078fecf24aca79d7
5
5
  SHA512:
6
- metadata.gz: e2b1210a029a62742928ebf2e285a58d9d48d2a809373cce1652a13f8b538675b37be361c99625d6e0bb6cf70ea58ebbaba7486f8ac73896cf5989b74257cd06
7
- data.tar.gz: 0e5d4798b159fd71af8da50703644f71a16cc276bfdafcaff3cf64777042d6ed9b78ac62ba1dfe07cbd1026cf8d359b77124a5abe39d239030c5d5f5b967b12c
6
+ metadata.gz: c51b30bf959533eeee109cea59fdce2c1f0057e1c40eec6a961b0360000665e940ff1366125db655b1d2026f7bf8767ba62cd8358b6a31b9ac7128f4f129c497
7
+ data.tar.gz: d639e00db05a01a1e2f8bdb57c1e95c72ee71c5bcc317d53b1130a915124075d0b8e922cb0c3340ba02b709a1c7e06142024f64d1de264abaa631caf7522b563
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
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
+
16
+ ## 1.3.6
17
+
18
+ - FIx Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
19
+
5
20
  ## 1.3.5
6
21
 
7
22
  - Added support for `/some/{kebab-cased}` path parameters ([#245](https://github.com/ahx/openapi_first/issues/245))
@@ -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,17 +22,21 @@ 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
- body = body.to_ary if body.respond_to?(:to_ary)
28
- request.validate_response(Rack::Response[status, headers, body], raise_error: true)
26
+ body = read_body(body)
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
 
32
32
  private
33
33
 
34
- def find_request(env)
35
- env[REQUEST] ||= @definition.request(Rack::Request.new(env))
34
+ def read_body(body)
35
+ return body.to_ary if body.respond_to?(:to_ary)
36
+
37
+ result = []
38
+ body.each { |part| result << part }
39
+ result
36
40
  end
37
41
  end
38
42
  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.5'
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.5
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-19 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