swagalicious 0.5.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -1
- data/lib/swagalicious/example_helpers.rb +93 -3
- data/lib/swagalicious/version.rb +1 -1
- data/swagalicious.gemspec +3 -0
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abb72dfd425ef772e7d2c0cf1ac1079d60cf9d6310b790dc9eef4454e145d7dd
|
4
|
+
data.tar.gz: 3c919667c104eba4d2e01d4177e68e4bcc5d57a8a0d33ee02b9fcfa79d3cf899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12939af351eaebed0316bff2af98b58fcf7f39041311920bab9338f163e5dc06d2575148fedcb22ab92581f91b9f9d8e28dbffb0bef60cc97faccc2a97bf9718
|
7
|
+
data.tar.gz: 8003706edc0671b7cce79a72d9098827de9d114b0d42502684ea980bf4ee22deab1a998603710a82a55321fa0c318b42414d7f047ae5a2028214ae2a8354a647
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swagalicious (0.
|
4
|
+
swagalicious (1.0.0)
|
5
5
|
faraday (~> 2.0)
|
6
6
|
faraday-rack
|
7
7
|
json-schema
|
8
8
|
oj (~> 3.11.0)
|
9
|
+
ox (~> 2.14.14)
|
9
10
|
rack-test (~> 2.0.2)
|
10
11
|
rspec (~> 3)
|
11
12
|
|
@@ -20,6 +21,7 @@ GEM
|
|
20
21
|
zeitwerk (~> 2.3)
|
21
22
|
addressable (2.8.1)
|
22
23
|
public_suffix (>= 2.0.2, < 6.0)
|
24
|
+
ast (2.4.2)
|
23
25
|
byebug (11.1.3)
|
24
26
|
coderay (1.1.3)
|
25
27
|
concurrent-ruby (1.1.10)
|
@@ -34,11 +36,16 @@ GEM
|
|
34
36
|
faraday (~> 2.0)
|
35
37
|
i18n (1.10.0)
|
36
38
|
concurrent-ruby (~> 1.0)
|
39
|
+
json (2.6.3)
|
37
40
|
json-schema (3.0.0)
|
38
41
|
addressable (>= 2.8)
|
39
42
|
method_source (1.0.0)
|
40
43
|
minitest (5.16.1)
|
41
44
|
oj (3.11.8)
|
45
|
+
ox (2.14.14)
|
46
|
+
parallel (1.22.1)
|
47
|
+
parser (3.2.1.0)
|
48
|
+
ast (~> 2.4.1)
|
42
49
|
pry (0.13.1)
|
43
50
|
coderay (~> 1.1)
|
44
51
|
method_source (~> 1.0)
|
@@ -49,7 +56,10 @@ GEM
|
|
49
56
|
rack (3.0.4.1)
|
50
57
|
rack-test (2.0.2)
|
51
58
|
rack (>= 1.3)
|
59
|
+
rainbow (3.1.1)
|
52
60
|
rake (12.3.3)
|
61
|
+
regexp_parser (2.7.0)
|
62
|
+
rexml (3.2.5)
|
53
63
|
rspec (3.11.0)
|
54
64
|
rspec-core (~> 3.11.0)
|
55
65
|
rspec-expectations (~> 3.11.0)
|
@@ -63,9 +73,28 @@ GEM
|
|
63
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
74
|
rspec-support (~> 3.11.0)
|
65
75
|
rspec-support (3.11.0)
|
76
|
+
rubocop (1.48.0)
|
77
|
+
json (~> 2.3)
|
78
|
+
parallel (~> 1.10)
|
79
|
+
parser (>= 3.2.0.0)
|
80
|
+
rainbow (>= 2.2.2, < 4.0)
|
81
|
+
regexp_parser (>= 1.8, < 3.0)
|
82
|
+
rexml (>= 3.2.5, < 4.0)
|
83
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
84
|
+
ruby-progressbar (~> 1.7)
|
85
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
86
|
+
rubocop-ast (1.27.0)
|
87
|
+
parser (>= 3.2.1.0)
|
88
|
+
rubocop-capybara (2.17.1)
|
89
|
+
rubocop (~> 1.41)
|
90
|
+
rubocop-rspec (2.19.0)
|
91
|
+
rubocop (~> 1.33)
|
92
|
+
rubocop-capybara (~> 2.17)
|
93
|
+
ruby-progressbar (1.13.0)
|
66
94
|
ruby2_keywords (0.0.5)
|
67
95
|
tzinfo (2.0.4)
|
68
96
|
concurrent-ruby (~> 1.0)
|
97
|
+
unicode-display_width (2.4.2)
|
69
98
|
zeitwerk (2.6.0)
|
70
99
|
|
71
100
|
PLATFORMS
|
@@ -76,6 +105,8 @@ DEPENDENCIES
|
|
76
105
|
pry-byebug (~> 3.9.0)
|
77
106
|
rake (~> 12.0)
|
78
107
|
rspec (~> 3.0)
|
108
|
+
rubocop (~> 1.48.0)
|
109
|
+
rubocop-rspec (~> 2.19.0)
|
79
110
|
swagalicious!
|
80
111
|
|
81
112
|
BUNDLED WITH
|
@@ -1,7 +1,11 @@
|
|
1
1
|
require "faraday"
|
2
2
|
require "faraday/rack"
|
3
3
|
require "rack"
|
4
|
+
require "json"
|
4
5
|
require "oj"
|
6
|
+
require "ox"
|
7
|
+
require "yaml"
|
8
|
+
require "active_support/core_ext/hash/indifferent_access"
|
5
9
|
|
6
10
|
require_relative "response_validator"
|
7
11
|
|
@@ -9,6 +13,55 @@ class Swagalicious
|
|
9
13
|
module ExampleHelpers
|
10
14
|
include Rack::Test::Methods
|
11
15
|
|
16
|
+
def self.raise_invalid_response(response:, request:, message:)
|
17
|
+
raise InvalidResponseTypeError.new(
|
18
|
+
headers: response.headers,
|
19
|
+
message: message,
|
20
|
+
request: request,
|
21
|
+
response: response,
|
22
|
+
status: response.status,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
class InvalidResponseTypeError < RuntimeError
|
27
|
+
attr_reader :status, :_message, :headers, :response, :request
|
28
|
+
|
29
|
+
def initialize(status:, message:, headers:, response:, request:)
|
30
|
+
@headers = headers
|
31
|
+
@_message = message
|
32
|
+
@request = request
|
33
|
+
@response = response
|
34
|
+
@status = status
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
JSON.pretty_generate(to_h)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_h
|
42
|
+
hash = {
|
43
|
+
headers: headers.to_h,
|
44
|
+
message: _message,
|
45
|
+
request: request.slice(:verb, :path, :headers),
|
46
|
+
status: status,
|
47
|
+
}
|
48
|
+
|
49
|
+
if parsed_body = Parser.new(request: request, response: response).parse(raise_on_invalid: false)
|
50
|
+
hash[:parsed_response] = parsed_body
|
51
|
+
end
|
52
|
+
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
"Received unexpected or unparseable response with status code #{status} for #{request[:verb].upcase} #{request[:path]}: #{_message}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def message
|
61
|
+
inspect
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
12
65
|
class MockResponse
|
13
66
|
attr_reader :body, :status, :headers
|
14
67
|
|
@@ -19,6 +72,44 @@ class Swagalicious
|
|
19
72
|
end
|
20
73
|
end
|
21
74
|
|
75
|
+
class Parser
|
76
|
+
attr_accessor :body
|
77
|
+
attr_reader :content_type, :request, :response
|
78
|
+
|
79
|
+
def initialize(response:, request:)
|
80
|
+
@content_type = response.headers["Content-Type"]
|
81
|
+
@body = response.body
|
82
|
+
@response = response
|
83
|
+
@request = request
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse(raise_on_invalid: true)
|
87
|
+
# Redirections shouldnt be parsed
|
88
|
+
if response.status >= 300 && response.status <= 399
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
92
|
+
case content_type
|
93
|
+
when /json/
|
94
|
+
self.body = "{}" if self.body.empty?
|
95
|
+
|
96
|
+
Oj.load(self.body, symbol_keys: true)
|
97
|
+
when /ya?ml/
|
98
|
+
body = "---" if self.body.empty?
|
99
|
+
|
100
|
+
(YAML.load(self.body) || {}).with_indifferent_access
|
101
|
+
when /xml/
|
102
|
+
(Ox.load(self.body, mode: :hash_no_attrs) || {}).with_indifferent_access
|
103
|
+
when "", nil
|
104
|
+
self.body
|
105
|
+
else
|
106
|
+
return unless raise_on_invalid
|
107
|
+
|
108
|
+
Swagalicious::ExampleHelpers.raise_invalid_response(response: response, request: request, message: "Invalid Content-Type header #{response.headers["Content-Type"]}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
22
113
|
def app
|
23
114
|
@app ||= if defined?(Rails)
|
24
115
|
Rails.application
|
@@ -52,10 +143,9 @@ class Swagalicious
|
|
52
143
|
end
|
53
144
|
end
|
54
145
|
|
55
|
-
|
56
|
-
body = "{}" if body.empty?
|
146
|
+
Swagalicious::ExampleHelpers.raise_invalid_response(response: response, request: request, message: "Received unexpected response code") unless response.status.to_s == metadata[:response][:code].to_s
|
57
147
|
|
58
|
-
@body =
|
148
|
+
@body = Parser.new(request: request, response: response).parse
|
59
149
|
|
60
150
|
metadata[:paths] ||= []
|
61
151
|
metadata[:paths] << request[:path]
|
data/lib/swagalicious/version.rb
CHANGED
data/swagalicious.gemspec
CHANGED
@@ -28,9 +28,12 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency "faraday-rack"
|
29
29
|
spec.add_dependency "json-schema"
|
30
30
|
spec.add_dependency "oj", "~> 3.11.0"
|
31
|
+
spec.add_dependency "ox", "~> 2.14.14"
|
31
32
|
spec.add_dependency "rack-test", "~> 2.0.2"
|
32
33
|
spec.add_dependency "rspec", "~> 3"
|
33
34
|
|
35
|
+
spec.add_development_dependency "rubocop", "~> 1.48.0"
|
36
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.19.0"
|
34
37
|
spec.add_development_dependency "factory_bot", "~> 6.1.0"
|
35
38
|
spec.add_development_dependency "pry-byebug", "~> 3.9.0"
|
36
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagalicious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Howe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.11.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ox
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.14.14
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.14.14
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rack-test
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,34 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.48.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.48.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.19.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.19.0
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: factory_bot
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|