rspec-openapi 0.20.0 → 0.21.0
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/.github/workflows/codeql-analysis.yml +3 -3
- data/.github/workflows/rubocop.yml +1 -1
- data/README.md +6 -0
- data/lib/rspec/openapi/schema_builder.rb +69 -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: 6b40fcb7598d29cf3c8bf2f95f6aafb5a011ddbb2beff06d6366052d11effa02
|
|
4
|
+
data.tar.gz: 85bd479d5b7e4da9e19dcc8bbbb963a594eed99437cb911a965695d04768a4bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89c7e3788cfccd022711d1ce76be3ee1b1568af4bade87908afb3384e64e88714a0d4b30499f0eeebb45909fe5eab5267c96afc231ea1db60a6b2fe8fc0155d6
|
|
7
|
+
data.tar.gz: 71e418493c5f3db1c8a5388bd2826fe36e15375445d3ddc7c1b2364cdfb7d160cdf3c9b02554e6134abf82e0f994355b725223c773857fb034e3b7eb034c2db7
|
|
@@ -28,12 +28,12 @@ jobs:
|
|
|
28
28
|
uses: actions/checkout@v5
|
|
29
29
|
|
|
30
30
|
- name: Initialize CodeQL
|
|
31
|
-
uses: github/codeql-action/init@
|
|
31
|
+
uses: github/codeql-action/init@v4
|
|
32
32
|
with:
|
|
33
33
|
languages: ${{ matrix.language }}
|
|
34
34
|
|
|
35
35
|
- name: Autobuild
|
|
36
|
-
uses: github/codeql-action/autobuild@
|
|
36
|
+
uses: github/codeql-action/autobuild@v4
|
|
37
37
|
|
|
38
38
|
- name: Perform CodeQL Analysis
|
|
39
|
-
uses: github/codeql-action/analyze@
|
|
39
|
+
uses: github/codeql-action/analyze@v4
|
data/README.md
CHANGED
|
@@ -408,6 +408,12 @@ Existing RSpec plugins which have OpenAPI integration:
|
|
|
408
408
|
* Orignally created by [k0kubun](https://github.com/k0kubun) and the ownership was transferred to [exoego](https://github.com/exoego) in 2022-11-29.
|
|
409
409
|
|
|
410
410
|
|
|
411
|
+
## Releasing
|
|
412
|
+
|
|
413
|
+
1. Bump version in `lib/rspec/openapi/version.rb`
|
|
414
|
+
2. Run `bundle exec rake release`
|
|
415
|
+
3. Push tag
|
|
416
|
+
|
|
411
417
|
## License
|
|
412
418
|
|
|
413
419
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -151,7 +151,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
|
151
151
|
property[:items] = if value.empty?
|
|
152
152
|
{} # unknown
|
|
153
153
|
else
|
|
154
|
-
|
|
154
|
+
build_array_items_schema(value, record: record)
|
|
155
155
|
end
|
|
156
156
|
when Hash
|
|
157
157
|
property[:properties] = {}.tap do |properties|
|
|
@@ -243,4 +243,72 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
|
243
243
|
def normalize_content_disposition(content_disposition)
|
|
244
244
|
content_disposition&.sub(/;.+\z/, '')
|
|
245
245
|
end
|
|
246
|
+
|
|
247
|
+
def build_array_items_schema(array, record: nil)
|
|
248
|
+
return {} if array.empty?
|
|
249
|
+
|
|
250
|
+
merged_schema = build_property(array.first, record: record)
|
|
251
|
+
|
|
252
|
+
# Future improvement - cover other types than just hashes
|
|
253
|
+
if array.size > 1 && array.all? { |item| item.is_a?(Hash) }
|
|
254
|
+
array[1..].each do |item|
|
|
255
|
+
item_schema = build_property(item, record: record)
|
|
256
|
+
merged_schema = merge_object_schemas(merged_schema, item_schema)
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
merged_schema
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def merge_object_schemas(schema1, schema2)
|
|
264
|
+
return schema1 unless schema2.is_a?(Hash) && schema1.is_a?(Hash)
|
|
265
|
+
return schema1 unless schema1[:type] == 'object' && schema2[:type] == 'object'
|
|
266
|
+
|
|
267
|
+
merged = schema1.dup
|
|
268
|
+
|
|
269
|
+
if schema1[:properties] && schema2[:properties]
|
|
270
|
+
merged[:properties] = schema1[:properties].dup
|
|
271
|
+
|
|
272
|
+
schema2[:properties].each do |key, prop2|
|
|
273
|
+
if merged[:properties][key]
|
|
274
|
+
prop1 = merged[:properties][key]
|
|
275
|
+
merged[:properties][key] = merge_property_schemas(prop1, prop2)
|
|
276
|
+
else
|
|
277
|
+
merged[:properties][key] = make_property_nullable(prop2)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
schema1[:properties].each do |key, prop1|
|
|
282
|
+
merged[:properties][key] = make_property_nullable(prop1) unless schema2[:properties][key]
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
required1 = Set.new(schema1[:required] || [])
|
|
286
|
+
required2 = Set.new(schema2[:required] || [])
|
|
287
|
+
merged[:required] = (required1 & required2).to_a
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
merged
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def merge_property_schemas(prop1, prop2)
|
|
294
|
+
return prop1 unless prop2.is_a?(Hash) && prop1.is_a?(Hash)
|
|
295
|
+
|
|
296
|
+
merged = prop1.dup
|
|
297
|
+
|
|
298
|
+
# If either property is nullable, the merged property should be nullable
|
|
299
|
+
merged[:nullable] = true if prop2[:nullable] && !prop1[:nullable]
|
|
300
|
+
|
|
301
|
+
# If both are objects, recursively merge their properties
|
|
302
|
+
merged = merge_object_schemas(prop1, prop2) if prop1[:type] == 'object' && prop2[:type] == 'object'
|
|
303
|
+
|
|
304
|
+
merged
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def make_property_nullable(property)
|
|
308
|
+
return property unless property.is_a?(Hash)
|
|
309
|
+
|
|
310
|
+
nullable_prop = property.dup
|
|
311
|
+
nullable_prop[:nullable] = true unless nullable_prop[:nullable]
|
|
312
|
+
nullable_prop
|
|
313
|
+
end
|
|
246
314
|
end
|
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.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takashi Kokubun
|
|
@@ -108,7 +108,7 @@ licenses:
|
|
|
108
108
|
metadata:
|
|
109
109
|
homepage_uri: https://github.com/exoego/rspec-openapi
|
|
110
110
|
source_code_uri: https://github.com/exoego/rspec-openapi
|
|
111
|
-
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.
|
|
111
|
+
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.21.0
|
|
112
112
|
rubygems_mfa_required: 'true'
|
|
113
113
|
rdoc_options: []
|
|
114
114
|
require_paths:
|