rswag-specs 2.13.0 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rswag/specs/configuration.rb +8 -0
- data/lib/rswag/specs/request_factory.rb +14 -9
- data/lib/rswag/specs/response_validator.rb +14 -4
- data/lib/rswag/specs/swagger_formatter.rb +13 -0
- data/lib/rswag/specs.rb +12 -2
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0a717ee80be6c37b90e1fc7ea402139c0e07d2972e6548c2aeffd1a1f86f07
|
4
|
+
data.tar.gz: ad12167354bfde937b5315657362adfb4d4930b76fb40ef3468c7fd08e2dbce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f725ad91cb4982da4ee8ce87c86b1677e4aefbb01727963cb9b847c6788cf00a6d62beda51af391a35d242ab5d54ea2201531792c522a2dd71ff295934040901
|
7
|
+
data.tar.gz: c3039e9a8176812533fdfa8564d2796b0273a2ad5f6d3ae0007054c5a3fb5be8199609a38b3a5a7397eb8eb8d95f764f5f62de8badfe9fddfa2bcfec346acad9
|
@@ -61,6 +61,14 @@ module Rswag
|
|
61
61
|
def openapi_strict_schema_validation
|
62
62
|
@rspec_config.openapi_strict_schema_validation || false
|
63
63
|
end
|
64
|
+
|
65
|
+
def openapi_all_properties_required
|
66
|
+
@rspec_config.openapi_all_properties_required || false
|
67
|
+
end
|
68
|
+
|
69
|
+
def openapi_no_additional_properties
|
70
|
+
@rspec_config.openapi_no_additional_properties || false
|
71
|
+
end
|
64
72
|
end
|
65
73
|
|
66
74
|
class ConfigurationError < StandardError; end
|
@@ -174,7 +174,7 @@ module Rswag
|
|
174
174
|
return "#{escaped_name}=" + value.to_a.flatten.map{|v| CGI.escape(v.to_s) }.join(separator)
|
175
175
|
end
|
176
176
|
else
|
177
|
-
return "#{
|
177
|
+
return "#{escaped_name}=#{CGI.escape(value.to_s)}"
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
@@ -242,11 +242,13 @@ module Rswag
|
|
242
242
|
content_type = request[:headers]['CONTENT_TYPE']
|
243
243
|
return if content_type.nil?
|
244
244
|
|
245
|
-
if ['application/x-www-form-urlencoded', 'multipart/form-data'].include?(content_type)
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
245
|
+
request[:payload] = if ['application/x-www-form-urlencoded', 'multipart/form-data'].include?(content_type)
|
246
|
+
build_form_payload(parameters, example)
|
247
|
+
elsif content_type =~ /\Aapplication\/([0-9A-Za-z._-]+\+json\z|json\z)/
|
248
|
+
build_json_payload(parameters, example)
|
249
|
+
else
|
250
|
+
build_raw_payload(parameters, example)
|
251
|
+
end
|
250
252
|
end
|
251
253
|
|
252
254
|
def build_form_payload(parameters, example)
|
@@ -260,14 +262,17 @@ module Rswag
|
|
260
262
|
Hash[tuples]
|
261
263
|
end
|
262
264
|
|
263
|
-
def
|
265
|
+
def build_raw_payload(parameters, example)
|
264
266
|
body_param = parameters.select { |p| p[:in] == :body }.first
|
265
|
-
|
266
267
|
return nil unless body_param
|
267
268
|
|
268
269
|
raise(MissingParameterError, body_param[:name]) unless example.respond_to?(body_param[:name])
|
269
270
|
|
270
|
-
example.send(body_param[:name])
|
271
|
+
example.send(body_param[:name])
|
272
|
+
end
|
273
|
+
|
274
|
+
def build_json_payload(parameters, example)
|
275
|
+
build_raw_payload(parameters, example)&.to_json
|
271
276
|
end
|
272
277
|
|
273
278
|
def doc_version(doc)
|
@@ -73,14 +73,24 @@ module Rswag
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def validation_options_from(metadata)
|
76
|
+
is_strict = @config.openapi_strict_schema_validation
|
77
|
+
|
76
78
|
if metadata.key?(:swagger_strict_schema_validation)
|
77
|
-
Rswag::Specs.deprecator.warn('Rswag::Specs: WARNING: This option will be
|
79
|
+
Rswag::Specs.deprecator.warn('Rswag::Specs: WARNING: This option will be removed in v3.0 please use openapi_all_properties_required and openapi_no_additional_properties set to true')
|
78
80
|
is_strict = !!metadata[:swagger_strict_schema_validation]
|
79
|
-
|
80
|
-
|
81
|
+
elsif metadata.key?(:openapi_strict_schema_validation)
|
82
|
+
Rswag::Specs.deprecator.warn('Rswag::Specs: WARNING: This option will be removed in v3.0 please use openapi_all_properties_required and openapi_no_additional_properties set to true')
|
83
|
+
is_strict = !!metadata[:openapi_strict_schema_validation]
|
81
84
|
end
|
82
85
|
|
83
|
-
|
86
|
+
all_properties_required = metadata.fetch(:openapi_all_properties_required, @config.openapi_all_properties_required)
|
87
|
+
no_additional_properties = metadata.fetch(:openapi_no_additional_properties, @config.openapi_no_additional_properties)
|
88
|
+
|
89
|
+
{
|
90
|
+
strict: is_strict,
|
91
|
+
allPropertiesRequired: all_properties_required,
|
92
|
+
noAdditionalProperties: no_additional_properties
|
93
|
+
}
|
84
94
|
end
|
85
95
|
|
86
96
|
def definitions_or_component_schemas(swagger_doc, version)
|
@@ -74,6 +74,11 @@ module Rswag
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
enum_param = value.dig(:parameters).find{|p| p[:enum]}
|
78
|
+
if enum_param && enum_param.is_a?(Hash)
|
79
|
+
enum_param[:description] = generate_enum_description(enum_param)
|
80
|
+
end
|
81
|
+
|
77
82
|
value[:parameters].reject! { |p| p[:in] == :body || p[:in] == :formData }
|
78
83
|
end
|
79
84
|
remove_invalid_operation_keys!(value)
|
@@ -211,6 +216,14 @@ module Rswag
|
|
211
216
|
value.delete(:request_examples) if value[:request_examples]
|
212
217
|
value[:parameters].each { |p| p.delete(:getter) } if value[:parameters]
|
213
218
|
end
|
219
|
+
|
220
|
+
def generate_enum_description(param)
|
221
|
+
enum_description = "#{param[:description]}:\n "
|
222
|
+
param[:enum].each do |k,v|
|
223
|
+
enum_description += "* `#{k}` #{v}\n "
|
224
|
+
end
|
225
|
+
enum_description
|
226
|
+
end
|
214
227
|
end
|
215
228
|
end
|
216
229
|
end
|
data/lib/rswag/specs.rb
CHANGED
@@ -12,8 +12,7 @@ module Rswag
|
|
12
12
|
swagger_root: :openapi_root,
|
13
13
|
swagger_docs: :openapi_specs,
|
14
14
|
swagger_dry_run: :rswag_dry_run,
|
15
|
-
swagger_format: :openapi_format
|
16
|
-
swagger_strict_schema_validation: :openapi_strict_schema_validation
|
15
|
+
swagger_format: :openapi_format
|
17
16
|
}.freeze
|
18
17
|
private_constant :RENAMED_METHODS
|
19
18
|
|
@@ -24,6 +23,8 @@ module Rswag
|
|
24
23
|
c.add_setting :rswag_dry_run
|
25
24
|
c.add_setting :openapi_format, default: :json
|
26
25
|
c.add_setting :openapi_strict_schema_validation
|
26
|
+
c.add_setting :openapi_all_properties_required
|
27
|
+
c.add_setting :openapi_no_additional_properties
|
27
28
|
c.extend ExampleGroupHelpers, type: :request
|
28
29
|
c.include ExampleHelpers, type: :request
|
29
30
|
end
|
@@ -46,6 +47,10 @@ module Rswag
|
|
46
47
|
public_send("#{new_name}=", *args, &block)
|
47
48
|
end
|
48
49
|
end
|
50
|
+
|
51
|
+
define_method('swagger_strict_schema_validation=') do |*args, &block|
|
52
|
+
public_send('openapi_strict_schema_validation=', *args, &block)
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
Specs.deprecator.deprecate_methods(
|
@@ -53,6 +58,11 @@ module Rswag
|
|
53
58
|
RENAMED_METHODS.to_h { |old_name, new_name| ["#{old_name}=".to_sym, "#{new_name}=".to_sym] }
|
54
59
|
)
|
55
60
|
|
61
|
+
Specs.deprecator.deprecate_methods(
|
62
|
+
RSpec::Core::Configuration,
|
63
|
+
:openapi_strict_schema_validation= => 'use openapi_all_properties_required and openapi_no_additional_properties set to true'
|
64
|
+
)
|
65
|
+
|
56
66
|
if RUBY_VERSION.start_with? '2.6'
|
57
67
|
Specs.deprecator.warn('Rswag::Specs: WARNING: Support for Ruby 2.6 will be dropped in v3.0')
|
58
68
|
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
|
+
version: 2.15.0
|
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:
|
13
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -18,20 +18,20 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '5.2'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '8.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
31
|
+
version: '5.2'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '8.0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: json-schema
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
version: '2.2'
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
44
|
+
version: '6.0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,27 +51,27 @@ dependencies:
|
|
51
51
|
version: '2.2'
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '6.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: railties
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '5.2'
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '8.0'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
71
|
+
version: '5.2'
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '8.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rspec-core
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
151
|
+
rubygems_version: 3.5.11
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: An OpenAPI-based (formerly called Swagger) DSL for rspec-rails & accompanying
|