fix: add webhooks to stats and fix crash for webhooks tags (#1663)

* 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 <adam@redocly.com>

---------

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
Co-authored-by: Adam Altman <adam@redocly.com>
This commit is contained in:
Roman Hotsiy
2024-08-14 21:19:27 +08:00
committed by GitHub
parent d0fc69c2bb
commit d6580ea9b6
8 changed files with 19 additions and 3 deletions

View File

@@ -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.

View File

@@ -92,6 +92,7 @@ Document: openapi.yaml stats:
👉 Parameters: 0
🔗 Links: 0
🔀 Path Items: 2
🎣 Webhooks: 0
👷 Operations: 2
🔖 Tags: 0

View File

@@ -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

View File

@@ -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 |

View File

@@ -10,6 +10,7 @@ Document: museum.yaml stats:
👉 Parameters: 6
🔗 Links: 0
🔀 Path Items: 5
🎣 Webhooks: 0
👷 Operations: 8
🔖 Tags: 3

View File

@@ -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() },
};

View File

@@ -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);
});
},
},
},

View File

@@ -13,5 +13,6 @@ export type StatsName =
| 'pathItems'
| 'links'
| 'schemas'
| 'webhooks'
| 'parameters';
export type StatsAccumulator = Record<StatsName, StatsRow>;