mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-07 12:47:49 +00:00
83 lines
2.0 KiB
Markdown
83 lines
2.0 KiB
Markdown
---
|
|
slug: /docs/cli/rules/operation-operationId-unique
|
|
---
|
|
|
|
# operation-operationId-unique
|
|
|
|
Requires unique `operationId` values for each operation.
|
|
|
|
| OAS | Compatibility |
|
|
| --- | ------------- |
|
|
| 2.0 | ✅ |
|
|
| 3.0 | ✅ |
|
|
| 3.1 | ✅ |
|
|
|
|
## API design principle
|
|
|
|
The `operationId` is used by tooling to identify operations (which are otherwise done through scary looking JSON pointers).
|
|
|
|
The `operationId` should be unique (used only once in an OpenAPI description).
|
|
|
|
This rule is unopinionated.
|
|
|
|
## Configuration
|
|
|
|
| Option | Type | Description |
|
|
| -------- | ------ | ------------------------------------------------------------------------------------------ |
|
|
| severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). |
|
|
|
|
An example configuration:
|
|
|
|
```yaml
|
|
rules:
|
|
operation-operationId-unique: error
|
|
```
|
|
|
|
## Examples
|
|
|
|
Given this configuration:
|
|
|
|
```yaml
|
|
rules:
|
|
operation-operationId-unique: error
|
|
```
|
|
|
|
Example of **incorrect** operations:
|
|
|
|
```yaml
|
|
paths:
|
|
/cars:
|
|
get:
|
|
operationId: Car
|
|
# ...
|
|
post:
|
|
operationId: Car
|
|
# ...
|
|
```
|
|
|
|
Example of **correct** operations:
|
|
|
|
```yaml
|
|
paths:
|
|
/cars:
|
|
get:
|
|
operationId: getCar
|
|
# ...
|
|
post:
|
|
operationId: postCar
|
|
# ...
|
|
```
|
|
|
|
## Related rules
|
|
|
|
- [operation-summary](./operation-summary.md)
|
|
- [operation-operationId-url-safe](./operation-operationId-url-safe.md)
|
|
- [operation-operationId](./operation-operationId.md)
|
|
- [configurable rules](./configurable-rules.md)
|
|
|
|
## Resources
|
|
|
|
- [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/common/operation-operationId-unique.ts)
|
|
- [Operation object docs](https://redocly.com/docs/openapi-visual-reference/operation/)
|
|
- Consider using [configurable rules](./configurable-rules.md) for more specific rules for `operationId`s such as length, casing, and pattern enforcement.
|