# license-defined

Source: https://apigenie.pl/docs/linter/swagger/rules/license-defined

This rule checks whether the licensing information is present in a Swagger
2.0 document.

## Rule Details

The `license-defined` rule ensures that the `info.license` object is defined,
and that both its `name` and its `url` are provided. The license specifies the
terms under which the API can be used, and helps consumers of the API to
understand any restrictions that apply.

The rule reports:

- `License object is missing` when there is no `info.license` object,
- `License name is empty` when `name` is empty,
- `License URL is missing or empty` when `url` is missing or empty.

Swagger 2.0 license objects have no SPDX `identifier` field (it was added in
OpenAPI 3.1), so the rule always requires a URL.

## Configuration

None.

## Examples

**Good**. The document links to its license, which makes it easier to
understand how the API can be used.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
paths: {}
```

**Bad**. The license has a name, but no link to its terms.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
  license:
    name: Proprietary
paths: {}
```

## When Not to Use It

You may skip licensing information for team-level APIs.

## Compatibility

This rule is compatible with Swagger 2.0 documents. OpenAPI 3.x and AsyncAPI
documents are linted by the OpenAPI and AsyncAPI linters, which have their own
`license-defined` rules.
