Skip to content

Commit

Permalink
Fix swagger generation if a controller's parent doesn't define a reso…
Browse files Browse the repository at this point in the history
…urce_description
  • Loading branch information
enrique-guillen authored and iNecas committed Oct 19, 2018
1 parent e69e025 commit 68e27ff
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ Example:
property :enum1, ['v1', 'v2'], :desc => "One of 2 possible string values"
end
end
tags %w[profiles logins]
tags 'more', 'related', 'resources'
description "method description"
formats ['json', 'jsonp', 'xml']
meta :message => "Some very important info"
Expand Down
2 changes: 1 addition & 1 deletion lib/apipie/method_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def tag_list
parent = Apipie.get_resource_description(@resource.controller.superclass)

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

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/controllers/tagged_cats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# defining a set of tags for the contained methods to include.
#

class TaggedCatsController < ApplicationController
class TaggedCatsController < ActionController::Base
resource_description do
description 'A controller to test "returns"'
short 'Pets'
Expand Down
15 changes: 15 additions & 0 deletions spec/dummy/app/controllers/tagged_dogs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# The TagsController defined here provides an example of a
# tags call without a resource description.
#

class TaggedDogsController < ActionController::Base
#-----------------------------------------------------------
# simple 'returns' example: a method that returns a cat record
#-----------------------------------------------------------
api :GET, "/pets/:id/as_properties", "Get a dog record"
tags(%w[Dogs Wolves])
def show_as_properties
render :plain => "showing pet properties"
end
end
21 changes: 21 additions & 0 deletions spec/lib/swagger/swagger_dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,27 @@ def have_field?(field, expected_name, breadcrumb)

end

#==============================================================================
# TaggedDogsController is a demonstration of how tags may be defined in a simple
# controller class without defining either the controller resource-description
# block or the controller's superclass's resource-description block.
#==============================================================================

describe TaggedDogsController do
describe "TaggedDogsController#show_as_properties" do
subject do
desc._methods[:show_as_properties]
end

it "should return tags with 'Dogs', and 'Wolves'" do
returns_obj = subject.tag_list
puts returns_obj.inspect

expect(returns_obj.tags).to eq(%w[Dogs Wolves])
end
end
end

#==============================================================================
# TaggedCatsController is a demonstration of how tags may be defined in the
# controller's resource description so that they may be automatically prefixed
Expand Down

0 comments on commit 68e27ff

Please sign in to comment.