openapi_first 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c1cc903f3a064f2f386503959e1b437729ab8a668ffbf0dd5aac19c38b4faf4
4
- data.tar.gz: 0ee337872917f9009c9e9b9d57da4382e7b34248cf7df51a2926b3c589bc2f46
3
+ metadata.gz: 6ceb641d45921bafb376d7fe7ea3a2f42b76c8900a5d8598e6ef018afca0304e
4
+ data.tar.gz: 123c15a5a4a149e69a40773b0a62543257f3145fbc06c788207e65757ba3c404
5
5
  SHA512:
6
- metadata.gz: 30636bed981564cfe21696a46eb92d51ccb7680531b754dbfa37a6f52e37420f4e9611437e93ee54aada8eb6062db92ffd7fbce32eb1c76e8d856c5777b64444
7
- data.tar.gz: 769c0821eca57bf60d8554ffd231b042511f57627f55c6083f2a9d054b35d08f0451d20f2411eaae035d7b3a591a046c57d732bf086143ac3d16162bf25b7c69
6
+ metadata.gz: 3e279fa5f4239b1f41020b788370377535ef5cf959d2f2a23df61240310d4b729484e0a1154ff11250e21164c15b1ab285b3173fc2f2e3ac84603a5722e60ec7
7
+ data.tar.gz: f96790f87324ea1ce7f78b6d3b41f86de709f990edf26a97ce1ad01b7929229198f9114ceb33d1aad94912211253ddc26dce6acae5566b386c805bb1219d886d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.1.1
6
+
7
+ - Fix issue with non file downloads / JSON responses https://github.com/ahx/openapi_first/issues/281
8
+
5
9
  ## 2.1.0
6
10
 
7
11
  - Added `OpenapiFirst::Definition#[]` to access the raw Hash representation of the OAS document. Example: `api['components'].fetch('schemas', 'Stations')`
@@ -40,10 +40,9 @@ module OpenapiFirst
40
40
  def_delegators :@resolved, :[]
41
41
 
42
42
  # Returns an Enumerable of available Routes for this API description.
43
+ # @!method routes
43
44
  # @return [Enumerable[Router::Route]]
44
- def routes
45
- @router.routes
46
- end
45
+ def_delegators :@router, :routes
47
46
 
48
47
  # Validates the request against the API description.
49
48
  # @param [Rack::Request] request The Rack request object.
@@ -51,15 +50,14 @@ module OpenapiFirst
51
50
  # @return [ValidatedRequest] The validated request object.
52
51
  def validate_request(request, raise_error: false)
53
52
  route = @router.match(request.request_method, request.path, content_type: request.content_type)
54
- validated = if route.error
55
- ValidatedRequest.new(request, error: route.error)
56
- else
57
- route.request_definition.validate(request, route_params: route.params)
58
- end
59
- @config.hooks[:after_request_validation].each { |hook| hook.call(validated, self) }
60
- raise validated.error.exception(validated) if validated.error && raise_error
61
-
62
- validated
53
+ if route.error
54
+ ValidatedRequest.new(request, error: route.error)
55
+ else
56
+ route.request_definition.validate(request, route_params: route.params)
57
+ end.tap do |validated|
58
+ @config.hooks[:after_request_validation].each { |hook| hook.call(validated, self) }
59
+ raise validated.error.exception(validated) if validated.error && raise_error
60
+ end
63
61
  end
64
62
 
65
63
  # Validates the response against the API description.
@@ -73,15 +71,14 @@ module OpenapiFirst
73
71
 
74
72
  response_match = route.match_response(status: rack_response.status, content_type: rack_response.content_type)
75
73
  error = response_match.error
76
- validated = if error
77
- ValidatedResponse.new(rack_response, error:)
78
- else
79
- response_match.response.validate(rack_response)
80
- end
81
- @config.hooks[:after_response_validation]&.each { |hook| hook.call(validated, rack_request, self) }
82
- raise validated.error.exception(validated) if raise_error && validated.invalid?
83
-
84
- validated
74
+ if error
75
+ ValidatedResponse.new(rack_response, error:)
76
+ else
77
+ response_match.response.validate(rack_response)
78
+ end.tap do |validated|
79
+ @config.hooks[:after_response_validation]&.each { |hook| hook.call(validated, rack_request, self) }
80
+ raise validated.error.exception(validated) if raise_error && validated.invalid?
81
+ end
85
82
  end
86
83
  end
87
84
  end
@@ -7,22 +7,30 @@ module OpenapiFirst
7
7
  class ResponseParser
8
8
  def initialize(headers:, content_type:)
9
9
  @headers = headers
10
- @content_type = content_type
10
+ @json = /json/i.match?(content_type)
11
11
  end
12
12
 
13
- attr_reader :headers, :content_type
14
-
15
13
  def parse(rack_response)
16
14
  ParsedResponse.new(
17
- body: parse_body(rack_response),
15
+ body: parse_body(read_body(rack_response)),
18
16
  headers: parse_headers(rack_response)
19
17
  )
20
18
  end
21
19
 
22
20
  private
23
21
 
24
- def parse_body(rack_response)
25
- MultiJson.load(read_body(rack_response)) if /json/i.match?(content_type)
22
+ attr_reader :headers
23
+
24
+ def json? = @json
25
+
26
+ def parse_body(body)
27
+ return parse_json(body) if json?
28
+
29
+ body
30
+ end
31
+
32
+ def parse_json(body)
33
+ MultiJson.load(body)
26
34
  rescue MultiJson::ParseError
27
35
  Failure.fail!(:invalid_response_body, message: 'Response body is invalid: Failed to parse response body as JSON')
28
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.1.0'
4
+ VERSION = '2.1.1'
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: 2.1.0
4
+ version: 2.1.1
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-07-18 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hana
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.5.11
170
+ rubygems_version: 3.5.19
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Implement HTTP APIs based on OpenApi 3.x