Skip to content

Commit eb5484c

Browse files
authored
Merge pull request ruby-grape#9 from d-velop/master
Pay heed to the property alias option :as
2 parents b06037c + f4dbc51 commit eb5484c

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

lib/grape-swagger/representable/parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def representer_mapping(representer, documentation, property, is_a_collection =
9999

100100
def parse_representer(representer)
101101
representer.map.each_with_object({}) do |value, property|
102-
property[value.name] = parse_representer_property(value)
102+
property_name = value[:as].try(:call) || value.name
103+
property[property_name] = parse_representer_property(value)
103104
end
104105
end
105106
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module GrapeSwagger
22
module Representable
3-
VERSION = '0.1.5'.freeze
3+
VERSION = '0.1.6'.freeze
44
end
55
end

spec/grape-swagger/representers/response_inline_representer_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Something < Representable::Decorator
2727
include Representable::JSON
2828

2929
property :text, documentation: { type: 'string', desc: 'Content of something.' }
30+
property :original, as: :alias, documentation: { type: 'string', desc: 'Aliased.'}
3031
property :kind, decorator: Kind, documentation: { desc: 'The kind of this something.' }
3132
property :kind2, decorator: Kind, documentation: { desc: 'Secondary kind.' } do
3233
property :name, documentation: { type: String, desc: 'Kind name.' }
@@ -121,6 +122,7 @@ def app
121122
'description' => 'This returns something',
122123
'properties' => {
123124
'text' => { 'description' => 'Content of something.', 'type' => 'string' },
125+
'alias' => { 'description' => 'Aliased.', 'type' => 'string' },
124126
'kind' => { '$ref' => '#/definitions/Kind', 'description' => 'The kind of this something.' },
125127
'kind2' => {
126128
'type' => 'object',

spec/grape-swagger/representers/response_representer_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Something < Representable::Decorator
3333
include Representable::JSON
3434

3535
property :text, documentation: { type: 'string', desc: 'Content of something.' }
36+
property :original, as: :alias, documentation: { type: 'string', desc: 'Aliased.'}
3637
property :kind, decorator: Kind, documentation: { desc: 'The kind of this something.' }
3738
property :kind2, decorator: Kind, documentation: { desc: 'Secondary kind.' }
3839
property :kind3, decorator: ThisApi::Representers::Kind, documentation: { desc: 'Tertiary kind.' }
@@ -121,6 +122,7 @@ def app
121122
'description' => 'This returns something',
122123
'properties' =>
123124
{ 'text' => { 'type' => 'string', 'description' => 'Content of something.' },
125+
'alias' => { 'type' => 'string', 'description' => 'Aliased.' },
124126
'kind' => { '$ref' => '#/definitions/Kind', 'description' => 'The kind of this something.' },
125127
'kind2' => { '$ref' => '#/definitions/Kind', 'description' => 'Secondary kind.' },
126128
'kind3' => { '$ref' => '#/definitions/Kind', 'description' => 'Tertiary kind.' },

0 commit comments

Comments
 (0)