|
| 1 | +import { isDefined } from '../../../utils/isDefined'; |
1 | 2 | import type { Dictionary } from '../../../utils/types';
|
2 | 3 | import type { OpenApi } from '../interfaces/OpenApi';
|
3 | 4 | import type { OpenApiMediaType } from '../interfaces/OpenApiMediaType';
|
4 | 5 | import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
5 | 6 |
|
6 | 7 | export function getContent(openApi: OpenApi, content: Dictionary<OpenApiMediaType>): OpenApiSchema | null {
|
7 |
| - /* prettier-ignore */ |
8 |
| - return ( |
9 |
| - content['application/json-patch+json'] && |
10 |
| - content['application/json-patch+json'].schema |
11 |
| - ) || ( |
12 |
| - content['application/json'] && |
13 |
| - content['application/json'].schema |
14 |
| - ) || ( |
15 |
| - content['text/json'] && |
16 |
| - content['text/json'].schema |
17 |
| - ) || ( |
18 |
| - content['text/plain'] && |
19 |
| - content['text/plain'].schema |
20 |
| - ) || ( |
21 |
| - content['multipart/mixed'] && |
22 |
| - content['multipart/mixed'].schema |
23 |
| - ) || ( |
24 |
| - content['multipart/related'] && |
25 |
| - content['multipart/related'].schema |
26 |
| - ) || ( |
27 |
| - content['multipart/batch'] && |
28 |
| - content['multipart/batch'].schema |
29 |
| - ) || null; |
| 8 | + const basicMediaTypeSchema = |
| 9 | + content['application/json-patch+json']?.schema || |
| 10 | + content['application/json']?.schema || |
| 11 | + content['text/json']?.schema || |
| 12 | + content['text/plain']?.schema || |
| 13 | + content['multipart/mixed']?.schema || |
| 14 | + content['multipart/related']?.schema || |
| 15 | + content['multipart/batch']?.schema; |
| 16 | + |
| 17 | + if (basicMediaTypeSchema) { |
| 18 | + return basicMediaTypeSchema; |
| 19 | + } |
| 20 | + |
| 21 | + const mediaTypes = Object.values(content); |
| 22 | + const mediaType = mediaTypes.find(mediaType => isDefined(mediaType.schema)); |
| 23 | + return mediaType?.schema || null; |
30 | 24 | }
|
0 commit comments