MCPcopy
hub / github.com/GitbookIO/gitbook / stringifyExample

Function stringifyExample

packages/react-openapi/src/OpenAPIExample.tsx:27–49  ·  view source on GitHub ↗
(args: { example: OpenAPIV3.ExampleObject; syntax: string })

Source from the content-addressed store, hash-verified

25}
26
27function stringifyExample(args: { example: OpenAPIV3.ExampleObject; syntax: string }):
28 | string
29 | null {
30 const { example, syntax } = args;
31
32 if (!example.value) {
33 return null;
34 }
35
36 if (typeof example.value === 'string') {
37 return example.value;
38 }
39
40 if (syntax === 'xml') {
41 return json2xml(example.value);
42 }
43
44 if (syntax === 'yaml') {
45 return yaml.dump(example.value).replace(/'/g, '').replace(/\\n/g, '\n');
46 }
47
48 return stringifyOpenAPI(example.value, null, 2);
49}
50
51/**
52 * Empty response example.

Callers 1

OpenAPIExampleFunction · 0.85

Calls 2

json2xmlFunction · 0.90
stringifyOpenAPIFunction · 0.90

Tested by

no test coverage detected