Skip to content

Commit 8c20f2b

Browse files
authored
Swagger: Adds option to skip default tags (#881)
* Swagger: Adds option to skip default tags - This option allows the resource tags to be manually specified - Fixes #759 * Fixes rubocop warnings
1 parent a403e2e commit 8c20f2b

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,9 @@ There are several configuration parameters that determine the structure of the g
17301730
See [https://swagger.io/docs/specification/2-0/authentication/] for details of what values can be specified
17311731
By default, no security is defined.
17321732

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

17341737
Known limitations of the current implementation
17351738
-------------------------------------------------

lib/apipie/generator/swagger/config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Config
1010
:json_input_uses_refs, :suppress_warnings, :api_host,
1111
:generate_x_computed_id_field, :allow_additional_properties_in_response,
1212
:responses_use_refs, :schemes, :security_definitions,
13-
:global_security].freeze
13+
:global_security, :skip_default_tags].freeze
1414

1515
attr_accessor(*CONFIG_ATTRIBUTES)
1616

@@ -43,6 +43,7 @@ class Config
4343
alias include_warning_tags? include_warning_tags
4444
alias json_input_uses_refs? json_input_uses_refs
4545
alias responses_use_refs? responses_use_refs
46+
alias skip_default_tags? skip_default_tags
4647
alias generate_x_computed_id_field? generate_x_computed_id_field
4748
alias swagger_include_warning_tags? swagger_include_warning_tags
4849
alias swagger_json_input_uses_refs? swagger_json_input_uses_refs
@@ -61,6 +62,7 @@ def initialize
6162
@schemes = [:https]
6263
@security_definitions = {}
6364
@global_security = []
65+
@skip_default_tags = false
6466
end
6567

6668
def self.deprecated_methods

lib/apipie/generator/swagger/method_description/api_schema_service.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ def summary(api)
4747
end
4848

4949
def tags
50-
[@method_description.resource._id] +
51-
warning_tags +
52-
@method_description.tag_list.tags
50+
tags = if Apipie.configuration.generator.swagger.skip_default_tags?
51+
[]
52+
else
53+
[@method_description.resource._id]
54+
end
55+
tags + warning_tags + @method_description.tag_list.tags
5356
end
5457

5558
def warning_tags

spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@
6464
it { is_expected.to include(*tags) }
6565
end
6666

67+
context 'when Apipie.configuration.generator.swagger.skip_default_tags is enabled' do
68+
before { Apipie.configuration.generator.swagger.skip_default_tags = true }
69+
after { Apipie.configuration.generator.swagger.skip_default_tags = false }
70+
71+
it { is_expected.to be_empty }
72+
73+
context 'when tags are available' do
74+
let(:tags) { ['Tag 1', 'Tag 2'] }
75+
76+
it { is_expected.to eq(tags) }
77+
end
78+
end
79+
6780
context 'when Apipie.configuration.generator.swagger.include_warning_tags is enabled' do
6881
before { Apipie.configuration.generator.swagger.include_warning_tags = true }
6982

0 commit comments

Comments
 (0)