openapi_first 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/openapi_first/definition.rb +18 -21
- data/lib/openapi_first/response_parser.rb +14 -6
- data/lib/openapi_first/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ceb641d45921bafb376d7fe7ea3a2f42b76c8900a5d8598e6ef018afca0304e
|
4
|
+
data.tar.gz: 123c15a5a4a149e69a40773b0a62543257f3145fbc06c788207e65757ba3c404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
@
|
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
|
-
|
25
|
-
|
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
|
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.
|
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-
|
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.
|
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
|