mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Added fallback to get non standard mediaType from response
This commit is contained in:
parent
1633970c42
commit
675c9705e2
@ -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;
|
||||
}
|
||||
|
||||
@ -60,7 +60,6 @@ describe('v3.node', () => {
|
||||
prop: 'valueBody'
|
||||
}
|
||||
);
|
||||
console.log(result)
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user