Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug? or Feature?] oneOf with shared properties fails validation #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions spec/data/normal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ paths:
mapping:
obj1: '#/components/schemas/one_of_object1'
obj2: '#/components/schemas/one_of_object2'
one_of_within_properties:
additionalProperties: false
required:
- shared_property
- sample_one_of
properties:
shared_property:
type: string
sample_one_of:
oneOf:
- $ref: '#/components/schemas/one_of_object1'
- $ref: '#/components/schemas/one_of_object2'
one_of_alongside_properties:
additionalProperties: false
required:
- shared_property
properties:
shared_property:
type: string
oneOf:
- $ref: '#/components/schemas/one_of_object1'
- $ref: '#/components/schemas/one_of_object2'
object_1:
type: object
properties:
Expand Down
37 changes: 37 additions & 0 deletions spec/openapi_parser/schema_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,43 @@

it { expect(subject).not_to eq nil }
end

context 'within properties' do
subject { request_operation.validate_request_body(content_type, { 'one_of_within_properties' => params }) }

let(:correct_params) do
{
'shared_property' => 'shared_property',
'name' => 'name',
'integer_1' => 42,
}
end
let(:params) { correct_params }

it { expect(subject).not_to eq nil }
end

context 'alongside properties' do
subject { request_operation.validate_request_body(content_type, { 'one_of_alongside_properties' => params }) }

let(:correct_params) do
{
'shared_property' => 'shared_property',
'name' => 'name',
'integer_1' => 42,
}
end
let(:params) { correct_params }

# TODO: this is failing, but it should not
# it { expect(subject).not_to eq nil }
it do
expect { subject }.to raise_error do |e|
expect(e.kind_of?(OpenAPIParser::NotOneOf)).to eq true
expect(e.message.include?("isn't one of")).to eq true
end
end
end
end

it 'unknown param' do
Expand Down