Hide x-gitbook-* symbols in OpenAPI blocks (#2863)

This commit is contained in:
Nolann B.
2025-02-21 12:38:55 +01:00
committed by GitHub
parent 9f0de74caa
commit 05e1d8cd96
3 changed files with 20 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Hide x-gitbook-\* symbols in OpenAPI blocks
@@ -5,6 +5,7 @@ import { checkIsReference, createStateKey, resolveDescription } from './utils';
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs'; import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
import { InteractiveSection } from './InteractiveSection'; import { InteractiveSection } from './InteractiveSection';
import { json2xml } from './json2xml'; import { json2xml } from './json2xml';
import { stringifyOpenAPI } from './stringifyOpenAPI';
/** /**
* Display an example of the response content. * Display an example of the response content.
@@ -226,7 +227,7 @@ function stringifyExample(args: { example: OpenAPIV3.ExampleObject; xml: boolean
return json2xml(example.value); return json2xml(example.value);
} }
return JSON.stringify(example.value, null, 2); return stringifyOpenAPI(example.value, null, 2);
} }
/** /**
+13 -2
View File
@@ -1,6 +1,17 @@
/** /**
* Stringify an OpenAPI object. Same API as JSON.stringify. * Stringify an OpenAPI object. Same API as JSON.stringify.
*/ */
export function stringifyOpenAPI(body: unknown, transformer?: null, indent?: number): string { export function stringifyOpenAPI(body: unknown, _?: null, indent?: number): string {
return JSON.stringify(body, transformer, indent); return JSON.stringify(
body,
(key, value) => {
// Ignore internal keys
if (key.startsWith('x-gitbook-')) {
return undefined;
}
return value;
},
indent,
);
} }