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

Function resolveFirstExample

packages/react-openapi/src/utils.ts:60–80  ·  view source on GitHub ↗
(object: AnyObject)

Source from the content-addressed store, hash-verified

58 * Resolve the first example from an object.
59 */
60export function resolveFirstExample(object: AnyObject): string | undefined {
61 if ('examples' in object && typeof object.examples === 'object' && object.examples) {
62 const keys = Object.keys(object.examples);
63 const firstKey = keys[0];
64 if (firstKey && object.examples[firstKey]) {
65 return formatExample(object.examples[firstKey]);
66 }
67 }
68
69 // Resolve top level example first
70 if (shouldDisplayExample(object)) {
71 return formatExample(object.example);
72 }
73
74 // Resolve example from items if it exists
75 if (object.items && typeof object.items === 'object') {
76 return formatExample(object.items.example);
77 }
78
79 return undefined;
80}
81
82/**
83 * Resolve the schema of a parameter.

Callers 2

resolveParameterSchemaFunction · 0.85

Calls 2

formatExampleFunction · 0.85
shouldDisplayExampleFunction · 0.85

Tested by

no test coverage detected