Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger: Adds option to skip default tags #881

Merged
merged 2 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be called skip_default_resource_tag since it still allows warning_tags? (Which has a separate config)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken swagger tags are only used in endpoints so I guess it's ok to leave it as is, fine by me either way.

[]
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