diff --git a/.changeset/short-onions-live.md b/.changeset/short-onions-live.md new file mode 100644 index 000000000..062a7f1b0 --- /dev/null +++ b/.changeset/short-onions-live.md @@ -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. diff --git a/__tests__/miscellaneous/resolve-refs-in-preprocessors/snapshot.js b/__tests__/miscellaneous/resolve-refs-in-preprocessors/snapshot.js index fa5f783b7..0f59cd177 100644 --- a/__tests__/miscellaneous/resolve-refs-in-preprocessors/snapshot.js +++ b/__tests__/miscellaneous/resolve-refs-in-preprocessors/snapshot.js @@ -92,6 +92,7 @@ Document: openapi.yaml stats: 👉 Parameters: 0 🔗 Links: 0 🔀 Path Items: 2 +🎣 Webhooks: 0 👷 Operations: 2 🔖 Tags: 0 diff --git a/__tests__/stats/stats-json/snapshot.js b/__tests__/stats/stats-json/snapshot.js index b493d527f..660905d7f 100644 --- a/__tests__/stats/stats-json/snapshot.js +++ b/__tests__/stats/stats-json/snapshot.js @@ -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 diff --git a/__tests__/stats/stats-markdown/snapshot.js b/__tests__/stats/stats-markdown/snapshot.js index 22401f87d..c98c9e4ab 100644 --- a/__tests__/stats/stats-markdown/snapshot.js +++ b/__tests__/stats/stats-markdown/snapshot.js @@ -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 | diff --git a/__tests__/stats/stats-stylish/snapshot.js b/__tests__/stats/stats-stylish/snapshot.js index 418a3991e..4c617c363 100644 --- a/__tests__/stats/stats-stylish/snapshot.js +++ b/__tests__/stats/stats-stylish/snapshot.js @@ -10,6 +10,7 @@ Document: museum.yaml stats: 👉 Parameters: 6 🔗 Links: 0 🔀 Path Items: 5 +🎣 Webhooks: 0 👷 Operations: 8 🔖 Tags: 3 diff --git a/packages/cli/src/commands/stats.ts b/packages/cli/src/commands/stats.ts index 4022ed28a..1ade7b74a 100755 --- a/packages/cli/src/commands/stats.ts +++ b/packages/cli/src/commands/stats.ts @@ -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() }, }; diff --git a/packages/core/src/rules/other/stats.ts b/packages/core/src/rules/other/stats.ts index 81a0a524c..3ba9a152c 100644 --- a/packages/core/src/rules/other/stats.ts +++ b/packages/core/src/rules/other/stats.ts @@ -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); + }); }, }, }, diff --git a/packages/core/src/typings/common.ts b/packages/core/src/typings/common.ts index f65569b0b..9ca840b4c 100644 --- a/packages/core/src/typings/common.ts +++ b/packages/core/src/typings/common.ts @@ -13,5 +13,6 @@ export type StatsName = | 'pathItems' | 'links' | 'schemas' + | 'webhooks' | 'parameters'; export type StatsAccumulator = Record;