Skip to content

Commit

Permalink
feat(rulesets): show warning if callbacks defined in a callback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylachun committed Jan 23, 2024
1 parent 0f2b9a4 commit ce17749
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/reference/openapi-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,25 @@ servers:

In this example, both **`{region}`** and **`{version}`** variables are properly defined and used in the server URL. Also, the default value for **`region`** is within the allowed values.

### oas3_callbacks_in_callbacks

A callback should not be defined within another callback.

**Recommended:** Yes

**Bad Example**

```yaml
paths:
/path:
get:
callbacks:
onData:
/data:
post:
callbacks: ...
```

### oas3_1-servers-in-webhook

Servers should not be defined in a webhook.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DiagnosticSeverity } from '@stoplight/types';
import testRule from '../../__tests__/__helpers__/tester';

testRule('oas3-callbacks-in-callbacks', [
{
name: 'callbacks defined within a callback',
document: {
openapi: '3.0.0',
paths: {
'/path': {
get: {
callbacks: {
onData: {
'/data': {
post: {
callbacks: {},
},
},
},
},
},
},
},
},
errors: [
{
message: 'Callbacks should not be defined within a callback',
path: ['paths', '/path', 'get', 'callbacks', 'onData', '/data', 'post', 'callbacks'],
severity: DiagnosticSeverity.Warning,
},
],
},
]);
9 changes: 9 additions & 0 deletions packages/rulesets/src/oas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@ const ruleset = {
},
},
},
'oas3-callbacks-in-callbacks': {
message: 'Callbacks should not be defined within a callback',
formats: [oas3],
recommended: true,
given: ['#OperationObject.callbacks[*][*][*].callbacks'],
then: {
function: undefined,
},
},
'oas3_1-servers-in-webhook': {
message: 'Servers should not be defined in a webhook.',
formats: [oas3_1],
Expand Down

0 comments on commit ce17749

Please sign in to comment.