* Format the example of a schema.
(example: unknown)
| 126 | * Format the example of a schema. |
| 127 | */ |
| 128 | function formatExample(example: unknown): string { |
| 129 | if (typeof example === 'string') { |
| 130 | return example |
| 131 | .replace(/\n/g, ' ') // Replace newlines with spaces |
| 132 | .replace(/\s+/g, ' ') // Collapse multiple spaces/newlines into a single space |
| 133 | .replace(/([\{\}:,])\s+/g, '$1 ') // Ensure a space after {, }, :, and , |
| 134 | .replace(/\s+([\{\}:,])/g, ' $1') // Ensure a space before {, }, :, and , |
| 135 | .trim(); |
| 136 | } |
| 137 | |
| 138 | return stringifyOpenAPI(example); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Check if an example should be displayed. |
no test coverage detected