import { RestApi } from "./exchangeTypes" ; import _ from "lodash" ; description export param { RestApi [ ] } apis param { string } groupBy param { boolean } allowUnclassified returns { { [ key : string ] : RestApi [ ] } } export function groupByCategory ( apis , groupBy , allowUnclassified = true ) { return _ . groupBy ( apis , ( api ) => { if ( api . categories && groupBy in api . categories ) { return api . categories [ groupBy ] [ 0 ] ; } else if ( allowUnclassified ) { return "unclassified" ; } else { throw new Error ( "Unclassified APIs are NOT allowed!" ) ; } } ) ; } description export param { RestApi [ ] } apis returns { RestApi [ ] } export function removeRamlLinks ( apis ) { const apiCopy = _ . cloneDeep ( apis ) ; apiCopy . forEach ( ( apiEntry ) => { delete apiEntry . fatRaml . externalLink ; } ) ; return apiCopy ; } param api export function removeVersionSpecificInformation ( api ) { const apiCopy = _ . cloneDeep ( api ) ; apiCopy . id = null ; apiCopy . updatedDate = null ; apiCopy . version = null ; if ( apiCopy . fatRaml ) { apiCopy . fatRaml . createdDate = null ; apiCopy . fatRaml . md5 = null ; apiCopy . fatRaml . sha1 = null ; delete apiCopy . fatRaml . externalLink ; } return apiCopy ; }