Skip to content

Commit

Permalink
Swagger: Adds option to skip default tags
Browse files Browse the repository at this point in the history
- This option allows the resource tags to be manually specified
- Fixes #759
  • Loading branch information
davidwessman committed Jun 3, 2023
1 parent a403e2e commit 5de619a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,9 @@ There are several configuration parameters that determine the structure of the g
See [https://swagger.io/docs/specification/2-0/authentication/] for details of what values can be specified
By default, no security is defined.

``config.generator.swagger.skip_default_tags``
By setting ``false`` (default): The resource name for e.g. ``/pets/{petId}`` will automatically be added as a tag ``pets``.
By setting ``true``: The tags needs to be explicitly added to the resource using the DSL.

Known limitations of the current implementation
-------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion lib/apipie/generator/swagger/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config
:json_input_uses_refs, :suppress_warnings, :api_host,
:generate_x_computed_id_field, :allow_additional_properties_in_response,
:responses_use_refs, :schemes, :security_definitions,
:global_security].freeze
:global_security, :skip_default_tags].freeze

attr_accessor(*CONFIG_ATTRIBUTES)

Expand Down Expand Up @@ -43,6 +43,7 @@ class Config
alias include_warning_tags? include_warning_tags
alias json_input_uses_refs? json_input_uses_refs
alias responses_use_refs? responses_use_refs
alias skip_default_tags? skip_default_tags
alias generate_x_computed_id_field? generate_x_computed_id_field
alias swagger_include_warning_tags? swagger_include_warning_tags
alias swagger_json_input_uses_refs? swagger_json_input_uses_refs
Expand All @@ -61,6 +62,7 @@ def initialize
@schemes = [:https]
@security_definitions = {}
@global_security = []
@skip_default_tags = false
end

def self.deprecated_methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ def summary(api)
end

def tags
[@method_description.resource._id] +
warning_tags +
@method_description.tag_list.tags
tags = if Apipie.configuration.generator.swagger.skip_default_tags?
[]
else
[@method_description.resource._id]
end
tags + warning_tags + @method_description.tag_list.tags
end

def warning_tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
it { is_expected.to include(*tags) }
end

context "when Apipie.configuration.generator.swagger.skip_default_tags is enabled" do
before { Apipie.configuration.generator.swagger.skip_default_tags = true }
after { Apipie.configuration.generator.swagger.skip_default_tags = false }

it { is_expected.to be_empty }

context "when tags are available" do
let(:tags) { ["Tag 1", "Tag 2"] }

it { is_expected.to eq(tags) }
end
end

context 'when Apipie.configuration.generator.swagger.include_warning_tags is enabled' do
before { Apipie.configuration.generator.swagger.include_warning_tags = true }

Expand Down

0 comments on commit 5de619a

Please sign in to comment.