swagalicious 0.3.1 → 0.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: 660f3ec40bfe890817b3e6bdb147ed5d7499a3bcf5b5f966c2310292fb76f8d7
4
- data.tar.gz: 4028bd843b9f12e82ff4c771a5389bf4504549bf304bc30d8fe3b0d66e057d6c
3
+ metadata.gz: 5b54b885038cd908b12fb7779ba5dad6700c25844d436aae339cffbf909b8b60
4
+ data.tar.gz: 6247d5ba551693f405b2139fcfeee3b679a821c0fe9db091e076f5ab4ef88c01
5
5
  SHA512:
6
- metadata.gz: e8250341f3eef2fef73ec5c0db76b38771e8a127c80af680f844fd0c8e342e8be23ac8e8d62b262084b6024177b42076d6544e1ffd7546c1d3689142e0c4618e
7
- data.tar.gz: 9ad802f13a6831eb15cccaa1491bbb52ff248b18e21dbf71c8cff0dde5093b52f5170b19f9f3314e4a1bafeec8e64a89ad998e10bda22122d1210fa94606a040
6
+ metadata.gz: 24117c44ed8d2b1632ddce6cf817bfb13fe308897535da97c0f1bc5daca7649b41c81dd8558269f11f6454f5e21c7b7504a1a3d5f6ad6d891ec856d880da0550
7
+ data.tar.gz: 42d867c31ca4d7ee5f5d5f0023b30330cb971abed696cf989cacc0dbc788dd05464d81586122e2b9d06f3636cb65bc666b124995e05bfd35b955824abd0c617f
@@ -1,28 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagalicious (0.2.0)
4
+ swagalicious (0.3.1)
5
5
  faraday (~> 1.3.0)
6
6
  json-schema (~> 2.8.1)
7
7
  oj (~> 3.11.0)
8
- rack-test (~> 1.1.0)
9
8
  rspec (~> 3.10.0)
10
9
 
11
10
  GEM
12
11
  remote: https://rubygems.org/
13
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)
14
19
  addressable (2.7.0)
15
20
  public_suffix (>= 2.0.2, < 5.0)
21
+ byebug (11.1.3)
22
+ coderay (1.1.3)
23
+ concurrent-ruby (1.1.8)
16
24
  diff-lcs (1.4.4)
25
+ factory_bot (6.1.0)
26
+ activesupport (>= 5.0.0)
17
27
  faraday (1.3.0)
18
28
  faraday-net_http (~> 1.0)
19
29
  multipart-post (>= 1.2, < 3)
20
30
  ruby2_keywords
21
31
  faraday-net_http (1.0.1)
32
+ i18n (1.8.7)
33
+ concurrent-ruby (~> 1.0)
22
34
  json-schema (2.8.1)
23
35
  addressable (>= 2.4)
36
+ method_source (1.0.0)
37
+ minitest (5.14.3)
24
38
  multipart-post (2.1.1)
25
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)
26
46
  public_suffix (4.0.6)
27
47
  rack (2.2.3)
28
48
  rack-test (1.1.0)
@@ -42,11 +62,17 @@ GEM
42
62
  rspec-support (~> 3.10.0)
43
63
  rspec-support (3.10.1)
44
64
  ruby2_keywords (0.0.4)
65
+ tzinfo (2.0.4)
66
+ concurrent-ruby (~> 1.0)
67
+ zeitwerk (2.4.2)
45
68
 
46
69
  PLATFORMS
47
70
  ruby
48
71
 
49
72
  DEPENDENCIES
73
+ factory_bot (~> 6.1.0)
74
+ pry-byebug (~> 3.9.0)
75
+ rack-test (~> 1.1.0)
50
76
  rake (~> 12.0)
51
77
  rspec (~> 3.0)
52
78
  swagalicious!
@@ -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
- metadata[:response][:examples]["application/json"] = @body
59
+ metadata[:response][:examples] ||= {}
60
+
61
+ mime_types = metadata[:response][:produces] || ["application/json"]
62
+ full_title = "#{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[0]}" if errors.any?
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]
@@ -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
- target_node[:content][mime_type] = { schema: schema }
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
 
@@ -1,3 +1,3 @@
1
1
  class Swagalicious
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -27,6 +27,9 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "faraday", "~> 1.3.0"
28
28
  spec.add_dependency "json-schema", "~> 2.8.1"
29
29
  spec.add_dependency "oj", "~> 3.11.0"
30
- spec.add_dependency "rack-test", "~> 1.1.0"
31
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.3.1
4
+ version: 0.4.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: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -53,33 +53,61 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.11.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: rack-test
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.1.0
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: 1.1.0
68
+ version: 3.10.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: factory_bot
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.10.0
76
- type: :runtime
75
+ version: 6.1.0
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.10.0
82
+ version: 6.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.9.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
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.