From 425b337baa218cd2a991946d4bc779a63a8a0498 Mon Sep 17 00:00:00 2001 From: Manikyam Bavandla Date: Tue, 19 Sep 2017 15:44:13 -0700 Subject: [PATCH] Resolve UnableToExtractDetailsFromSdkAssembly error when OperationType in OperationId conflicts with Definition name. When OperationType value conflicts with a definition name, AutoREST generates method name by adding Method to the OperationType. Current error for swagger specs of Azure Servicebus and Relay services. ```powershell Generating module for 'C:\temp\AzureSwaggerSpecs\SwaggerSpecs\servicebus\servicebus.json'. Update-PathFunctionDetails : Module generation failed. If no error messages follow, check the output of code metadata extraction above Unable to find expected method 'CheckNameAvailabilityWithHttpMessagesAsync' on type 'Microsoft.PowerShell.Azservicebus.v001.INamespacesOperations' At C:\Code\PSSwagger\PSSwagger\PSSwagger.psm1:555 char:28 + ... onDetails = Update-PathFunctionDetails -PathFunctionDetails $PathFunc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails ``` ```powershell Generating module for 'C:\temp\AzureSwaggerSpecs\SwaggerSpecs\relay\relay.json'. Update-PathFunctionDetails : Module generation failed. If no error messages follow, check the output of code metadata extraction above Unable to find expected method 'CheckNameAvailabilityWithHttpMessagesAsync' on type 'Microsoft.PowerShell.Azrelay.v001.INamespacesOperations' At C:\Code\PSSwagger\PSSwagger\PSSwagger.psm1:555 char:28 + ... onDetails = Update-PathFunctionDetails -PathFunctionDetails $PathFunc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails ``` --- PSSwagger/Paths.psm1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/PSSwagger/Paths.psm1 b/PSSwagger/Paths.psm1 index 4806794..e1b68f3 100644 --- a/PSSwagger/Paths.psm1 +++ b/PSSwagger/Paths.psm1 @@ -1034,12 +1034,13 @@ function Set-ExtendedCodeMetadata { } $operationId = $parameterSetDetail.OperationId - $methodName = '' + $methodNames = @() $operations = '' $operationsWithSuffix = '' $opIdValues = $operationId -split '_',2 if(-not $opIdValues -or ($opIdValues.count -ne 2)) { - $methodName = $operationId + 'WithHttpMessagesAsync' + $methodNames += $operationId + 'WithHttpMessagesAsync' + $methodNames += $operationId + 'Method' + 'WithHttpMessagesAsync' } else { $operationName = $opIdValues[0] $operationType = $opIdValues[1] @@ -1049,10 +1050,11 @@ function Set-ExtendedCodeMetadata { $operationsWithSuffix = $operations + 'Operations' } - $methodName = $operationType + 'WithHttpMessagesAsync' + $methodNames += $operationType + 'WithHttpMessagesAsync' + # When OperationType value conflicts with a definition name, AutoREST generates method name by adding Method to the OperationType. + $methodNames += $operationType + 'Method' + 'WithHttpMessagesAsync' } - $parameterSetDetail['MethodName'] = $methodName $parameterSetDetail['Operations'] = $operations # For some reason, moving this out of this loop causes issues @@ -1119,13 +1121,14 @@ function Set-ExtendedCodeMetadata { $clientType = $propertyObject.PropertyType } - $methodInfo = $clientType.GetMethods() | Where-Object { $_.Name -eq $MethodName } | Select-Object -First 1 + $methodInfo = $clientType.GetMethods() | Where-Object {$MethodNames -contains $_.Name} | Select-Object -First 1 if (-not $methodInfo) { - $resultRecord.ErrorMessages += $LocalizedData.ExpectedMethodOnTypeNotFound -f ($MethodName, $clientType) + $resultRecord.ErrorMessages += $LocalizedData.ExpectedMethodOnTypeNotFound -f (($MethodNames -join ', or '), $clientType) Export-CliXml -InputObject $resultRecord -Path $CliXmlTmpPath $errorOccurred = $true return } + $parameterSetDetail['MethodName'] = $methodInfo.Name # Process output type $returnType = $methodInfo.ReturnType