import { createLogger } from '@sap-cloud-sdk/util' ; import { OpenAPIV3 } from 'openapi-types' ; import { OpenApiSchema } from '../openapi-types' ; import { OpenApiDocumentRefs } from './refs' ; import { parseSchema } from './schema' ; import { ParserOptions } from './options' ; const logger = createLogger ( 'openapi-generator' ) ; param bodyOrResponseObject param refs param options returns internal export function parseApplicationJsonMediaType ( bodyOrResponseObject , refs , options ) { if ( bodyOrResponseObject ) { const mediaType = getMediaTypeObject ( bodyOrResponseObject , 'application/json' ) ; const schema = mediaType ?. schema ; if ( schema ) { return parseSchema ( schema , refs , options ) ; } } } internal export function parseMediaType ( bodyOrResponseObject , refs , options ) { const allMediaTypes = getMediaTypes ( bodyOrResponseObject ) ; if ( allMediaTypes . length ) { const jsonMediaType = parseApplicationJsonMediaType ( bodyOrResponseObject , refs , options ) ; if ( ! jsonMediaType ) { logger . warn ( "Could not parse media type, because it is not 'application/json'. Generation will continue with 'any'. This might lead to errors at runtime." ) ; return { type : 'any' } ; } if ( allMediaTypes . length === 1 ) { return jsonMediaType ; } return { anyOf : [ jsonMediaType , { type : 'any' } ] } ; } } internal export function getMediaTypes ( bodyOrResponseObject ) { return Object . keys ( bodyOrResponseObject ?. content || { } ) ; } param bodyOrResponseObject param contentType returns function getMediaTypeObject ( bodyOrResponseObject , contentType ) { if ( bodyOrResponseObject ?. content ) { return Object . entries ( bodyOrResponseObject . content ) . find ( ( [ key ] ) => key === contentType ) ?. [ 1 ] ; } }