Skip to content

Commit

Permalink
feat(rulesets): check servers array at webhook operation level
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylachun committed Jan 23, 2024
1 parent 3c61d56 commit 0f2b9a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/reference/openapi-rules.md
Expand Up @@ -931,13 +931,27 @@ Servers should not be defined in a webhook.

**Bad Example**

At the path item object level:

```yaml
webhooks:
servers:
- url: https://example.com/
- url: https://example.com/api/
```

or

At the operation level:

```yaml
webhooks:
newPet:
post:
servers:
-url: https://example.com/
```

### oas3_1-callbacks-in-webhook

Callbacks should not be defined in a webhook.
Expand Down
Expand Up @@ -8,6 +8,11 @@ testRule('oas3_1-servers-in-webhook', [
openapi: '3.1.0',
webhooks: {
servers: [],
newPet: {
post: {
servers: [],
},
},
},
},
errors: [
Expand All @@ -16,6 +21,11 @@ testRule('oas3_1-servers-in-webhook', [
path: ['webhooks', 'servers'],
severity: DiagnosticSeverity.Warning,
},
{
message: 'Servers should not be defined in a webhook.',
path: ['webhooks', 'newPet', 'post', 'servers'],
severity: DiagnosticSeverity.Warning,
},
],
},
]);
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/index.ts
Expand Up @@ -711,7 +711,7 @@ const ruleset = {
message: 'Servers should not be defined in a webhook.',
formats: [oas3_1],
recommended: true,
given: ['$.webhooks.servers'],
given: ['$.webhooks.servers', '$.webhooks[*][*].servers'],
then: {
function: undefined,
},
Expand Down

0 comments on commit 0f2b9a4

Please sign in to comment.