swagalicious 0.2.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +49 -18
- data/lib/swagalicious.rb +8 -8
- data/lib/swagalicious/example_helpers.rb +12 -2
- data/lib/swagalicious/response_validator.rb +1 -1
- data/lib/swagalicious/swagger_formatter.rb +19 -2
- data/lib/swagalicious/version.rb +1 -1
- data/swagalicious.gemspec +7 -4
- metadata +43 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc2174d33212b6196c1cfa15e022cd1e3c9d6f2633b6f6ad6c56cc4506895b82
|
4
|
+
data.tar.gz: 3a67216c81d671a023969138a24fdf5f0a3dfc20ec468a07abf1ce4b4dbb3892
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51bc671599f979b41ef407a3b4d2936a3ec133efe6df7c2b6a51b1ad92a5c98850d5226908ed66cbac0ef183bbddbc542e1505f1777ed02c9153b4d7a90324fe
|
7
|
+
data.tar.gz: d3db035d1bc8e6d37fd934be9ed7cbd93809c469a761fa1133080b2ad4faf7be3016655f8f88453c5bbd7e34989bd29003901e5ee8aa5b09f8928e24ac194d5a
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,81 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swagalicious (0.
|
5
|
-
faraday (~> 1.0
|
4
|
+
swagalicious (0.4.2)
|
5
|
+
faraday (~> 1.3.0)
|
6
6
|
json-schema (~> 2.8.1)
|
7
|
-
oj (~> 3.
|
8
|
-
|
7
|
+
oj (~> 3.11.0)
|
8
|
+
rspec (~> 3.10.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
+
activesupport (6.1.1)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
zeitwerk (~> 2.3)
|
13
19
|
addressable (2.7.0)
|
14
20
|
public_suffix (>= 2.0.2, < 5.0)
|
21
|
+
byebug (11.1.3)
|
22
|
+
coderay (1.1.3)
|
23
|
+
concurrent-ruby (1.1.8)
|
15
24
|
diff-lcs (1.4.4)
|
16
|
-
|
25
|
+
factory_bot (6.1.0)
|
26
|
+
activesupport (>= 5.0.0)
|
27
|
+
faraday (1.3.0)
|
28
|
+
faraday-net_http (~> 1.0)
|
17
29
|
multipart-post (>= 1.2, < 3)
|
30
|
+
ruby2_keywords
|
31
|
+
faraday-net_http (1.0.1)
|
32
|
+
i18n (1.8.7)
|
33
|
+
concurrent-ruby (~> 1.0)
|
18
34
|
json-schema (2.8.1)
|
19
35
|
addressable (>= 2.4)
|
36
|
+
method_source (1.0.0)
|
37
|
+
minitest (5.14.3)
|
20
38
|
multipart-post (2.1.1)
|
21
|
-
oj (3.
|
39
|
+
oj (3.11.0)
|
40
|
+
pry (0.13.1)
|
41
|
+
coderay (~> 1.1)
|
42
|
+
method_source (~> 1.0)
|
43
|
+
pry-byebug (3.9.0)
|
44
|
+
byebug (~> 11.0)
|
45
|
+
pry (~> 0.13.0)
|
22
46
|
public_suffix (4.0.6)
|
23
47
|
rack (2.2.3)
|
24
48
|
rack-test (1.1.0)
|
25
49
|
rack (>= 1.0, < 3)
|
26
50
|
rake (12.3.3)
|
27
|
-
rspec (3.
|
28
|
-
rspec-core (~> 3.
|
29
|
-
rspec-expectations (~> 3.
|
30
|
-
rspec-mocks (~> 3.
|
31
|
-
rspec-core (3.
|
32
|
-
rspec-support (~> 3.
|
33
|
-
rspec-expectations (3.
|
51
|
+
rspec (3.10.0)
|
52
|
+
rspec-core (~> 3.10.0)
|
53
|
+
rspec-expectations (~> 3.10.0)
|
54
|
+
rspec-mocks (~> 3.10.0)
|
55
|
+
rspec-core (3.10.1)
|
56
|
+
rspec-support (~> 3.10.0)
|
57
|
+
rspec-expectations (3.10.1)
|
34
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.
|
36
|
-
rspec-mocks (3.
|
59
|
+
rspec-support (~> 3.10.0)
|
60
|
+
rspec-mocks (3.10.1)
|
37
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-support (3.
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-support (3.10.1)
|
64
|
+
ruby2_keywords (0.0.4)
|
65
|
+
tzinfo (2.0.4)
|
66
|
+
concurrent-ruby (~> 1.0)
|
67
|
+
zeitwerk (2.4.2)
|
40
68
|
|
41
69
|
PLATFORMS
|
42
70
|
ruby
|
43
71
|
|
44
72
|
DEPENDENCIES
|
73
|
+
factory_bot (~> 6.1.0)
|
74
|
+
pry-byebug (~> 3.9.0)
|
75
|
+
rack-test (~> 1.1.0)
|
45
76
|
rake (~> 12.0)
|
46
77
|
rspec (~> 3.0)
|
47
78
|
swagalicious!
|
48
79
|
|
49
80
|
BUNDLED WITH
|
50
|
-
2.
|
81
|
+
2.2.6
|
data/lib/swagalicious.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rspec/core"
|
2
2
|
|
3
|
-
require_relative "swagalicious/version"
|
3
|
+
require_relative "./swagalicious/version"
|
4
4
|
|
5
5
|
class Swagalicious
|
6
6
|
class Error < StandardError; end
|
@@ -9,13 +9,13 @@ class Swagalicious
|
|
9
9
|
@config ||= Swagalicious::Configuration.new(RSpec.configuration)
|
10
10
|
end
|
11
11
|
|
12
|
-
require_relative "swagalicious/configuration"
|
13
|
-
require_relative "swagalicious/example_group_helpers"
|
14
|
-
require_relative "swagalicious/example_helpers"
|
15
|
-
require_relative "swagalicious/extended_schema"
|
16
|
-
require_relative "swagalicious/request_factory"
|
17
|
-
require_relative "swagalicious/response_validator"
|
18
|
-
require_relative "swagalicious/swagger_formatter"
|
12
|
+
require_relative "./swagalicious/configuration"
|
13
|
+
require_relative "./swagalicious/example_group_helpers"
|
14
|
+
require_relative "./swagalicious/example_helpers"
|
15
|
+
require_relative "./swagalicious/extended_schema"
|
16
|
+
require_relative "./swagalicious/request_factory"
|
17
|
+
require_relative "./swagalicious/response_validator"
|
18
|
+
require_relative "./swagalicious/swagger_formatter"
|
19
19
|
|
20
20
|
::RSpec::Core::ExampleGroup.define_example_group_method :path
|
21
21
|
|
@@ -49,12 +49,22 @@ class Swagalicious
|
|
49
49
|
|
50
50
|
@body = Oj.load(body, symbol_keys: true)
|
51
51
|
|
52
|
+
metadata[:paths] ||= []
|
53
|
+
metadata[:paths] << request[:path]
|
54
|
+
|
52
55
|
if request[:payload]
|
53
56
|
metadata[:response][:request] = Oj.load(request[:payload])
|
54
57
|
end
|
55
58
|
|
56
|
-
metadata[:response][:examples]
|
57
|
-
|
59
|
+
metadata[:response][:examples] ||= {}
|
60
|
+
|
61
|
+
mime_types = metadata[:response][:produces] || ["application/json"]
|
62
|
+
full_title = metadata[:swagger_example_name] || "#{metadata[:operation][:summary]}: #{metadata[:description]}"
|
63
|
+
|
64
|
+
mime_types.each do |mime_type|
|
65
|
+
metadata[:response][:examples][mime_type] ||= {}
|
66
|
+
metadata[:response][:examples][mime_type][full_title] = @body
|
67
|
+
end
|
58
68
|
|
59
69
|
# Validates response matches the proper schema
|
60
70
|
Swagalicious::ResponseValidator.new.validate!(metadata, response)
|
@@ -44,7 +44,7 @@ class Swagalicious
|
|
44
44
|
.merge(schemas)
|
45
45
|
|
46
46
|
errors = JSON::Validator.fully_validate(validation_schema, body)
|
47
|
-
raise UnexpectedResponse, "Expected response body to match schema: #{errors
|
47
|
+
raise UnexpectedResponse, "Expected response body to match schema: #{errors.join(", ")}" unless errors.empty?
|
48
48
|
end
|
49
49
|
|
50
50
|
def definitions_or_component_schemas(swagger_doc, version)
|
@@ -92,6 +92,19 @@ class Swagalicious
|
|
92
92
|
def metadata_to_swagger(metadata)
|
93
93
|
response_code = metadata[:response][:code]
|
94
94
|
response = metadata[:response].reject { |k, _v| k == :code }
|
95
|
+
examples = response.delete(:examples) || []
|
96
|
+
|
97
|
+
examples.each do |mime_type, titles|
|
98
|
+
titles.each do |title, example|
|
99
|
+
next unless response[:content][mime_type]
|
100
|
+
|
101
|
+
response[:content][mime_type][:examples] ||= {}
|
102
|
+
|
103
|
+
response[:content][mime_type][:examples][title] ||= {}
|
104
|
+
|
105
|
+
response[:content][mime_type][:examples][title][:value] = example
|
106
|
+
end
|
107
|
+
end
|
95
108
|
|
96
109
|
verb = metadata[:operation][:verb]
|
97
110
|
operation = metadata[:operation]
|
@@ -112,7 +125,7 @@ class Swagalicious
|
|
112
125
|
|
113
126
|
def upgrade_response_produces!(swagger_doc, metadata)
|
114
127
|
# Accept header
|
115
|
-
mime_list = Array(metadata[:operation]
|
128
|
+
mime_list = Array(metadata[:operation].delete(:produces) || swagger_doc[:produces])
|
116
129
|
target_node = metadata[:response]
|
117
130
|
upgrade_content!(mime_list, target_node)
|
118
131
|
metadata[:response].delete(:schema)
|
@@ -125,7 +138,11 @@ class Swagalicious
|
|
125
138
|
|
126
139
|
mime_list.each do |mime_type|
|
127
140
|
# TODO upgrade to have content-type specific schema
|
128
|
-
|
141
|
+
body = target_node
|
142
|
+
.fetch(:body, {})
|
143
|
+
.fetch(mime_type, {})
|
144
|
+
|
145
|
+
target_node[:content][mime_type] = { schema: schema }.merge(body)
|
129
146
|
end
|
130
147
|
end
|
131
148
|
|
data/lib/swagalicious/version.rb
CHANGED
data/swagalicious.gemspec
CHANGED
@@ -24,9 +24,12 @@ Gem::Specification.new do |spec|
|
|
24
24
|
end
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency "faraday", "~> 1.0
|
27
|
+
spec.add_dependency "faraday", "~> 1.3.0"
|
28
28
|
spec.add_dependency "json-schema", "~> 2.8.1"
|
29
|
-
spec.add_dependency "oj", "~> 3.
|
30
|
-
spec.add_dependency "
|
31
|
-
|
29
|
+
spec.add_dependency "oj", "~> 3.11.0"
|
30
|
+
spec.add_dependency "rspec", "~> 3.10.0"
|
31
|
+
|
32
|
+
spec.add_development_dependency "factory_bot", "~> 6.1.0"
|
33
|
+
spec.add_development_dependency "pry-byebug", "~> 3.9.0"
|
34
|
+
spec.add_development_dependency "rack-test", "~> 1.1.0"
|
32
35
|
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.2
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Howe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
19
|
+
version: 1.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0
|
26
|
+
version: 1.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json-schema
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,42 +44,70 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.11.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.11.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.10.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.10.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: factory_bot
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 6.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 6.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: 3.9.0
|
76
|
-
type: :
|
90
|
+
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: 3.9.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.0
|
83
111
|
description: This gem is almost a straight copy and paste of https://github.com/rswag/rswag/tree/master/rswag-specs
|
84
112
|
with the Rails specific code stripped out so it can be used in Rack applications
|
85
113
|
that don't use Rails.
|
@@ -118,7 +146,7 @@ metadata:
|
|
118
146
|
allowed_push_host: https://rubygems.org
|
119
147
|
homepage_uri: https://github.com/ehowe/swagalicious
|
120
148
|
source_code_uri: https://github.com/ehowe/swagalicious
|
121
|
-
post_install_message:
|
149
|
+
post_install_message:
|
122
150
|
rdoc_options: []
|
123
151
|
require_paths:
|
124
152
|
- lib
|
@@ -133,8 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
161
|
- !ruby/object:Gem::Version
|
134
162
|
version: '0'
|
135
163
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
137
|
-
signing_key:
|
164
|
+
rubygems_version: 3.0.8
|
165
|
+
signing_key:
|
138
166
|
specification_version: 4
|
139
167
|
summary: RSwag without Rails
|
140
168
|
test_files: []
|