import { HttpHeader , ObjectSchema , Property } from "@autorest/codemodel" ; import { getLanguageMetadata } from "../utils/languageHelpers" ; export function headersToSchema ( headers , operationFullName , isError ) { if ( ! headers || ! headers . length ) { return undefined ; } const headersSchema = new ObjectSchema ( `${ operationFullName }${ isError ? "Exception" : "" }Headers` , `Defines headers for ${ operationFullName } operation.` ) ; headers . forEach ( ( { header , language , schema , extensions } ) => { if ( ! headersSchema . properties ) { headersSchema . properties = [ ] ; } const { description , name } = getLanguageMetadata ( language ) ; const prop = new Property ( name , description , schema , { serializedName : header . toLocaleLowerCase ( ) } ) ; if ( extensions && extensions [ "x-ms-header-collection-prefix" ] ) { prop . schema . language . default [ "headerCollectionPrefix" ] = extensions [ "x-ms-header-collection-prefix" ] ; } headersSchema . properties . push ( prop ) ; } ) ; return headersSchema ; }