Skip to content

Commit 05e1d8c

Browse files
authored
Hide x-gitbook-* symbols in OpenAPI blocks (#2863)
1 parent 9f0de74 commit 05e1d8c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.changeset/happy-plants-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Hide x-gitbook-\* symbols in OpenAPI blocks

packages/react-openapi/src/OpenAPIResponseExample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { checkIsReference, createStateKey, resolveDescription } from './utils';
55
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
66
import { InteractiveSection } from './InteractiveSection';
77
import { json2xml } from './json2xml';
8+
import { stringifyOpenAPI } from './stringifyOpenAPI';
89

910
/**
1011
* Display an example of the response content.
@@ -226,7 +227,7 @@ function stringifyExample(args: { example: OpenAPIV3.ExampleObject; xml: boolean
226227
return json2xml(example.value);
227228
}
228229

229-
return JSON.stringify(example.value, null, 2);
230+
return stringifyOpenAPI(example.value, null, 2);
230231
}
231232

232233
/**
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
/**
22
* Stringify an OpenAPI object. Same API as JSON.stringify.
33
*/
4-
export function stringifyOpenAPI(body: unknown, transformer?: null, indent?: number): string {
5-
return JSON.stringify(body, transformer, indent);
4+
export function stringifyOpenAPI(body: unknown, _?: null, indent?: number): string {
5+
return JSON.stringify(
6+
body,
7+
(key, value) => {
8+
// Ignore internal keys
9+
if (key.startsWith('x-gitbook-')) {
10+
return undefined;
11+
}
12+
13+
return value;
14+
},
15+
indent,
16+
);
617
}

0 commit comments

Comments
 (0)