import assert from 'assert' ; import * as model from '../model/metamodel' ; import { JsonSpec } from '../model/json-spec' ; /**
 * Adds the `accept` and `contentType` fields to every endpoint
 * from the rest-api-spec if present.
 */ export default async function addContentType ( model , jsonSpec ) { for ( const endpoint of model . endpoints ) { const spec = jsonSpec . get ( endpoint . name ) ; assert ( spec , `Can't find the json spec for ${ endpoint . name }` ) ; if ( Array . isArray ( spec . headers . accept ) ) { endpoint . accept = spec . headers . accept ; } if ( Array . isArray ( spec . headers . content_type ) ) { endpoint . contentType = spec . headers . content_type ; } } return model ; }