@ -20,6 +20,8 @@ import {
createTypesToImportsReducer ,
removeTypeModifiers ,
} from './type' ;
import { eBindingSourceId } from '../enums' ;
import { camelizeHyphen } from './text' ;
export function serializeParameters ( parameters : Property [ ] ) {
return parameters . map ( p = > p . name + p . optional + ': ' + p . type + p . default , '' ) . join ( ', ' ) ;
@ -79,8 +81,12 @@ export function createActionToSignatureMapper() {
return ( action : Action ) = > {
const signature = new Signature ( { name : getMethodNameFromAction ( action ) } ) ;
signature . parameters = action . parametersOnMethod . map ( p = > {
const versionParameter = getVersionParameter ( action ) ;
const parameters = [
. . . action . parametersOnMethod ,
. . . ( versionParameter ? [ versionParameter ] : [ ] ) ,
] ;
signature . parameters = parameters . map ( p = > {
const type = adaptType ( p . typeSimple ) ;
const parameter = new Property ( { name : p.name , type } ) ;
parameter . setDefault ( p . defaultValue ) ;
@ -96,6 +102,40 @@ function getMethodNameFromAction(action: Action): string {
return action . uniqueName . split ( 'Async' ) [ 0 ] ;
}
function getVersionParameter ( action : Action ) {
const versionParameter = action . parameters . find (
p = >
( p . name == 'apiVersion' && p . bindingSourceId == eBindingSourceId . Path ) ||
( p . name == 'api-version' && p . bindingSourceId == eBindingSourceId . Query ) ,
) ;
const bestVersion = findBestApiVersion ( action ) ;
return versionParameter && bestVersion
? {
. . . versionParameter ,
name : camelizeHyphen ( versionParameter . name ) ,
defaultValue : ` " ${ bestVersion } " ` ,
}
: null ;
}
// Implementation of https://github.com/abpframework/abp/commit/c3f77c1229508279015054a9b4f5586404a88a14#diff-a4dbf6be9a1aa21d8294f11047774949363ee6b601980bf3225e8046c0748c9eR101
function findBestApiVersion ( action : Action ) {
/ *
TODO : Implement configuredVersion when js proxies implemented
let configuredVersion = null ;
if ( action . supportedVersions . includes ( configuredVersion ) ) {
return configuredVersion ;
}
* /
if ( ! action . supportedVersions ? . length ) {
// TODO: return configuredVersion if exists or '1.0'
return '1.0' ;
}
//TODO: Ensure to get the latest version!
return action . supportedVersions [ action . supportedVersions . length - 1 ] ;
}
function createActionToImportsReducer (
solution : string ,
types : Record < string , Type > ,