import { OperationGroup , ObjectSchema , Operation , Response } from "@autorest/codemodel" ; import { getOperationFullName } from "./nameUtils" ; import { headersToSchema } from "./headersToSchema" ; import { getLanguageMetadata } from "./languageHelpers" ; export function extractHeaders ( operationGroups , clientName ) { let responseHeaders = [ ] ; operationGroups . forEach ( operationGroup => operationGroup . operations . forEach ( operation => { processHeaders ( false , operation . responses || [ ] , responseHeaders , operationGroup , operation , clientName ) ; processHeaders ( true , operation . exceptions || [ ] , responseHeaders , operationGroup , operation , clientName ) ; } ) ) ; return responseHeaders ; } function processHeaders ( isException , responses , responseHeaders , operationGroup , operation , clientName ) { responses . forEach ( response => { const operationName = getOperationFullName ( operationGroup , operation , clientName ) ; const headers = response . protocol . http ?. headers ; if ( headers ) { const headerSchema = headersToSchema ( headers , operationName , isException ) ; if ( headerSchema ) { updateResponseHeaders ( headerSchema , responseHeaders ) ; } } } ) ; } function updateResponseHeaders ( headerSchema , responseHeaders ) { let pushHeaderSchema = true ; for ( let responseHeader of responseHeaders ) { if ( getLanguageMetadata ( responseHeader . language ) . name == getLanguageMetadata ( headerSchema . language ) . name ) { if ( headerSchema . properties ) { if ( responseHeader . properties ) { responseHeader . properties . concat ( headerSchema . properties ) ; } else { responseHeader . properties = headerSchema . properties ; } pushHeaderSchema = false ; } } } if ( pushHeaderSchema ) { responseHeaders . push ( headerSchema ) ; } }