-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add failing test * Process JSON tree in Symbol until dump * Extract common function
- Loading branch information
Showing
10 changed files
with
128 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class << RSpec::OpenAPI::KeyTransformer = Object.new | ||
def symbolize(value) | ||
case value | ||
when Hash | ||
value.to_h { |k, v| [k.to_sym, symbolize(v)] } | ||
when Array | ||
value.map { |v| symbolize(v) } | ||
else | ||
value | ||
end | ||
end | ||
|
||
def stringify(value) | ||
case value | ||
when Hash | ||
value.to_h { |k, v| [k.to_s, stringify(v)] } | ||
when Array | ||
value.map { |v| stringify(v) } | ||
else | ||
value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'schema merger spec' do | ||
include SpecHelper | ||
|
||
describe 'mixed symbol and strings' do | ||
let(:base) do | ||
{ | ||
'n' => 1, | ||
'required' => %w[foo bar], | ||
'a' => { | ||
b1: 1, | ||
b2: %w[foo bar], | ||
'b3' => { | ||
'c1' => 2, | ||
c2: 3, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
let(:spec) do | ||
{ | ||
n: 1, | ||
required: ['buz'], | ||
a: { | ||
'b1' => 1, | ||
'b2' => %w[foo bar], | ||
b3: { | ||
c1: 2, | ||
'c2' => 3, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
it 'normalize keys to symbol' do | ||
result = RSpec::OpenAPI::SchemaMerger.merge!(base, spec) | ||
expect(result).to eq({ | ||
n: 1, | ||
required: [], | ||
a: { | ||
b1: 1, | ||
b2: %w[foo bar], | ||
b3: { | ||
c1: 2, | ||
c2: 3, | ||
}, | ||
}, | ||
}) | ||
end | ||
end | ||
end |