|
2 | 2 | require_relative '../../../spec/support/shared_contexts/this_api' |
3 | 3 |
|
4 | 4 | describe GrapeSwagger::Entity::Parser do |
5 | | - include_context 'this api' |
| 5 | + context 'this api' do |
| 6 | + include_context 'this api' |
6 | 7 |
|
7 | | - describe '#call' do |
8 | | - let(:parsed_entity) { described_class.new(ThisApi::Entities::Something, endpoint).call } |
9 | | - let(:properties) { parsed_entity.first } |
10 | | - let(:required) { parsed_entity.last } |
| 8 | + describe '#call' do |
| 9 | + let(:parsed_entity) { described_class.new(ThisApi::Entities::Something, endpoint).call } |
| 10 | + let(:properties) { parsed_entity.first } |
| 11 | + let(:required) { parsed_entity.last } |
11 | 12 |
|
12 | | - context 'when no endpoint is passed' do |
13 | | - let(:endpoint) { nil } |
| 13 | + context 'when no endpoint is passed' do |
| 14 | + let(:endpoint) { nil } |
14 | 15 |
|
15 | | - it 'parses the model with the correct :using definition' do |
16 | | - expect(properties[:kind]['$ref']).to eq('#/definitions/Kind') |
17 | | - expect(properties[:kind2]['$ref']).to eq('#/definitions/Kind') |
18 | | - expect(properties[:kind3]['$ref']).to eq('#/definitions/Kind') |
| 16 | + it 'parses the model with the correct :using definition' do |
| 17 | + expect(properties[:kind]['$ref']).to eq('#/definitions/Kind') |
| 18 | + expect(properties[:kind2]['$ref']).to eq('#/definitions/Kind') |
| 19 | + expect(properties[:kind3]['$ref']).to eq('#/definitions/Kind') |
| 20 | + end |
| 21 | + |
| 22 | + it 'merges attributes that have merge: true defined' do |
| 23 | + expect(properties[:merged_attribute]).to be_nil |
| 24 | + expect(properties[:code][:type]).to eq('string') |
| 25 | + expect(properties[:message][:type]).to eq('string') |
| 26 | + expect(properties[:attr][:type]).to eq('string') |
| 27 | + end |
| 28 | + |
| 29 | + it 'hides hidden attributes' do |
| 30 | + expect(properties).to_not include(:hidden_attr) |
| 31 | + end |
19 | 32 | end |
| 33 | + end |
| 34 | + end |
| 35 | + context 'inheritance api' do |
| 36 | + include_context 'inheritance api' |
20 | 37 |
|
21 | | - it 'merges attributes that have merge: true defined' do |
22 | | - expect(properties[:merged_attribute]).to be_nil |
23 | | - expect(properties[:code][:type]).to eq('string') |
24 | | - expect(properties[:message][:type]).to eq('string') |
25 | | - expect(properties[:attr][:type]).to eq('string') |
| 38 | + describe '#call for Parent' do |
| 39 | + let(:parsed_entity) do |
| 40 | + described_class.new(InheritanceApi::Entities::Parent, endpoint).call |
26 | 41 | end |
| 42 | + let(:properties) { parsed_entity.first } |
| 43 | + |
| 44 | + context 'when no endpoint is passed' do |
| 45 | + let(:endpoint) { nil } |
| 46 | + |
| 47 | + it 'parses the model with discriminator' do |
| 48 | + expect(properties[:type][:documentation]).to eq(is_discriminator: true) |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe '#call for Child' do |
| 54 | + let(:parsed_entity) do |
| 55 | + described_class.new(InheritanceApi::Entities::Child, endpoint).call |
| 56 | + end |
| 57 | + let(:properties) { parsed_entity } |
| 58 | + |
| 59 | + context 'when no endpoint is passed' do |
| 60 | + let(:endpoint) { nil } |
27 | 61 |
|
28 | | - it 'hides hidden attributes' do |
29 | | - expect(properties).to_not include(:hidden_attr) |
| 62 | + it 'parses the model with allOf' do |
| 63 | + expect(properties).to include(:allOf) |
| 64 | + all_of = properties[:allOf] |
| 65 | + child_property = all_of.last.first |
| 66 | + child_required = all_of.last.last |
| 67 | + expect(all_of.first['$ref']).to eq('#/definitions/Parent') |
| 68 | + expect(child_property[:name][:type]).to eq('string') |
| 69 | + expect(child_property[:type][:type]).to eq('string') |
| 70 | + expect(child_property[:type][:enum]).to eq(['Child']) |
| 71 | + expect(child_required).to include(:type) |
| 72 | + end |
30 | 73 | end |
31 | 74 | end |
32 | 75 | end |
|
0 commit comments