0

我正在尝试使用 Azure CLI 使用新规范更新 Azure API 管理服务内的版本集中的现有版本。

我知道它确实支持将其作为没有版本集的 API 导入:

az apim api import `
  --path "/as" `
  --resource-group "myResourceGroup" `
  --service-name "test-apim" `
  --api-id "test-apim" `
  --specification-format "OpenApiJson" `
  --specification-path "..\swagger.json"

而且我还知道您可以使用 Azure Powershell 模块来获取版本集并使用它来上传新规范:

$apiMgmtContext = New-AzApiManagementContext `
    -ResourceGroupName "myResourceGroup" `
    -ServiceName "test-apim"

$versionSet = Get-AzApiManagementApiVersionSet -Context $apiMgmtContext |          
    Where-Object { $_.DisplayName -eq "my-version-set" } |
        Sort-Object -Property ApiVersionSetId -Descending |
            Select-Object -first 1

Import-AzApiManagementApi `
    -Context $apiMgmtContext `
    -ApiVersionSetId $versionSet.ApiVersionSetId `
    -ServiceUrl "http" `
    -SpecificationFormat "OpenApiJson" `
    -SpecificationPath "..\swagger.json" `
    -Path "/as" `
    -ApiId "test-apim"

但是有谁知道这是否可以通过 az cli 来完成,因为 powershell 模块最终会过时?

4

1 回答 1

0

查看文档,它支持版本集。

您需要使用参数--api-version-set-id

az apim api import `
  --path "/as" `
  --resource-group "myResourceGroup" `
  --service-name "test-apim" `
  --api-id "test-apim" `
  --specification-format "OpenApiJson" `
  --specification-path "..\swagger.json" `
  --api-version-set-id "my-version-set-id"

此外,目前没有迹象表明 Az Powershell 会过时。

于 2021-07-07T08:42:23.277 回答