Skip to content

Commit 8b25243

Browse files
committed
Update webhook block
1 parent 21812aa commit 8b25243

14 files changed

+278
-65
lines changed

bun.lock

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"name": "@gitbook/cache-tags",
2727
"version": "0.3.1",
2828
"dependencies": {
29-
"@gitbook/api": "^0.109.0",
29+
"@gitbook/api": "^0.110.0",
3030
"assert-never": "^1.2.1",
3131
},
3232
"devDependencies": {
@@ -259,7 +259,7 @@
259259
},
260260
"overrides": {
261261
"@codemirror/state": "6.4.1",
262-
"@gitbook/api": "0.109.0",
262+
"@gitbook/api": "0.110.0",
263263
"react": "18.3.1",
264264
"react-dom": "18.3.1",
265265
},
@@ -620,7 +620,7 @@
620620

621621
"@fortawesome/fontawesome-svg-core": ["@fortawesome/[email protected]", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
622622

623-
"@gitbook/api": ["@gitbook/api@0.109.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-nzhxmiNR2MMHh+HoU7fFdOJ+u4BFyXjtsVquQf3VhZMjeI71yeLx5JEbjkOcijVd/GMAtvpYlYR2qcPqzq27gw=="],
623+
"@gitbook/api": ["@gitbook/api@0.110.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-uv9nOudURynJpLSLj+T9qG2de+skQfi2DRWfLpFB2n2BqMaGBWn6jWXNHijvAP69LnByRdYPCZD0rpPbuxv8aw=="],
624624

625625
"@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"],
626626

@@ -4018,7 +4018,7 @@
40184018

