- Added fallback to get non standard mediaType from response

This commit is contained in:
Ferdi Koomen 2021-09-28 23:37:02 +02:00
parent 1633970c42
commit 675c9705e2
2 changed files with 17 additions and 24 deletions

View File

@ -1,30 +1,24 @@
import { isDefined } from '../../../utils/isDefined';
import type { Dictionary } from '../../../utils/types';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiMediaType } from '../interfaces/OpenApiMediaType';
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
export function getContent(openApi: OpenApi, content: Dictionary<OpenApiMediaType>): OpenApiSchema | null {
/* prettier-ignore */
return (
content['application/json-patch+json'] &&
content['application/json-patch+json'].schema
) || (
content['application/json'] &&
content['application/json'].schema
) || (
content['text/json'] &&
content['text/json'].schema
) || (
content['text/plain'] &&
content['text/plain'].schema
) || (
content['multipart/mixed'] &&
content['multipart/mixed'].schema
) || (
content['multipart/related'] &&
content['multipart/related'].schema
) || (
content['multipart/batch'] &&
content['multipart/batch'].schema
) || null;
const basicMediaTypeSchema =
content['application/json-patch+json']?.schema ||
content['application/json']?.schema ||
content['text/json']?.schema ||
content['text/plain']?.schema ||
content['multipart/mixed']?.schema ||
content['multipart/related']?.schema ||
content['multipart/batch']?.schema;
if (basicMediaTypeSchema) {
return basicMediaTypeSchema;
}
const mediaTypes = Object.values(content);
const mediaType = mediaTypes.find(mediaType => isDefined(mediaType.schema));
return mediaType?.schema || null;
}

View File

@ -60,7 +60,6 @@ describe('v3.node', () => {
prop: 'valueBody'
}
);
console.log(result)
expect(result).toBeDefined();
});
});