(args: { example: OpenAPIV3.ExampleObject; syntax: string })
| 25 | } |
| 26 | |
| 27 | function 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. |
no test coverage detected