# operation-tags-defined

Source: https://api-genie.dev/docs/linter/swagger/rules/operation-tags-defined

A rule of the Swagger 2.0 linter, which reads Swagger 2.0 documents; OpenAPI 3 documents go to the OpenAPI linter. Since 0.9.0. In the rulesets: Recommended at warning, Strict at warning, All at error.

This rule checks whether every operation of a Swagger 2.0 document has at
least one tag.

## Rule details

Tags group operations. Documentation tools use them to build sections, and code
generators use them to split generated clients into classes or modules.
Untagged operations usually end up in a catch-all group.

The `operation-tags-defined` rule reports `Operation has no tags defined` for
every operation whose `tags` list is missing or empty.

The OpenAPI linter has a rule of the same name,
[operation-tags-defined](/docs/linter/openapi/rules/operation-tags-defined), for OpenAPI 3.x
documents.

Turn the rule off for small APIs where grouping operations brings no value.

## Examples

**Good**. The operation is tagged.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
tags:
  - name: pets
    description: Operations on pets.
paths:
  /pets:
    get:
      tags: [pets]
      responses:
        '200':
          description: A list of pets.
```

**Bad**. The first operation has no tags, the second has an empty list.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
paths:
  /pets:
    get:
      responses:
        '200':
          description: A list of pets.
    post:
      tags: []
      responses:
        '201':
          description: The pet was added.
```