40194019
"gaxios/node-fetch": ["[email protected]", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
40204020

4021-
"gitbook-v2/next": ["[email protected]", "", { "dependencies": { "@next/env": "15.3.1-canary.6", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.1-canary.6", "@next/swc-darwin-x64": "15.3.1-canary.6", "@next/swc-linux-arm64-gnu": "15.3.1-canary.6", "@next/swc-linux-arm64-musl": "15.3.1-canary.6", "@next/swc-linux-x64-gnu": "15.3.1-canary.6", "@next/swc-linux-x64-musl": "15.3.1-canary.6", "@next/swc-win32-arm64-msvc": "15.3.1-canary.6", "@next/swc-win32-x64-msvc": "15.3.1-canary.6", "sharp": "^0.34.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-mw5jVmLEGeDeuRqATKUw/ldoYTqKlz7/Zn8EPaxpOny/yKrpxVCpW8z+ji/jCm8SmyvLYuyn743ll/6tInzCzQ=="],
4021+
"gitbook-v2/next": ["[email protected]", "", { "dependencies": { "@next/env": "15.3.1-canary.8", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.1-canary.8", "@next/swc-darwin-x64": "15.3.1-canary.8", "@next/swc-linux-arm64-gnu": "15.3.1-canary.8", "@next/swc-linux-arm64-musl": "15.3.1-canary.8", "@next/swc-linux-x64-gnu": "15.3.1-canary.8", "@next/swc-linux-x64-musl": "15.3.1-canary.8", "@next/swc-win32-arm64-msvc": "15.3.1-canary.8", "@next/swc-win32-x64-msvc": "15.3.1-canary.8", "sharp": "^0.34.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-Of5a3BTTIl/iUvL2a9Jh7m7G/H8z4Pj5Vs54CLvcdadokxSNgLOpjzbDgFR8J4PawLx6+MOMy19m9Cvr6EPGug=="],
40224022

40234023
"global-dirs/ini": ["[email protected]", "", {}, "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="],
40244024

@@ -4886,23 +4886,23 @@
48864886

48874887
"gaxios/https-proxy-agent/debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ=="],
48884888

4889-
"gitbook-v2/next/@next/env": ["@next/[email protected].6", "", {}, "sha512-RZuPfUpY1Vcc9qFEGgmrl7PlcU+G2e0AZzTGL+amv3y0PXpC6Bp6dNGUSckUAxrzh6j3IQEKSM1cnselxFjCNg=="],
4889+
"gitbook-v2/next/@next/env": ["@next/[email protected].8", "", {}, "sha512-ShZTo0hNhbTRrp7k6oUDSck4Xx4hhfSeLBp35jvGaw1QMZzWYr5v/oc0kEt0bfMdl+833flwKV7kFR3BnrULfg=="],
48904890

4891-
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/[email protected].6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-boVBCyPE9Q8QOkgR/JqBzPqmRnPedvzRZVO8/TU388jdNcB2sGhYSdlLAdn3/j3byyi0ne/YN31OwPq/FYdtMw=="],
4891+
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/[email protected].8", "", { "os": "darwin", "cpu": "arm64" }, "sha512-ZaDynM+pbrnLLlBAxH/CDGp9KN79OFrLcT1ejlWyo86V3SS9Gyqr4nmTuvTevByTTpr1VHReQel8Zbq0Pttu7Q=="],
48924892

4893-
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/[email protected].6", "", { "os": "darwin", "cpu": "x64" }, "sha512-GDiTNrwTB9a6843PBAvKvD7+j6Zvy8PdMQNyF5Q0u58m29s+M9wP2ie0+3wdIdaLX/H2cVKnFGP5fAMzTsAjaw=="],
4893+
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/[email protected].8", "", { "os": "darwin", "cpu": "x64" }, "sha512-BsMR8WqeCDAX8C9RYAO8TI4ttpuqKk2oYMb1+bCrOYi857SMfB4vWD4PWmMvj7mwFXGqrxly4W6CBQlD66A+fg=="],
48944894

4895-
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/[email protected].6", "", { "os": "linux", "cpu": "arm64" }, "sha512-UUQAAe1vrFWsE94vbmCUMQk3YfOvGAlD+mbwFN5vHprgANvaSoL+kMxnF4K/IqjEltuGaNQyP63omyvPoOvXnQ=="],
4895+
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/[email protected].8", "", { "os": "linux", "cpu": "arm64" }, "sha512-xL+K2SW+/46j/KnKNf1gizM1bxwcEaE56eCEG9RPoYS/lfxHLuHcR9O2MlcPI90g/rIN2HXmHeuKRbXbnVy15g=="],
48964896

4897-
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/[email protected].6", "", { "os": "linux", "cpu": "arm64" }, "sha512-jbpLxohCU9VhWBNvIFr2rLDWIqBhmGI4ODSLffqI6dApIc92q+rLYS3YMsu9VWOd1/ivoKpXT1yAWqkfYiJxGQ=="],
4897+
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/[email protected].8", "", { "os": "linux", "cpu": "arm64" }, "sha512-bzXlCUXkjIRsMTb6rr7OsWEQmdO2rZgKijnMGBJzEpa9ROq95VJTF+rdyrLmHuc4fPsAGDn/C18V3E1YOi4ipQ=="],
48984898

4899-
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/[email protected].6", "", { "os": "linux", "cpu": "x64" }, "sha512-0UKu7pOOXi7Kn7rylskI7f4kT57icLnVA2X8y4U1LHs5KOU03uRA9h8ofQgWXgbQigPdBwR1Kn/APmYOyqNWZg=="],
4899+
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/[email protected].8", "", { "os": "linux", "cpu": "x64" }, "sha512-snbPQ9th7eoYYMZpNGhEvX4EbqGjjkiXzTEm2F/oDadlZR2wI6egtfQHiZqeczL7XwG3M66hBJ1/U20wdTDtvA=="],
49004900

4901-
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/[email protected].6", "", { "os": "linux", "cpu": "x64" }, "sha512-FRTdzhAX5uKb6YQ/o4ykWt3vrpfg1PIOaLh8rriA/DDzzTTBEL/JSMc5Xc/DpnbRJhA/OUHMkNW8Y29qjezKhA=="],
4901+
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/[email protected].8", "", { "os": "linux", "cpu": "x64" }, "sha512-5hmcaGazc3w6rg/gbQOrmuw0kKShf4Egs0JlUPop/ZiRDfZO5KlyrGY0hUD+2pLG7Yx3B/fTbj86cHKfQZDMBw=="],
49024902

4903-
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/[email protected].6", "", { "os": "win32", "cpu": "arm64" }, "sha512-SrTGmFwMHagT1CYXTn/xtJFfjuBcYBZNKipmdg8k7mv9ROB5rO47Xeb7tzmbtCL2JQtP2mDg8blIHCfo5HnkwA=="],
4903+
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/[email protected].8", "", { "os": "win32", "cpu": "arm64" }, "sha512-t6uwWC/UbQ8CQGyBVbEmpcJC41yAvz2eZZGec9EoO0ZyQ/fbvjOkqfPnf+WcjWifWNeuiWogjN1UBg7YK9IaVA=="],
49044904

4905-
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/[email protected].6", "", { "os": "win32", "cpu": "x64" }, "sha512-uofQ0olsdSketGLIgTEgXAh9UH4YJK2i1+IJxq+U1H/cqN3yvk9CQ8wrgo9cyKQ1oA/D5IVqzszPGlV9UV8SXQ=="],
4905+
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/[email protected].8", "", { "os": "win32", "cpu": "x64" }, "sha512-93gNqVYwlr9bz6Pm5dQnqjpuOEQyvDre0+H39UqS7h2KuFh3sf2MejhAEr2uFEux4mb7TN0PlohaihO7YxJ3fw=="],
49064906

49074907
"gitbook-v2/next/postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="],
49084908

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@codemirror/state": "6.4.1",
1313
"react": "18.3.1",
1414
"react-dom": "18.3.1",
15-
"@gitbook/api": "0.109.0"
15+
"@gitbook/api": "0.110.0"
1616
},
1717
"private": true,
1818
"scripts": {

packages/cache-tags/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"version": "0.3.1",
1212
"dependencies": {
13-
"@gitbook/api": "^0.109.0",
13+
"@gitbook/api": "^0.110.0",
1414
"assert-never": "^1.2.1"
1515
},
1616
"devDependencies": {

packages/gitbook/src/lib/openapi/resolveOpenAPIWebhookBlock.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export function resolveOpenAPIWebhookBlock(
1919
args: ResolveOpenAPIBlockArgs<OpenAPIWebhookBlock>
2020
): Promise<ResolveOpenAPIWebhookBlockResult> {
2121
if (weakmap.has(args.block)) {
22-
return weakmap.get(args.block)!;
22+
const result = weakmap.get(args.block);
23+
24+
if (result) {
25+
return result;
26+
}
2327
}
2428

2529
const result = baseResolveOpenAPIWebhookBlock(args);
@@ -34,7 +38,7 @@ async function baseResolveOpenAPIWebhookBlock(
3438
args: ResolveOpenAPIBlockArgs<OpenAPIWebhookBlock>
3539
): Promise<ResolveOpenAPIWebhookBlockResult> {
3640
const { context, block } = args;
37-
if (!block.data.path || !block.data.method) {
41+
if (!block.data.name || !block.data.method) {
3842
return { data: null, specUrl: null };
3943
}
4044

packages/gitbook/src/lib/openapi/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
DocumentBlockOpenAPI,
33
DocumentBlockOpenAPIOperation,
44
DocumentBlockOpenAPISchemas,
5-
// DocumentBlockOpenAPIWebhook,
5+
DocumentBlockOpenAPIWebhook,
66
} from '@gitbook/api';
77
import type { Filesystem, OpenAPIParseError, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
88
import type { GitBookAnyContext } from '@v2/lib/context';
@@ -20,7 +20,7 @@ export type OpenAPISchemasBlock = DocumentBlockOpenAPISchemas;
2020
/**
2121
* Type for OpenAPI Webhook block
2222
*/
23-
export type OpenAPIWebhookBlock = any; //DocumentBlockOpenAPIWebhook
23+
export type OpenAPIWebhookBlock = DocumentBlockOpenAPIWebhook;
2424

2525
/**
2626
* Arguments for resolving OpenAPI block.

packages/react-openapi/src/OpenAPICodeSample.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function OpenAPICodeSample(props: {
2222
data: OpenAPIOperationData;
2323
context: OpenAPIContext;
2424
}) {
25-
const { data } = props;
25+
const { data, context } = props;
2626

2727
// If code samples are disabled at operation level, we don't display the code samples.
2828
if (data.operation['x-codeSamples'] === false) {
@@ -43,7 +43,9 @@ export function OpenAPICodeSample(props: {
4343
return null;
4444
}
4545

46-
return <OpenAPICodeSampleBody data={data} items={samples} />;
46+
return (
47+
<OpenAPICodeSampleBody data={data} items={samples} selectIcon={context.icons.chevronDown} />
48+
);
4749
}
4850

4951
/**
@@ -146,6 +148,7 @@ function generateCodeSamples(props: {
146148
method={data.method}
147149
path={data.path}
148150
renderers={renderers}
151+
blockKey={context.blockKey}
149152
/>
150153
),
151154
footer: (
@@ -207,6 +210,7 @@ function OpenAPICodeSampleFooter(props: {
207210
path={data.path}
208211
renderers={renderers}
209212
selectIcon={context.icons.chevronDown}
213+
blockKey={context.blockKey}
210214
/>
211215
) : (
212216
<span />

packages/react-openapi/src/OpenAPICodeSampleInteractive.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
import clsx from 'clsx';
33
import type { MediaTypeRenderer } from './OpenAPICodeSample';
44
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
5+
import { createStateKey } from './utils';
56

67
export function OpenAPIMediaTypeExamplesSelector(props: {
78
method: string;
89
path: string;
910
renderers: MediaTypeRenderer[];
1011
selectIcon?: React.ReactNode;
12+
blockKey?: string;
1113
}) {
12-
const { method, path, renderers, selectIcon } = props;
14+
const { method, path, renderers, selectIcon, blockKey } = props;
1315
if (!renderers[0]) {
1416
throw new Error('No renderers provided');
1517
}
16-
const stateKey = `media-type-${method}-${path}`;
18+
const stateKey = createStateKey('request-body-media-type', blockKey);
1719
const state = useSelectState(stateKey, renderers[0].mediaType);
1820
const selected = renderers.find((r) => r.mediaType === state.key) || renderers[0];
1921

@@ -102,13 +104,17 @@ export function OpenAPIMediaTypeExamplesBody(props: {
102104
method: string;
103105
path: string;
104106
renderers: MediaTypeRenderer[];
107+
blockKey?: string;
105108
}) {
106-
const { renderers, method, path } = props;
109+
const { renderers, method, path, blockKey } = props;
107110
if (!renderers[0]) {
108111
throw new Error('No renderers provided');
109112
}
110113

111-
const mediaTypeState = useSelectState(`media-type-${method}-${path}`, renderers[0].mediaType);
114+
const mediaTypeState = useSelectState(
115+
createStateKey('request-body-media-type', blockKey),
116+
renderers[0].mediaType
117+
);
112118
const selected = renderers.find((r) => r.mediaType === mediaTypeState.key) ?? renderers[0];
113119
if (selected.examples.length === 0) {
114120
return selected.element;

packages/react-openapi/src/OpenAPIRequestBody.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
22
import { InteractiveSection } from './InteractiveSection';
33
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
4-
import type { OpenAPIClientContext, OpenAPIOperationData } from './types';
5-
import { checkIsReference } from './utils';
4+
import type { OpenAPIClientContext, OpenAPIOperationData, OpenAPIWebhookData } from './types';
5+
import { checkIsReference, createStateKey } from './utils';
66

77
/**
88
* Display an interactive request body.
99
*/
1010
export function OpenAPIRequestBody(props: {
1111
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
1212
context: OpenAPIClientContext;
13-
data: OpenAPIOperationData;
13+
data: OpenAPIOperationData | OpenAPIWebhookData;
1414
}) {
1515
const { requestBody, context, data } = props;
16-
const { method, path } = data;
1716

1817
if (checkIsReference(requestBody)) {
1918
return null;
2019
}
2120

21+
const header = 'name' in data ? 'Payload' : 'Body';
22+
2223
return (
2324
<InteractiveSection
24-
header="Body"
25+
header={header}
2526
className="openapi-requestbody"
26-
stateKey={`media-type-${method}-${path}`}
27+
stateKey={createStateKey('request-body-media-type', context.blockKey)}
2728
selectIcon={context.icons.chevronDown}
2829
tabs={Object.entries(requestBody.content ?? {}).map(
2930
([contentType, mediaTypeObject]) => {

packages/react-openapi/src/OpenAPIResponseExample.tsx

+3-18
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import {
88
} from './OpenAPIExample';
99
import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
1010
import { OpenAPIResponseMediaTypeContent } from './OpenAPIResponseMediaType';
11-
import type { OpenAPIContext, OpenAPIOperationData } from './types';
12-
import { getStatusCodeDefaultLabel } from './utils';
11+
import type { OpenAPIContext, OpenAPIOperationData, OpenAPIWebhookData } from './types';
12+
import { getStatusCodeDefaultLabel, getSyntaxFromMediaType } from './utils';
1313
import { checkIsReference, resolveDescription } from './utils';
1414

1515
/**
1616
* Display an example of the response content.
1717
*/
1818
export function OpenAPIResponseExample(props: {
19-
data: OpenAPIOperationData;
19+
data: OpenAPIOperationData | OpenAPIWebhookData;
2020
context: OpenAPIContext;
2121
}) {
2222
const { data, context } = props;
@@ -154,18 +154,3 @@ function getExamples(props: {
154154
};
155155
});
156156
}
157-
158-
/**
159-
* Get the syntax from a media type.
160-
*/
161-
function getSyntaxFromMediaType(mediaType: string): string {
162-
if (mediaType.includes('json')) {
163-
return 'json';
164-
}
165-
166-
if (mediaType === 'application/xml') {
167-
return 'xml';
168-
}
169-
170-
return 'text';
171-
}

packages/react-openapi/src/OpenAPIWebhook.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import clsx from 'clsx';
2-
import { OpenAPIExample, getExampleFromSchema } from './OpenAPIExample';
32
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
43
import { OpenAPISummary } from './common/OpenAPISummary';
54
import type { OpenAPIContext, OpenAPIWebhookData } from './types';
5+
import { OpenAPIWebhookExample } from './webhook/OpenAPIWebhookExample';
66

77
/**
88
* Display an interactive OpenAPI webhook.
@@ -13,7 +13,6 @@ export function OpenAPIWebhook(props: {
1313
context: OpenAPIContext;
1414
}) {
1515
const { className, data, context } = props;
16-
const { operation } = data;
1716

1817
return (
1918
<div className={clsx('openapi-webhook', className)}>
@@ -22,18 +21,7 @@ export function OpenAPIWebhook(props: {
2221
<OpenAPIColumnSpec data={data} context={context} />
2322
<div className="openapi-column-preview">
2423
<div className="openapi-column-preview-body">
25-
<div className="openapi-panel">
26-
<h4 className="openapi-panel-heading">Payload</h4>
27-
<div className="openapi-panel-body">
28-
<OpenAPIExample
29-
example={getExampleFromSchema({
30-
schema: operation.schema,
31-
})}
32-
context={context}
33-
syntax="json"
34-
/>
35-
</div>
36-
</div>
24+
<OpenAPIWebhookExample data={data} context={context} />
3725
</div>
3826
</div>
3927
</div>

packages/react-openapi/src/common/OpenAPISummary.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export function OpenAPISummary(props: {
99
const { data, context } = props;
1010
const { operation } = data;
1111

12+
const title = 'name' in data ? data.name : operation.summary;
13+
1214
return (
1315
<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
1416
{(operation.deprecated || operation['x-stability']) && (
@@ -19,11 +21,11 @@ export function OpenAPISummary(props: {
1921
)}
2022
</div>
2123
)}
22-
{operation.summary
24+
{title
2325
? context.renderHeading({
2426
deprecated: operation.deprecated ?? false,
2527
stability: operation['x-stability'],
26-
title: operation.summary,
28+
title: title,
2729
})
2830
: null}
2931
{'path' in data ? <OpenAPIPath data={data} /> : null}

packages/react-openapi/src/utils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,18 @@ function getStatusCodeCategory(statusCode: number | string): number | string {
211211

212212
return category;
213213
}
214+
215+
/**
216+
* Get the syntax from a media type.
217+
*/
218+
export function getSyntaxFromMediaType(mediaType: string): string {
219+
if (mediaType.includes('json')) {
220+
return 'json';
221+
}
222+
223+
if (mediaType === 'application/xml') {
224+
return 'xml';
225+
}
226+
227+
return 'text';
228+
}

0 commit comments

Comments
 (0)