Skip to content

Commit d056235

Browse files
authored
fix(webhooks): use event name when summary missing (#1193)
1 parent 6253f5a commit d056235

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Webhook Example
4+
version: 1.0.0
5+
paths: {}
6+
webhooks:
7+
order.created:
8+
post:
9+
requestBody:
10+
description: example body
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
responses:
16+
"200":
17+
description: OK

packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,19 @@ function createItems(
274274
for (let [path, pathObject] of Object.entries(
275275
openapiData["x-webhooks"] ?? openapiData["webhooks"] ?? {}
276276
)) {
277+
const eventName = path;
277278
path = "webhook";
278279
const { $ref, description, parameters, servers, summary, ...rest } =
279280
pathObject;
280281
for (let [method, operationObject] of Object.entries({ ...rest })) {
281282
method = "event";
283+
if (
284+
operationObject.summary === undefined &&
285+
operationObject.operationId === undefined
286+
) {
287+
operationObject.summary = eventName;
288+
}
289+
282290
const title =
283291
operationObject.summary ??
284292
operationObject.operationId ??
@@ -290,7 +298,7 @@ function createItems(
290298

291299
const baseId = operationObject.operationId
292300
? kebabCase(operationObject.operationId)
293-
: kebabCase(operationObject.summary);
301+
: kebabCase(operationObject.summary ?? eventName);
294302

295303
const extensions = [];
296304
const commonExtensions = ["x-codeSamples"];
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* ============================================================================
2+
* Copyright (c) Palo Alto Networks
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
import path from "path";
9+
10+
// eslint-disable-next-line import/no-extraneous-dependencies
11+
import { posixPath } from "@docusaurus/utils";
12+
13+
import { readOpenapiFiles, processOpenapiFiles } from ".";
14+
15+
describe("webhooks", () => {
16+
it("uses event name when summary and operationId are missing", async () => {
17+
const files = await readOpenapiFiles(
18+
posixPath(path.join(__dirname, "__fixtures__/webhook/openapi.yaml"))
19+
);
20+
21+
const [items] = await processOpenapiFiles(
22+
files,
23+
{ specPath: "", outputDir: "" } as any,
24+
{}
25+
);
26+
27+
const webhookItem = items.find((item) => item.type === "api");
28+
expect(webhookItem?.id).toBe("order-created");
29+
});
30+
});

0 commit comments

Comments
 (0)