Skip to content

Commit a55ea13

Browse files
committed
Fix OpenapiFirst.load when MultiJson is configured to return symol keys
1 parent c727a15 commit a55ea13

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

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

33
## Unreleased
44

5+
- Fix OpenapiFirst.load when MultiJson is configured to return symbol keys
6+
57
## 2.9.2
68

79
- OpenapiFirst::Test reports all non-covered requests now

lib/openapi_first/file_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def load(file_path)
1313

1414
body = File.read(file_path)
1515
extname = File.extname(file_path)
16-
return JSON.parse(body) if extname == '.json'
16+
return ::JSON.parse(body) if extname == '.json'
1717
return YAML.unsafe_load(body) if ['.yaml', '.yml'].include?(extname)
1818

1919
body

spec/file_loader_spec.rb

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

33
RSpec.describe OpenapiFirst::FileLoader do
44
describe '.load' do
5-
it 'loads .json' do
6-
contents = described_class.load('./spec/data/petstore.json')
7-
expect(contents['openapi']).to eq('3.0.0')
5+
begin
6+
require 'multi_json'
7+
before do
8+
MultiJson.load_options = { symbolize_keys: true }
9+
end
10+
11+
after do
12+
MultiJson.load_options = { symbolize_keys: false }
13+
end
14+
rescue LoadError # rubocop:disable Lint/SuppressedException
815
end
916

1017
it 'loads .yaml' do
@@ -17,6 +24,11 @@
1724
expect(contents['openapi']).to eq('3.0.0')
1825
end
1926

27+
it 'loads .json' do
28+
contents = described_class.load('./spec/data/petstore.json')
29+
expect(contents['openapi']).to eq('3.0.0')
30+
end
31+
2032
it 'raises FileNotFoundError if file was not found' do
2133
expect { described_class.load('./spec/data/unknown.yaml') }.to raise_error(OpenapiFirst::FileNotFoundError, 'File not found "./spec/data/unknown.yaml"')
2234
end

0 commit comments

Comments
 (0)