From 95014fcc4d14412d4ddacf92eb620e0b9594179e Mon Sep 17 00:00:00 2001 From: tomo-kn Date: Mon, 9 Oct 2023 21:07:09 +0900 Subject: [PATCH] test: within properties and alongside properties spec --- spec/data/normal.yml | 22 ++++++++++++ spec/openapi_parser/schema_validator_spec.rb | 37 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/spec/data/normal.yml b/spec/data/normal.yml index 66d1437..961a814 100644 --- a/spec/data/normal.yml +++ b/spec/data/normal.yml @@ -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: diff --git a/spec/openapi_parser/schema_validator_spec.rb b/spec/openapi_parser/schema_validator_spec.rb index c712e1f..368ad39 100644 --- a/spec/openapi_parser/schema_validator_spec.rb +++ b/spec/openapi_parser/schema_validator_spec.rb @@ -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