(object: AnyObject)
| 58 | * Resolve the first example from an object. |
| 59 | */ |
| 60 | export 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. |
no test coverage detected