Skip to content

Commit 675c970

Browse files
committed
- Added fallback to get non standard mediaType from response
1 parent 1633970 commit 675c970

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/openApi/v3/parser/getContent.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1+
import { isDefined } from '../../../utils/isDefined';
12
import type { Dictionary } from '../../../utils/types';
23
import type { OpenApi } from '../interfaces/OpenApi';
34
import type { OpenApiMediaType } from '../interfaces/OpenApiMediaType';
45
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
56

67
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;
3024
}

test/e2e/v3.node.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ describe('v3.node', () => {
6060
prop: 'valueBody'
6161
}
6262
);
63-
console.log(result)
6463
expect(result).toBeDefined();
6564
});
6665
});

0 commit comments

Comments
 (0)