Skip to content

Commit 68e27ff

Browse files
enrique-guilleniNecas
authored andcommitted
Fix swagger generation if a controller's parent doesn't define a resource_description
1 parent e69e025 commit 68e27ff

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ Example:
283283
property :enum1, ['v1', 'v2'], :desc => "One of 2 possible string values"
284284
end
285285
end
286+
tags %w[profiles logins]
287+
tags 'more', 'related', 'resources'
286288
description "method description"
287289
formats ['json', 'jsonp', 'xml']
288290
meta :message => "Some very important info"

lib/apipie/method_description.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def tag_list
101101
parent = Apipie.get_resource_description(@resource.controller.superclass)
102102

103103
# get tags from parent resource description
104-
parent_tags = [parent, @resource].flat_map { |resource| resource._tag_list_arg }
104+
parent_tags = [parent, @resource].compact.flat_map { |resource| resource._tag_list_arg }
105105
Apipie::TagListDescription.new((parent_tags + @tag_list).uniq.compact)
106106
end
107107

spec/dummy/app/controllers/tagged_cats_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# defining a set of tags for the contained methods to include.
44
#
55

6-
class TaggedCatsController < ApplicationController
6+
class TaggedCatsController < ActionController::Base
77
resource_description do
88
description 'A controller to test "returns"'
99
short 'Pets'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# The TagsController defined here provides an example of a
3+
# tags call without a resource description.
4+
#
5+
6+
class TaggedDogsController < ActionController::Base
7+
#-----------------------------------------------------------
8+
# simple 'returns' example: a method that returns a cat record
9+
#-----------------------------------------------------------
10+
api :GET, "/pets/:id/as_properties", "Get a dog record"
11+
tags(%w[Dogs Wolves])
12+
def show_as_properties
13+
render :plain => "showing pet properties"
14+
end
15+
end

spec/lib/swagger/swagger_dsl_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,27 @@ def have_field?(field, expected_name, breadcrumb)
448448

449449
end
450450

451+
#==============================================================================
452+
# TaggedDogsController is a demonstration of how tags may be defined in a simple
453+
# controller class without defining either the controller resource-description
454+
# block or the controller's superclass's resource-description block.
455+
#==============================================================================
456+
457+
describe TaggedDogsController do
458+
describe "TaggedDogsController#show_as_properties" do
459+
subject do
460+
desc._methods[:show_as_properties]
461+
end
462+
463+
it "should return tags with 'Dogs', and 'Wolves'" do
464+
returns_obj = subject.tag_list
465+
puts returns_obj.inspect
466+
467+
expect(returns_obj.tags).to eq(%w[Dogs Wolves])
468+
end
469+
end
470+
end
471+
451472
#==============================================================================
452473
# TaggedCatsController is a demonstration of how tags may be defined in the
453474
# controller's resource description so that they may be automatically prefixed

0 commit comments

Comments
 (0)