rswag-specs 2.4.0 → 2.5.0.rc1

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: 9ef5793bfd5d9e2b17fb14a67c41562597de0d3ceba4de65bff02708b52ced46
4
- data.tar.gz: a2c38863e7ed7fe5e3f3d9d2fbdb8eff5d2052c9304ebe89795c6f087c44cce3
3
+ metadata.gz: 0337b822234111d51e0497b909b48a516359c377d60281fca510757737d4ec5b
4
+ data.tar.gz: efbab52e3fde30f2b29861c03b1ccc7aaeece2a6ed4136e87f0240fbcb257a30
5
5
  SHA512:
6
- metadata.gz: 36dc472748a196a30eed6904064c05b3716089bbcea879976ee3ce14be95bcae41b2eab01f2cbd521c3ddbf1b959eaf898ae034c86d7a6b010bc8f7a33b3f66f
7
- data.tar.gz: 610024b7e3ab5a860fb394b3c933a0cfab739c86f7e29f3b9927a566981aedb4e0ed38ddda617e625e49e1e8585d6c1ac14d770de22acaac2452efd14b38b5e5
6
+ metadata.gz: cd6b56b9d346ae29af299a02cbe48dc7bc308fc136b89fa973d56f89fbabab3e5f2910ff701097f3869be539c0b4592106a42b6e052351387694efeede956bae
7
+ data.tar.gz: e92f2795b54cdf75c5a70d547c11a60872456b0f88d929908a553014435950f2c6a1b0201eaac44b9b73e92ede8e75111d31e3822df8dbc44b086e36d6f1a4fd
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
2
+ require "active_support"
3
3
  require 'active_support/core_ext/hash/slice'
4
4
  require 'active_support/core_ext/hash/conversions'
5
5
  require 'json'
@@ -194,12 +194,36 @@ module Rswag
194
194
 
195
195
  def build_json_payload(parameters, example)
196
196
  body_param = parameters.select { |p| p[:in] == :body }.first
197
- body_param ? example.send(body_param[:name]).to_json : nil
197
+
198
+ return nil unless body_param
199
+
200
+ raise(MissingParameterError, body_param[:name]) unless example.respond_to?(body_param[:name])
201
+
202
+ example.send(body_param[:name]).to_json
198
203
  end
199
204
 
200
205
  def doc_version(doc)
201
206
  doc[:openapi] || doc[:swagger] || '3'
202
207
  end
203
208
  end
209
+
210
+ class MissingParameterError < StandardError
211
+ attr_reader :body_param
212
+
213
+ def initialize(body_param)
214
+ @body_param = body_param
215
+ end
216
+
217
+ def message
218
+ <<~MSG
219
+ Missing parameter '#{body_param}'
220
+
221
+ Please check your spec. It looks like you defined a body parameter,
222
+ but did not declare usage via let. Try adding:
223
+
224
+ let(:#{body_param}) {}
225
+ MSG
226
+ end
227
+ end
204
228
  end
205
229
  end
@@ -50,7 +50,11 @@ module Rswag
50
50
  .merge(schemas)
51
51
 
52
52
  errors = JSON::Validator.fully_validate(validation_schema, body)
53
- raise UnexpectedResponse, "Expected response body to match schema: #{errors[0]}" if errors.any?
53
+ return unless errors.any?
54
+
55
+ raise UnexpectedResponse,
56
+ "Expected response body to match schema: #{errors[0]}\n" \
57
+ "Response body: #{JSON.pretty_generate(JSON.parse(body))}"
54
58
  end
55
59
 
56
60
  def definitions_or_component_schemas(swagger_doc, version)
@@ -62,7 +66,7 @@ module Rswag
62
66
  swagger_doc.slice(:definitions)
63
67
  else
64
68
  components = swagger_doc[:components] || {}
65
- { components: { schemas: components[:schemas] } }
69
+ { components: components }
66
70
  end
67
71
  end
68
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rswag-specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richie Morris
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-09 00:00:00.000000000 Z
13
+ date: 2022-02-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.1'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '7.0'
24
+ version: '7.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '3.1'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '7.0'
34
+ version: '7.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: railties
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -41,7 +41,7 @@ dependencies:
41
41
  version: '3.1'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '7.0'
44
+ version: '7.1'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,7 +51,7 @@ dependencies:
51
51
  version: '3.1'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '7.0'
54
+ version: '7.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json-schema
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,11 +109,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ">="
112
+ - - ">"
113
113
  - !ruby/object:Gem::Version
114
- version: '0'
114
+ version: 1.3.1
115
115
  requirements: []
116
- rubygems_version: 3.0.6
116
+ rubygems_version: 3.3.3
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: An OpenAPI-based (formerly called Swagger) DSL for rspec-rails & accompanying