rspec-openapi 0.15.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +5 -5
- data/Gemfile +9 -0
- data/lib/rspec/openapi/components_updater.rb +14 -12
- data/lib/rspec/openapi/hash_helper.rb +6 -4
- data/lib/rspec/openapi/key_transformer.rb +25 -0
- data/lib/rspec/openapi/record.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +9 -4
- data/lib/rspec/openapi/schema_builder.rb +5 -4
- data/lib/rspec/openapi/schema_cleaner.rb +10 -10
- data/lib/rspec/openapi/schema_file.rb +2 -2
- data/lib/rspec/openapi/schema_merger.rb +19 -24
- data/lib/rspec/openapi/schema_sorter.rb +1 -1
- data/lib/rspec/openapi/version.rb +1 -1
- data/lib/rspec/openapi.rb +1 -0
- data/rspec-openapi.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c69f9d896be2ad115cb158175dbcf2c1cba9b6d08a7214d23a107a67ec5fc529
|
4
|
+
data.tar.gz: a5af92611c4b47790f165ce6d861bfdedd1214f5dcd9c5641e618f272fe5a7ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e345e850fc539eb4e9fb018cdc48e7acadb47c774b47b438fcd1a95ebc680708999ae6d5440ee45f793bab47d27effd4e054fa3a08e25bf4e6956085effe9ea
|
7
|
+
data.tar.gz: b1f47ba0a95186141f38465ac4e6a89636185606c48b8a0a67b7f163934c18181ea59e4c7fe94e54291aa821f662ee726437f350f69f872399063b024f7cbfde
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-
|
3
|
+
# on 2024-04-01 14:13:50 UTC using RuboCop version 1.62.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,12 +9,12 @@
|
|
9
9
|
# Offense count: 11
|
10
10
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
11
11
|
Metrics/AbcSize:
|
12
|
-
Max:
|
12
|
+
Max: 49
|
13
13
|
|
14
14
|
# Offense count: 2
|
15
15
|
# Configuration parameters: CountComments, CountAsOne.
|
16
16
|
Metrics/ClassLength:
|
17
|
-
Max:
|
17
|
+
Max: 195
|
18
18
|
|
19
19
|
# Offense count: 8
|
20
20
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
@@ -24,9 +24,9 @@ Metrics/CyclomaticComplexity:
|
|
24
24
|
# Offense count: 19
|
25
25
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
26
26
|
Metrics/MethodLength:
|
27
|
-
Max:
|
27
|
+
Max: 36
|
28
28
|
|
29
|
-
# Offense count:
|
29
|
+
# Offense count: 4
|
30
30
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
31
31
|
Metrics/PerceivedComplexity:
|
32
32
|
Max: 13
|
data/Gemfile
CHANGED
@@ -6,7 +6,16 @@ source 'https://rubygems.org'
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
gem 'rails', ENV['RAILS_VERSION'] || '6.0.3.7'
|
9
|
+
|
10
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
11
|
+
gem 'hanami', ENV['HANAMI_VERSION'] || '2.1.0'
|
12
|
+
gem 'hanami-controller', ENV['HANAMI_VERSION'] || '2.1.0'
|
13
|
+
gem 'hanami-router', ENV['HANAMI_VERSION'] || '2.1.0'
|
14
|
+
end
|
15
|
+
|
9
16
|
gem 'roda'
|
17
|
+
|
18
|
+
gem 'rails-dom-testing', '~> 2.2'
|
10
19
|
gem 'rspec-rails'
|
11
20
|
|
12
21
|
group :test do
|
@@ -23,28 +23,28 @@ class << RSpec::OpenAPI::ComponentsUpdater = Object.new
|
|
23
23
|
# 0 1 2 ^...............................^
|
24
24
|
# ["components", "schema", "Table", "properties", "owner", "properties", "company", "$ref"]
|
25
25
|
# 0 1 2 ^...........................................^
|
26
|
-
needle = paths.reject { |path| path.is_a?(Integer) || path ==
|
26
|
+
needle = paths.reject { |path| path.is_a?(Integer) || path == :oneOf }
|
27
27
|
needle = needle.slice(2, needle.size - 3)
|
28
28
|
nested_schema = fresh_schemas.dig(*needle)
|
29
29
|
|
30
30
|
# Skip if the property using $ref is not found in the parent schema. The property may be removed.
|
31
31
|
next if nested_schema.nil?
|
32
32
|
|
33
|
-
schema_name = base.dig(*paths)&.gsub('#/components/schemas/', '')
|
33
|
+
schema_name = base.dig(*paths)&.gsub('#/components/schemas/', '')&.to_sym
|
34
34
|
fresh_schemas[schema_name] ||= {}
|
35
35
|
RSpec::OpenAPI::SchemaMerger.merge!(fresh_schemas[schema_name], nested_schema)
|
36
36
|
end
|
37
37
|
|
38
|
-
RSpec::OpenAPI::SchemaMerger.merge!(base, {
|
39
|
-
RSpec::OpenAPI::SchemaCleaner.cleanup_components_schemas!(base, {
|
38
|
+
RSpec::OpenAPI::SchemaMerger.merge!(base, { components: { schemas: fresh_schemas } })
|
39
|
+
RSpec::OpenAPI::SchemaCleaner.cleanup_components_schemas!(base, { components: { schemas: fresh_schemas } })
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def build_fresh_schemas(references, base, fresh)
|
45
45
|
references.inject({}) do |acc, paths|
|
46
|
-
ref_link = dig_schema(base, paths)[
|
47
|
-
schema_name = ref_link.gsub('#/components/schemas/', '')
|
46
|
+
ref_link = dig_schema(base, paths)[:$ref]
|
47
|
+
schema_name = ref_link.to_s.gsub('#/components/schemas/', '')
|
48
48
|
schema_body = dig_schema(fresh, paths.reject { |path| path.is_a?(Integer) })
|
49
49
|
|
50
50
|
RSpec::OpenAPI::SchemaMerger.merge!(acc, { schema_name => schema_body })
|
@@ -52,9 +52,11 @@ class << RSpec::OpenAPI::ComponentsUpdater = Object.new
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def dig_schema(obj, paths)
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
# Response code can be an integer
|
56
|
+
paths = paths.map { |path| path.is_a?(Integer) ? path : path.to_sym }
|
57
|
+
item_schema = obj.dig(*paths, :schema, :items)
|
58
|
+
object_schema = obj.dig(*paths, :schema)
|
59
|
+
one_of_schema = obj.dig(*paths.take(paths.size - 1), :schema, :oneOf, paths.last)
|
58
60
|
|
59
61
|
item_schema || object_schema || one_of_schema
|
60
62
|
end
|
@@ -85,12 +87,12 @@ class << RSpec::OpenAPI::ComponentsUpdater = Object.new
|
|
85
87
|
end
|
86
88
|
|
87
89
|
def find_one_of_refs(base, paths)
|
88
|
-
dig_schema(base, paths)&.dig(
|
89
|
-
paths + [index] if schema&.dig(
|
90
|
+
dig_schema(base, paths)&.dig(:oneOf)&.map&.with_index do |schema, index|
|
91
|
+
paths + [index] if schema&.dig(:$ref)&.start_with?('#/components/schemas/')
|
90
92
|
end&.compact
|
91
93
|
end
|
92
94
|
|
93
95
|
def find_object_refs(base, paths)
|
94
|
-
[paths] if dig_schema(base, paths)&.dig(
|
96
|
+
[paths] if dig_schema(base, paths)&.dig(:$ref)&.start_with?('#/components/schemas/')
|
95
97
|
end
|
96
98
|
end
|
@@ -5,7 +5,7 @@ class << RSpec::OpenAPI::HashHelper = Object.new
|
|
5
5
|
case obj
|
6
6
|
when Hash
|
7
7
|
obj.each.flat_map do |k, v|
|
8
|
-
k = k.
|
8
|
+
k = k.to_sym
|
9
9
|
[[k]] + paths_to_all_fields(v).map { |x| [k, *x] }
|
10
10
|
end
|
11
11
|
when Array
|
@@ -18,10 +18,10 @@ class << RSpec::OpenAPI::HashHelper = Object.new
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def matched_paths(obj, selector)
|
21
|
-
selector_parts = selector.split('.').map(&:
|
21
|
+
selector_parts = selector.split('.').map(&:to_sym)
|
22
22
|
paths_to_all_fields(obj).select do |key_parts|
|
23
23
|
key_parts.size == selector_parts.size && key_parts.zip(selector_parts).all? do |kp, sp|
|
24
|
-
kp == sp || (sp ==
|
24
|
+
kp == sp || (sp == :* && !kp.nil?)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -29,7 +29,9 @@ class << RSpec::OpenAPI::HashHelper = Object.new
|
|
29
29
|
def matched_paths_deeply_nested(obj, begin_selector, end_selector)
|
30
30
|
path_depth_sizes = paths_to_all_fields(obj).map(&:size).uniq
|
31
31
|
path_depth_sizes.map do |depth|
|
32
|
-
|
32
|
+
begin_selector_count = begin_selector.is_a?(Symbol) ? 0 : begin_selector.count('.')
|
33
|
+
end_selector_count = end_selector.is_a?(Symbol) ? 0 : end_selector.count('.')
|
34
|
+
diff = depth - begin_selector_count - end_selector_count
|
33
35
|
if diff >= 0
|
34
36
|
selector = "#{begin_selector}.#{'*.' * diff}#{end_selector}"
|
35
37
|
matched_paths(obj, selector)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class << RSpec::OpenAPI::KeyTransformer = Object.new
|
4
|
+
def symbolize(value)
|
5
|
+
case value
|
6
|
+
when Hash
|
7
|
+
value.to_h { |k, v| [k.to_sym, symbolize(v)] }
|
8
|
+
when Array
|
9
|
+
value.map { |v| symbolize(v) }
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def stringify(value)
|
16
|
+
case value
|
17
|
+
when Hash
|
18
|
+
value.to_h { |k, v| [k.to_s, stringify(v)] }
|
19
|
+
when Array
|
20
|
+
value.map { |v| stringify(v) }
|
21
|
+
else
|
22
|
+
value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/rspec/openapi/record.rb
CHANGED
@@ -14,6 +14,7 @@ RSpec::OpenAPI::Record = Struct.new(
|
|
14
14
|
:operation_id, # @param [String] - "request-1234"
|
15
15
|
:description, # @param [String] - "returns a status"
|
16
16
|
:security, # @param [Array] - [{securityScheme1: []}]
|
17
|
+
:deprecated, # @param [Boolean] - true
|
17
18
|
:status, # @param [Integer] - 200
|
18
19
|
:response_body, # @param [Object] - {"status" => "ok"}
|
19
20
|
:response_headers, # @param [Array] - [["header_key1", "header_value1"], ["header_key2", "header_value2"]]
|
@@ -11,7 +11,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
11
11
|
request, response = extract_request_response(context)
|
12
12
|
return if request.nil?
|
13
13
|
|
14
|
-
path, summary, tags, operation_id, required_request_params, raw_path_params, description, security =
|
14
|
+
path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated =
|
15
15
|
extract_request_attributes(request, example)
|
16
16
|
|
17
17
|
return if RSpec::OpenAPI.ignored_paths.any? { |ignored_path| path.match?(ignored_path) }
|
@@ -32,6 +32,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
32
32
|
operation_id: operation_id,
|
33
33
|
description: description,
|
34
34
|
security: security,
|
35
|
+
deprecated: deprecated,
|
35
36
|
status: response.status,
|
36
37
|
response_body: safe_parse_body(response, response.media_type),
|
37
38
|
response_headers: response_headers,
|
@@ -53,8 +54,11 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
53
54
|
|
54
55
|
def extract_headers(request, response)
|
55
56
|
request_headers = RSpec::OpenAPI.request_headers.each_with_object([]) do |header, headers_arr|
|
56
|
-
header_key = header.gsub('-', '_').upcase
|
57
|
-
|
57
|
+
header_key = header.gsub('-', '_').upcase.to_sym
|
58
|
+
|
59
|
+
header_value = request.get_header(['HTTP', header_key].join('_')) ||
|
60
|
+
request.get_header(header_key) ||
|
61
|
+
request.get_header(header_key.to_s)
|
58
62
|
headers_arr << [header, header_value] if header_value
|
59
63
|
end
|
60
64
|
response_headers = RSpec::OpenAPI.response_headers.each_with_object([]) do |header, headers_arr|
|
@@ -73,6 +77,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
73
77
|
required_request_params = metadata[:required_request_params] || []
|
74
78
|
security = metadata[:security]
|
75
79
|
description = metadata[:description] || RSpec::OpenAPI.description_builder.call(example)
|
80
|
+
deprecated = metadata[:deprecated]
|
76
81
|
raw_path_params = request.path_parameters
|
77
82
|
path = request.path
|
78
83
|
if rails?
|
@@ -91,7 +96,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
91
96
|
raw_path_params = raw_path_params.slice(*(raw_path_params.keys - RSpec::OpenAPI.ignored_path_params))
|
92
97
|
end
|
93
98
|
summary ||= "#{request.method} #{path}"
|
94
|
-
[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security]
|
99
|
+
[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated]
|
95
100
|
end
|
96
101
|
|
97
102
|
def extract_request_response(context)
|
@@ -25,16 +25,18 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
http_method = record.http_method.downcase
|
28
29
|
{
|
29
30
|
paths: {
|
30
31
|
normalize_path(record.path) => {
|
31
|
-
|
32
|
+
http_method => {
|
32
33
|
summary: record.summary,
|
33
34
|
tags: record.tags,
|
34
35
|
operationId: record.operation_id,
|
35
36
|
security: record.security,
|
37
|
+
deprecated: record.deprecated ? true : nil,
|
36
38
|
parameters: build_parameters(record),
|
37
|
-
requestBody: build_request_body(record),
|
39
|
+
requestBody: http_method == 'get' ? nil : build_request_body(record),
|
38
40
|
responses: {
|
39
41
|
record.status.to_s => response,
|
40
42
|
},
|
@@ -47,7 +49,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
47
49
|
private
|
48
50
|
|
49
51
|
def enrich_with_required_keys(obj)
|
50
|
-
obj[:required] = obj[:properties]&.keys
|
52
|
+
obj[:required] = obj[:properties]&.keys || []
|
51
53
|
obj
|
52
54
|
end
|
53
55
|
|
@@ -123,7 +125,6 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
123
125
|
|
124
126
|
def build_request_body(record)
|
125
127
|
return nil if record.request_content_type.nil?
|
126
|
-
return nil if record.request_params.empty?
|
127
128
|
return nil if record.status >= 400
|
128
129
|
|
129
130
|
{
|
@@ -27,7 +27,7 @@ class << RSpec::OpenAPI::SchemaCleaner = Object.new
|
|
27
27
|
cleanup_hash!(base, spec, 'paths.*.*')
|
28
28
|
|
29
29
|
# cleanup parameters
|
30
|
-
cleanup_array!(base, spec, 'paths.*.*.parameters', %
|
30
|
+
cleanup_array!(base, spec, 'paths.*.*.parameters', %i[name in])
|
31
31
|
|
32
32
|
# cleanup requestBody
|
33
33
|
cleanup_hash!(base, spec, 'paths.*.*.requestBody.content.application/json.schema.properties.*')
|
@@ -40,7 +40,7 @@ class << RSpec::OpenAPI::SchemaCleaner = Object.new
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def cleanup_conflicting_security_parameters!(base)
|
43
|
-
security_schemes = base.dig(
|
43
|
+
security_schemes = base.dig(:components, :securitySchemes) || {}
|
44
44
|
|
45
45
|
return if security_schemes.empty?
|
46
46
|
|
@@ -65,22 +65,22 @@ class << RSpec::OpenAPI::SchemaCleaner = Object.new
|
|
65
65
|
paths_to_objects.each do |path|
|
66
66
|
parent = base.dig(*path.take(path.length - 1))
|
67
67
|
# "required" array must not be present if empty
|
68
|
-
parent.delete(
|
68
|
+
parent.delete(:required) if parent[:required] && parent[:required].empty?
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def remove_parameters_conflicting_with_security_sceheme!(path_definition, security_scheme, security_scheme_name)
|
75
|
-
return unless path_definition[
|
76
|
-
return unless path_definition[
|
77
|
-
return unless path_definition.dig(
|
75
|
+
return unless path_definition[:security]
|
76
|
+
return unless path_definition[:parameters]
|
77
|
+
return unless path_definition.dig(:security, 0).keys.include?(security_scheme_name)
|
78
78
|
|
79
|
-
path_definition[
|
80
|
-
parameter[
|
81
|
-
parameter[
|
79
|
+
path_definition[:parameters].reject! do |parameter|
|
80
|
+
parameter[:in] == security_scheme[:in] && # same location (ie. header)
|
81
|
+
parameter[:name] == security_scheme[:name] # same name (ie. AUTHORIZATION)
|
82
82
|
end
|
83
|
-
path_definition.delete(
|
83
|
+
path_definition.delete(:parameters) if path_definition[:parameters].empty?
|
84
84
|
end
|
85
85
|
|
86
86
|
def cleanup_array!(base, spec, selector, fields_for_identity = [])
|
@@ -15,7 +15,7 @@ class RSpec::OpenAPI::SchemaFile
|
|
15
15
|
spec = read
|
16
16
|
block.call(spec)
|
17
17
|
ensure
|
18
|
-
write(spec)
|
18
|
+
write(RSpec::OpenAPI::KeyTransformer.stringify(spec))
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -24,7 +24,7 @@ class RSpec::OpenAPI::SchemaFile
|
|
24
24
|
def read
|
25
25
|
return {} unless File.exist?(@path)
|
26
26
|
|
27
|
-
YAML.safe_load(File.read(@path)) # this can also parse JSON
|
27
|
+
RSpec::OpenAPI::KeyTransformer.symbolize(YAML.safe_load(File.read(@path))) # this can also parse JSON
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [Hash] spec
|
@@ -4,32 +4,20 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
4
4
|
# @param [Hash] base
|
5
5
|
# @param [Hash] spec
|
6
6
|
def merge!(base, spec)
|
7
|
-
spec =
|
7
|
+
spec = RSpec::OpenAPI::KeyTransformer.symbolize(spec)
|
8
|
+
base.replace(RSpec::OpenAPI::KeyTransformer.symbolize(base))
|
8
9
|
merge_schema!(base, spec)
|
9
10
|
end
|
10
11
|
|
11
12
|
private
|
12
13
|
|
13
|
-
def normalize_keys(spec)
|
14
|
-
case spec
|
15
|
-
when Hash
|
16
|
-
spec.to_h do |key, value|
|
17
|
-
[key.to_s, normalize_keys(value)]
|
18
|
-
end
|
19
|
-
when Array
|
20
|
-
spec.map { |s| normalize_keys(s) }
|
21
|
-
else
|
22
|
-
spec
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
14
|
# Not doing `base.replace(deep_merge(base, spec))` to preserve key orders.
|
27
15
|
# Also this needs to be aware of OpenAPI details because a Hash-like structure
|
28
16
|
# may be an array whose Hash elements have a key name.
|
29
17
|
#
|
30
18
|
# TODO: Should we probably force-merge `summary` regardless of manual modifications?
|
31
19
|
def merge_schema!(base, spec)
|
32
|
-
if (options = base[
|
20
|
+
if (options = base[:oneOf])
|
33
21
|
merge_closest_match!(options, spec)
|
34
22
|
|
35
23
|
return base
|
@@ -37,13 +25,13 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
37
25
|
|
38
26
|
spec.each do |key, value|
|
39
27
|
if base[key].is_a?(Hash) && value.is_a?(Hash)
|
40
|
-
merge_schema!(base[key], value) unless base[key].key?(
|
28
|
+
merge_schema!(base[key], value) unless base[key].key?(:$ref)
|
41
29
|
elsif base[key].is_a?(Array) && value.is_a?(Array)
|
42
30
|
# parameters need to be merged as if `name` and `in` were the Hash keys.
|
43
31
|
merge_arrays(base, key, value)
|
44
32
|
else
|
45
33
|
# do not ADD `properties` or `required` fields if `additionalProperties` field is present
|
46
|
-
base[key] = value unless base.key?(
|
34
|
+
base[key] = value unless base.key?(:additionalProperties) && %i[properties required].include?(key)
|
47
35
|
end
|
48
36
|
end
|
49
37
|
base
|
@@ -51,9 +39,9 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
51
39
|
|
52
40
|
def merge_arrays(base, key, value)
|
53
41
|
base[key] = case key
|
54
|
-
when
|
42
|
+
when :parameters
|
55
43
|
merge_parameters(base, key, value)
|
56
|
-
when
|
44
|
+
when :required
|
57
45
|
# Preserve properties that appears in all test cases
|
58
46
|
value & base[key]
|
59
47
|
else
|
@@ -65,22 +53,29 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
65
53
|
def merge_parameters(base, key, value)
|
66
54
|
all_parameters = value | base[key]
|
67
55
|
|
68
|
-
unique_base_parameters = base
|
56
|
+
unique_base_parameters = build_unique_params(base, key)
|
57
|
+
|
69
58
|
all_parameters = all_parameters.map do |parameter|
|
70
|
-
base_parameter = unique_base_parameters[[parameter[
|
59
|
+
base_parameter = unique_base_parameters[[parameter[:name], parameter[:in]]] || {}
|
71
60
|
base_parameter ? base_parameter.merge(parameter) : parameter
|
72
61
|
end
|
73
62
|
|
74
|
-
all_parameters.uniq! { |param| param.slice(
|
63
|
+
all_parameters.uniq! { |param| param.slice(:name, :in) }
|
75
64
|
base[key] = all_parameters
|
76
65
|
end
|
77
66
|
|
67
|
+
def build_unique_params(base, key)
|
68
|
+
base[key].each_with_object({}) do |parameter, hash|
|
69
|
+
hash[[parameter[:name], parameter[:in]]] = parameter
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
78
73
|
SIMILARITY_THRESHOLD = 0.5
|
79
74
|
|
80
75
|
def merge_closest_match!(options, spec)
|
81
76
|
score, option = options.map { |option| [similarity(option, spec), option] }.max_by(&:first)
|
82
77
|
|
83
|
-
return if option&.key?(
|
78
|
+
return if option&.key?(:$ref)
|
84
79
|
|
85
80
|
if score.to_f > SIMILARITY_THRESHOLD
|
86
81
|
merge_schema!(option, spec)
|
@@ -97,7 +92,7 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
97
92
|
when [Array, Array]
|
98
93
|
(first & second).size / [first.size, second.size].max.to_f
|
99
94
|
when [Hash, Hash]
|
100
|
-
return 1 if first.merge(second).key?(
|
95
|
+
return 1 if first.merge(second).key?(:$ref)
|
101
96
|
|
102
97
|
intersection = first.keys & second.keys
|
103
98
|
total_size = [first.size, second.size].max.to_f
|
data/lib/rspec/openapi.rb
CHANGED
@@ -10,6 +10,7 @@ require 'rspec/openapi/schema_file'
|
|
10
10
|
require 'rspec/openapi/schema_merger'
|
11
11
|
require 'rspec/openapi/schema_cleaner'
|
12
12
|
require 'rspec/openapi/schema_sorter'
|
13
|
+
require 'rspec/openapi/key_transformer'
|
13
14
|
|
14
15
|
require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
|
15
16
|
require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
|
data/rspec-openapi.gemspec
CHANGED
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.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 5.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails-dom-testing
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rspec-core
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,6 +81,7 @@ files:
|
|
67
81
|
- lib/rspec/openapi/components_updater.rb
|
68
82
|
- lib/rspec/openapi/default_schema.rb
|
69
83
|
- lib/rspec/openapi/hash_helper.rb
|
84
|
+
- lib/rspec/openapi/key_transformer.rb
|
70
85
|
- lib/rspec/openapi/minitest_hooks.rb
|
71
86
|
- lib/rspec/openapi/record.rb
|
72
87
|
- lib/rspec/openapi/record_builder.rb
|
@@ -88,7 +103,7 @@ licenses:
|
|
88
103
|
metadata:
|
89
104
|
homepage_uri: https://github.com/exoego/rspec-openapi
|
90
105
|
source_code_uri: https://github.com/exoego/rspec-openapi
|
91
|
-
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.
|
106
|
+
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.16.1
|
92
107
|
rubygems_mfa_required: 'true'
|
93
108
|
post_install_message:
|
94
109
|
rdoc_options: []
|