Skip to content

Commit

Permalink
fix: add webhooks to stats and fix crash for webhooks tags (#1663)
Browse files Browse the repository at this point in the history
* fix: add webhooks to stats and fix crash for webhooks tags

* chore: add changeset

* Update packages/cli/src/wrapper.ts

* Update .changeset/short-onions-live.md

* update snapshots

* Update .changeset/short-onions-live.md

Co-authored-by: Adam Altman <[email protected]>

---------

Co-authored-by: Andrew Tatomyr <[email protected]>
Co-authored-by: Adam Altman <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent d0fc69c commit d6580ea
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-onions-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/cli": patch
---

Added support for webhooks in stats and fixed a crash that occurred when tags were not included in webhooks.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Document: openapi.yaml stats:
👉 Parameters: 0
🔗 Links: 0
🔀 Path Items: 2
🎣 Webhooks: 0
👷 Operations: 2
🔖 Tags: 0
Expand Down
4 changes: 4 additions & 0 deletions __tests__/stats/stats-json/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ exports[`E2E stats stats should produce correct JSON output 1`] = `
"metric": "🔀 Path Items",
"total": 5
},
"webhooks": {
"metric": "🎣 Webhooks",
"total": 0
},
"operations": {
"metric": "👷 Operations",
"total": 8
Expand Down
1 change: 1 addition & 0 deletions __tests__/stats/stats-markdown/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`E2E stats stats should produce correct Markdown format 1`] = `
| 👉 Parameters | 6 |
| 🔗 Links | 0 |
| 🔀 Path Items | 5 |
| 🎣 Webhooks | 0 |
| 👷 Operations | 8 |
| 🔖 Tags | 3 |
Expand Down
1 change: 1 addition & 0 deletions __tests__/stats/stats-stylish/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Document: museum.yaml stats:
👉 Parameters: 6
🔗 Links: 0
🔀 Path Items: 5
🎣 Webhooks: 0
👷 Operations: 8
🔖 Tags: 3
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const statsAccumulator: StatsAccumulator = {
parameters: { metric: '👉 Parameters', total: 0, color: 'yellow', items: new Set() },
links: { metric: '🔗 Links', total: 0, color: 'cyan', items: new Set() },
pathItems: { metric: '🔀 Path Items', total: 0, color: 'green' },
webhooks: { metric: '🎣 Webhooks', total: 0, color: 'green' },
operations: { metric: '👷 Operations', total: 0, color: 'yellow' },
tags: { metric: '🔖 Tags', total: 0, color: 'white', items: new Set() },
};
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/rules/other/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export const Stats = (statsAccumulator: StatsAccumulator) => {
WebhooksMap: {
Operation: {
leave(operation: any) {
operation.tags.forEach((tag: string) => {
statsAccumulator.tags.items!.add(tag);
});
statsAccumulator.webhooks.total++;
operation.tags &&
operation.tags.forEach((tag: string) => {
statsAccumulator.tags.items!.add(tag);
});
},
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/typings/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export type StatsName =
| 'pathItems'
| 'links'
| 'schemas'
| 'webhooks'
| 'parameters';
export type StatsAccumulator = Record<StatsName, StatsRow>;

1 comment on commit d6580ea

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.49% 4664/6019
🟡 Branches 65.94% 1938/2939
🟡 Functions 71.38% 763/1069
🟡 Lines 77.7% 4401/5664

Test suite run success

759 tests passing in 107 suites.

Report generated by 🧪jest coverage report action from d6580ea

Please sign in to comment.