Skip to content

Commit e12b0ce

Browse files
authored
Merge pull request #363 from ahx/fix-resolve-array
Fix resolving referenced array values
2 parents 8c0f7e4 + dc7bbd7 commit e12b0ce

6 files changed

Lines changed: 52 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
## 2.7.2
6+
7+
- Fix $ref-resolving for referenced arrays.
8+
This fixes loading something like this:
9+
```yaml
10+
parameters:
11+
$ref: 'my-paramters.yaml'
12+
```
13+
514
## 2.7.1
615
716
- Speedup loading very large OADs by deferring creation of JSONSchemer::Schema instances.

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
openapi_first (2.7.1)
4+
openapi_first (2.7.2)
55
hana (~> 1.3)
66
json_schemer (>= 2.1, < 3.0)
77
openapi_parameters (>= 0.3.3, < 2.0)
@@ -47,23 +47,23 @@ GEM
4747
concurrent-ruby (1.3.5)
4848
connection_pool (2.5.3)
4949
crass (1.0.6)
50-
diff-lcs (1.6.1)
50+
diff-lcs (1.6.2)
5151
docile (1.4.1)
5252
drb (2.2.1)
5353
erubi (1.13.1)
5454
hana (1.3.7)
5555
i18n (1.14.7)
5656
concurrent-ruby (~> 1.0)
57-
json (2.11.3)
57+
json (2.12.0)
5858
json_schemer (2.4.0)
5959
bigdecimal
6060
hana (~> 1.3)
6161
regexp_parser (~> 2.0)
6262
simpleidn (~> 0.2)
63-
language_server-protocol (3.17.0.4)
63+
language_server-protocol (3.17.0.5)
6464
lint_roller (1.1.0)
6565
logger (1.7.0)
66-
loofah (2.24.0)
66+
loofah (2.24.1)
6767
crass (~> 1.0.2)
6868
nokogiri (>= 1.12.0)
6969
minitest (5.25.5)
@@ -79,7 +79,7 @@ GEM
7979
racc
8080
prism (1.4.0)
8181
racc (1.8.1)
82-
rack (3.1.13)
82+
rack (3.1.14)
8383
rack-session (2.1.1)
8484
base64 (>= 0.1.0)
8585
rack (>= 3.0.0)
@@ -110,7 +110,7 @@ GEM
110110
diff-lcs (>= 1.2.0, < 2.0)
111111
rspec-support (~> 3.13.0)
112112
rspec-support (3.13.3)
113-
rubocop (1.75.5)
113+
rubocop (1.75.6)
114114
json (~> 2.3)
115115
language_server-protocol (~> 3.17.0.2)
116116
lint_roller (~> 1.1.0)

benchmarks/Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
openapi_first (2.7.1)
4+
openapi_first (2.7.2)
55
hana (~> 1.3)
66
json_schemer (>= 2.1, < 3.0)
77
openapi_parameters (>= 0.3.3, < 2.0)
@@ -16,7 +16,7 @@ GEM
1616
benchmark-memory (0.2.0)
1717
memory_profiler (~> 1)
1818
bigdecimal (3.1.9)
19-
committee (5.5.3)
19+
committee (5.5.4)
2020
json_schema (~> 0.14, >= 0.14.3)
2121
openapi_parser (~> 2.0)
2222
rack (>= 1.5, < 3.2)
@@ -36,12 +36,12 @@ GEM
3636
rack (>= 2.2)
3737
openapi_parser (2.2.6)
3838
optparse (0.6.0)
39-
profile-viewer (0.0.4)
39+
profile-viewer (0.0.5)
4040
optparse
4141
webrick
4242
puma (6.6.0)
4343
nio4r (~> 2.0)
44-
rack (3.1.13)
44+
rack (3.1.14)
4545
rack-protection (4.1.1)
4646
base64 (>= 0.1.0)
4747
logger (>= 1.6.0)
@@ -60,7 +60,7 @@ GEM
6060
rack-session (>= 2.0.0, < 3)
6161
tilt (~> 2.0)
6262
tilt (2.6.0)
63-
vernier (1.7.0)
63+
vernier (1.7.1)
6464
webrick (1.9.1)
6565

6666
PLATFORMS

lib/openapi_first/ref_resolver.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ def self.load(filepath)
1414
def self.for(value, filepath: nil, context: value)
1515
case value
1616
when ::Hash
17-
Hash.new(value, context:, filepath:)
17+
resolver = Hash.new(value, context:, filepath:)
18+
if value.key?('$ref')
19+
probe = resolver.resolve_ref(value['$ref'])
20+
return probe if probe.is_a?(Array)
21+
end
22+
resolver
1823
when ::Array
1924
Array.new(value, context:, filepath:)
2025
when ::NilClass

lib/openapi_first/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module OpenapiFirst
4-
VERSION = '2.7.1'
4+
VERSION = '2.7.2'
55
end

spec/ref_resolver_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,30 @@
295295
{ 'name' => 'B' }
296296
])
297297
end
298+
299+
it 'works with a referenced array' do
300+
contents = {
301+
'definitions' => {
302+
'Thing' => { 'type' => 'object' },
303+
'A' => { 'name' => 'A' },
304+
'array' => [
305+
{ 'object' => { '$ref' => '#/definitions/A' } },
306+
{ 'object' => { 'name' => 'B' } }
307+
]
308+
},
309+
'array' => { '$ref' => '#/definitions/array' }
310+
}
311+
doc = described_class.for(contents)
312+
313+
results = []
314+
doc['array'].each do |node|
315+
results << node['object'].resolved
316+
end
317+
expect(results).to eq([
318+
{ 'name' => 'A' },
319+
{ 'name' => 'B' }
320+
])
321+
end
298322
end
299323
end
300324
end

0 commit comments

Comments
 (0)