Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: Webhook Example
version: 1.0.0
paths: {}
webhooks:
order.created:
post:
requestBody:
description: example body
content:
application/json:
schema:
type: object
responses:
"200":
description: OK
10 changes: 9 additions & 1 deletion packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,19 @@ function createItems(
for (let [path, pathObject] of Object.entries(
openapiData["x-webhooks"] ?? openapiData["webhooks"] ?? {}
)) {
const eventName = path;
path = "webhook";
const { $ref, description, parameters, servers, summary, ...rest } =
pathObject;
for (let [method, operationObject] of Object.entries({ ...rest })) {
method = "event";
if (
operationObject.summary === undefined &&
operationObject.operationId === undefined
) {
operationObject.summary = eventName;
}

const title =
operationObject.summary ??
operationObject.operationId ??
Expand All @@ -290,7 +298,7 @@ function createItems(

const baseId = operationObject.operationId
? kebabCase(operationObject.operationId)
: kebabCase(operationObject.summary);
: kebabCase(operationObject.summary ?? eventName);

const extensions = [];
const commonExtensions = ["x-codeSamples"];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import path from "path";

// eslint-disable-next-line import/no-extraneous-dependencies
import { posixPath } from "@docusaurus/utils";

import { readOpenapiFiles, processOpenapiFiles } from ".";

describe("webhooks", () => {
it("uses event name when summary and operationId are missing", async () => {
const files = await readOpenapiFiles(
posixPath(path.join(__dirname, "__fixtures__/webhook/openapi.yaml"))
);

const [items] = await processOpenapiFiles(
files,
{ specPath: "", outputDir: "" } as any,
{}
);

const webhookItem = items.find((item) => item.type === "api");
expect(webhookItem?.id).toBe("order-created");
});
});