import { unixEOL , titleFormat } from '@sap-cloud-sdk/util' ; import { endWithDot } from './generator-utils' ; import { VdmComplexType , VdmEntity , VdmEnumType , VdmNavigationProperty , VdmProperty , VdmPropertyValueConstraints , VdmServiceMetadata } from './vdm-types' ; import { getServiceName } from './service-generator' ; internal export function getFunctionDoc ( description , tags ) { if ( tags ) { if ( tags . typeparams ) { tags . typeparams . forEach ( typeparam => { description += tagToText ( 'typeparam' , `${ typeparam . type } ${ typeparam . description }` ) ; } ) ; } if ( tags . params && tags . params . length ) { tags . params . forEach ( param => { description += tagToText ( 'param' , `${ param . name } ${ param . description }` ) ; } ) ; } if ( tags . returns ) { description += tagToText ( 'returns' , `${ tags . returns . description }` ) ; } } return description ; } internal export function getComplexTypeFieldDescription ( complexType ) { return `${ complexType . fieldType }${ unixEOL }@typeparam EntityT - Type of the entity the complex type field belongs to.` ; } internal export function getPropertyDescription ( property , constraints = { nullable : false } ) { return addConstraints ( property . description || endWithDot ( titleFormat ( property . instancePropertyName ) . trim ( ) ) , constraints ) ; } param documentation returns internal export function addLeadingNewline ( documentation ) { if ( ! documentation . startsWith ( unixEOL ) ) { return unixEOL + documentation ; } return documentation ; } internal export function getNavPropertyDescription ( property ) { return `${ property . isCollection ? 'One-to-many' : 'One-to-one' } navigation property to the [[${ property . toEntityClassName }]] entity.` . trim ( ) ; } internal export function getComplexTypePropertyDescription ( property , complexTypeName ) { return `Representation of the [[${ complexTypeName }.${ property . instancePropertyName }]] property for query construction.${ unixEOL }Use to reference this property in query operations such as 'filter' in the fluent request API.` ; } internal export function getStaticPropertyDescription ( property ) { return `Static representation of the [[${ property . instancePropertyName }]] property for query construction.${ unixEOL }Use to reference this property in query operations such as 'select' in the fluent request API.` ; } internal export function getStaticNavPropertyDescription ( property ) { return `Static representation of the ${ property . isCollection ? 'one-to-many' : 'one-to-one' } navigation property [[${ property . instancePropertyName }]] for query construction.${ unixEOL }Use to reference this property in query operations such as 'select' in the fluent request API.` ; } internal export function getEntityDescription ( entity , service ) { let description = entityDescription ( entity . entitySetName , getServiceName ( service ) ) ; if ( service . apiBusinessHubMetadata && service . apiBusinessHubMetadata . communicationScenario ) { description = partOfCommunicationScenarios ( service . apiBusinessHubMetadata . communicationScenario ) ; } if ( service . apiBusinessHubMetadata ) { description = seeForMoreInformation ( service . apiBusinessHubMetadata . url ) ; } return description ; } const entityDescription = ( entitySetName , speakingModuleName ) => `This class represents the entity "${ entitySetName }" of service "${ speakingModuleName }".` ; const seeForMoreInformation = ( url ) => `See ${ url } for more information.` ; const partOfCommunicationScenarios = ( communicationScenarios ) => `This service is part of the following communication scenarios: ${ communicationScenarios }.` ; internal export function getRequestBuilderDescription ( entity ) { return `Request builder class for operations supported on the [[${ entity . className }]] entity.` ; } internal export function getLookupDescription ( service ) { return `Lookup class for finding the constructor for an entity of the [[${ service . className }]] service.` ; } function addConstraints ( description , constraints ) { if ( constraints . maxLength ) { description += `${ unixEOL }Maximum length: ${ constraints . maxLength }.` ; } if ( constraints . nullable ) { description += `${ unixEOL }@nullable` ; } return description ; } internal export interface DocType { type : string ; description : string ; } internal export interface NamedDocType extends DocType { name : string ; } function tagToText ( tag , description = '' ) { return `${ unixEOL }@${ tag }` + ( description ? ` ${ description }` : '' ) ; } internal export function enumDocs ( enumType ) { return [ `This enum represents the enum type "[[${ enumType . originalName }]]".` , `The members represent values of EDM type ${ enumType . underlyingType }.` ] . join ( `${ unixEOL }` ) ; }