Skip to content

Commit c67967a

Browse files
authored
Merge pull request #48 from MaximeRDY/features/add_extension_to_entity
Add Extension for model Entity
2 parents 7bdc730 + 2cb9471 commit c67967a

6 files changed

Lines changed: 17 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
/pkg/
88
/spec/reports/
99
/tmp/
10+
.ruby-gemset
11+
.ruby-version

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#48](https://github.com/ruby-grape/grape-swagger-entity/pull/48): Add support for extensions - [@MaximeRDY](https://github.com/MaximeRDY).
67

78
#### Fixes
89

lib/grape-swagger/entity/attribute_parser.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def call(entity_options)
3838

3939
add_attribute_documentation(param, documentation)
4040

41+
add_extension_documentation(param, documentation)
42+
4143
param
4244
end
4345
end
@@ -122,6 +124,10 @@ def add_array_documentation(param, documentation)
122124
param[:maxItems] = documentation[:max_items] if documentation.key?(:max_items)
123125
param[:uniqueItems] = documentation[:unique_items] if documentation.key?(:unique_items)
124126
end
127+
128+
def add_extension_documentation(param, documentation)
129+
GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(documentation, param)
130+
end
125131
end
126132
end
127133
end

spec/grape-swagger/entities/response_model_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def app
6565

6666
expect(subject['definitions'].keys).to include 'ThisApi::Entities::Kind'
6767
expect(subject['definitions']['ThisApi::Entities::Kind']).to eq(
68-
'type' => 'object', 'properties' => { 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' } }
68+
'type' => 'object', 'properties' => { 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' }, 'content' => { 'description' => 'Content', 'type' => 'string', 'x-some' => 'stuff' } }
6969
)
7070

7171
expect(subject['definitions'].keys).to include 'ThisApi::Entities::Relation'

spec/grape-swagger/entity/attribute_parser_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060

6161
it { is_expected.to include(maxLength: 1) }
6262
end
63+
64+
context 'when it contains extensions' do
65+
let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', x: { some: 'stuff' } } } }
66+
67+
it { is_expected.to include('x-some' => 'stuff') }
68+
end
6369
end
6470

6571
context 'when it is exposed as an array' do

spec/support/shared_contexts/this_api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module ThisApi
44
module Entities
55
class Kind < Grape::Entity
66
expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
7+
expose :content, documentation: { type: 'string', desc: 'Content', x: { some: 'stuff' } }
78
end
89

910
class Relation < Grape::Entity

0 commit comments

Comments
 (0)