rspec-openapi 0.21.3 → 0.21.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rspec/openapi/schema_builder.rb +31 -11
- data/lib/rspec/openapi/schema_merger.rb +6 -1
- data/lib/rspec/openapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b35d6193603f213ab605629e833a56827da2cc4071a9bde884ed7f67ae257946
|
|
4
|
+
data.tar.gz: d3f5d1b55e242ccde842aca000aebdcff950fac29d11197cdd2002bedd9f6976
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c30cc46860494d67aed4b1eb9ea11db58b77bbfec31f3d1fef1f0723aad7a16775ed30f4b874331eec6ed26a3238522f8ee018d0ae252fe769a78de3b6b5eb46
|
|
7
|
+
data.tar.gz: e50cf253d00c8d4c11d6abe1793c32b8a5eec594dca37d8fdeb48969a3e4c13c79b40e8a034f3ca0f4cec2909e0c48d5d8082131c9109ffe9015ddc0ec5bdf75
|
|
@@ -272,15 +272,20 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
|
272
272
|
else
|
|
273
273
|
unique_types = property_variations.map { |p| p[:type] }.compact.uniq
|
|
274
274
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
merged_schema[:properties][key] = {
|
|
278
|
-
items_variations = property_variations.map { |p| p[:items] }.compact
|
|
279
|
-
merged_schema[:properties][key][:items] = build_merged_schema_from_variations(items_variations)
|
|
280
|
-
when 'object'
|
|
281
|
-
merged_schema[:properties][key] = build_merged_schema_from_variations(property_variations)
|
|
275
|
+
if unique_types.size > 1
|
|
276
|
+
unique_props = property_variations.map { |p| p.reject { |k, _| k == :nullable } }.uniq
|
|
277
|
+
merged_schema[:properties][key] = { oneOf: unique_props }
|
|
282
278
|
else
|
|
283
|
-
|
|
279
|
+
case unique_types.first
|
|
280
|
+
when 'array'
|
|
281
|
+
merged_schema[:properties][key] = { type: 'array' }
|
|
282
|
+
items_variations = property_variations.map { |p| p[:items] }.compact
|
|
283
|
+
merged_schema[:properties][key][:items] = build_merged_schema_from_variations(items_variations)
|
|
284
|
+
when 'object'
|
|
285
|
+
merged_schema[:properties][key] = build_merged_schema_from_variations(property_variations)
|
|
286
|
+
else
|
|
287
|
+
merged_schema[:properties][key] = property_variations.first.dup
|
|
288
|
+
end
|
|
284
289
|
end
|
|
285
290
|
end
|
|
286
291
|
|
|
@@ -309,7 +314,9 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
|
309
314
|
nullable_only = all_prop_variations.select { |p| p && p.keys == [:nullable] }
|
|
310
315
|
prop_variations = all_prop_variations.select { |p| p && p.keys != [:nullable] }.compact
|
|
311
316
|
|
|
312
|
-
has_nullable = all_prop_variations.any?
|
|
317
|
+
has_nullable = all_prop_variations.any? do |v|
|
|
318
|
+
v.nil? || (v.is_a?(Hash) && v[:nullable] == true)
|
|
319
|
+
end || nullable_only.any?
|
|
313
320
|
|
|
314
321
|
if prop_variations.empty? && has_nullable
|
|
315
322
|
merged[:properties][key] = { nullable: true }
|
|
@@ -318,8 +325,21 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
|
318
325
|
merged[:properties][key][:nullable] = true if has_nullable
|
|
319
326
|
elsif prop_variations.size > 1
|
|
320
327
|
prop_types = prop_variations.map { |p| p[:type] }.compact.uniq
|
|
321
|
-
|
|
322
|
-
|
|
328
|
+
has_one_of = prop_variations.any? { |p| p.key?(:oneOf) }
|
|
329
|
+
|
|
330
|
+
if has_one_of
|
|
331
|
+
all_options = []
|
|
332
|
+
prop_variations.each do |prop|
|
|
333
|
+
clean_prop = prop.reject { |k, _| k == :nullable }
|
|
334
|
+
if clean_prop.key?(:oneOf)
|
|
335
|
+
all_options.concat(clean_prop[:oneOf])
|
|
336
|
+
else
|
|
337
|
+
all_options << clean_prop unless clean_prop.empty?
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
all_options.uniq!
|
|
341
|
+
merged[:properties][key] = { oneOf: all_options }
|
|
342
|
+
elsif prop_types.size == 1
|
|
323
343
|
# Only recursively merge if it's an object type
|
|
324
344
|
merged[:properties][key] = if prop_types.first == 'object'
|
|
325
345
|
build_merged_schema_from_variations(prop_variations)
|
|
@@ -25,7 +25,12 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
|
25
25
|
|
|
26
26
|
spec.each do |key, value|
|
|
27
27
|
if base[key].is_a?(Hash) && value.is_a?(Hash)
|
|
28
|
-
|
|
28
|
+
# If the new value has oneOf, replace the entire value instead of merging
|
|
29
|
+
if value.key?(:oneOf)
|
|
30
|
+
base[key] = value
|
|
31
|
+
else
|
|
32
|
+
merge_schema!(base[key], value) unless base[key].key?(:$ref)
|
|
33
|
+
end
|
|
29
34
|
elsif base[key].is_a?(Array) && value.is_a?(Array)
|
|
30
35
|
# parameters need to be merged as if `name` and `in` were the Hash keys.
|
|
31
36
|
merge_arrays(base, key, value)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-openapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.21.
|
|
4
|
+
version: 0.21.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takashi Kokubun
|
|
@@ -110,7 +110,7 @@ licenses:
|
|
|
110
110
|
metadata:
|
|
111
111
|
homepage_uri: https://github.com/exoego/rspec-openapi
|
|
112
112
|
source_code_uri: https://github.com/exoego/rspec-openapi
|
|
113
|
-
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.21.
|
|
113
|
+
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.21.5
|
|
114
114
|
rubygems_mfa_required: 'true'
|
|
115
115
|
rdoc_options: []
|
|
116
116
|
require_paths:
|