import { codeBlock , documentationBlock , unixEOL } from '@sap-cloud-sdk/util' ; import { OpenApiApi , OpenApiOperation , OpenApiReferenceSchema } from '../openapi-types' ; import { collectRefs , getUniqueRefs } from '../schema-util' ; import { serializeOperation } from './operation' ; import { Import , serializeImports } from './imports' ; param api param serviceName returns internal export function apiFile ( api , serviceName ) { const imports = serializeImports ( getImports ( api ) ) ; const apiDoc = apiDocumentation ( api , serviceName ) ; const apiContent = codeBlock `
export const ${ api . name } = {
  ${ api . operations . map ( operation => serializeOperation ( operation ) ) . join ( ',\n' ) }
};
` ; return [ imports , apiDoc , apiContent ] . join ( unixEOL ) ; } param operations returns function collectRefsFromOperations ( operations ) { return getUniqueRefs ( operations . reduce ( ( referenceTypes , operation ) => [ ... referenceTypes , ... collectRefs ( ... [ operation . requestBody ?. schema , operation . response , ... operation . queryParameters . map ( ( { schema } ) => schema ) ] ) ] , [ ] ) ) ; } function getImports ( api ) { const refs = collectRefsFromOperations ( api . operations ) . map ( requestBodyType => requestBodyType . schemaName ) ; const refImports = { names : refs , moduleIdentifier : './schema' , typeOnly : true } ; const openApiImports = { names : [ 'OpenApiRequestBuilder' ] , moduleIdentifier : '@sap-cloud-sdk/openapi' } ; return [ openApiImports , refImports ] ; } internal export function apiDocumentation ( api , serviceName ) { return documentationBlock `
  Representation of the '${ api . name }'.
  This API is part of the '${ serviceName }' service.` ; }