import { omit } from 'lodash' ; import { ApiResponseSchemaHost } from '../decorators' ; import { getSchemaPath } from '../utils' ; import { MimetypeContentWrapper } from './mimetype-content-wrapper' ; export class ResponseObjectMapper { private readonly mimetypeContentWrapper = new MimetypeContentWrapper ( ) ; toArrayRefObject ( response , name , produces ) { return { ... response , ... this . mimetypeContentWrapper . wrap ( produces , { schema : { type : 'array' , items : { $ref : getSchemaPath ( name ) } } } ) } ; } toRefObject ( response , name , produces ) { return { ... response , ... this . mimetypeContentWrapper . wrap ( produces , { schema : { $ref : getSchemaPath ( name ) } } ) } ; } wrapSchemaWithContent ( response , produces ) { if ( ! response . schema ) { return response ; } const content = this . mimetypeContentWrapper . wrap ( produces , { schema : response . schema } ) ; return { ... omit ( response , 'schema' ) , ... content } ; } }