在我的 azure devops 管道中,我有一个任务 AzureCLI@2 将 api 部署到 apim。如何使用az apim api使用相同的任务来更新 api?我知道有一个操作可以做到这一点,但文档没有显示如何做,我也没有找到任何例子。我正在使用管道中生成的打开的 api 文件来创建,我也想用它来更新 api。
1364 次
4 回答
5
再用az apim api import
一次。它将用新的 API 替换现有的 API,保留具有相同模板的操作的策略。--path
和--api-id
参数必须与现有 API 相同。提供 swagger/openapi 的 url/path 和正确的规范格式。例子:
az apim api import --path "/myapi" --api-id "myapiid" --resource-group "test-rg" --service-name "test-apim" --specification-url "https://petstore.swagger.io/v2/swagger.json" --specification-format Swagger
如果要添加修订而不是更新现有的,请添加附加--api-revision
参数
az apim api update
适用于更新单个属性或字段,如描述、api 类型等。
于 2021-05-02T21:28:09.337 回答
0
请使用以下脚本使用 az cli 在 APIM 中创建/更新 API。我假设
A. 您的 api 定义在 Open API 定义文件中。B. 您正在使用路径 ($apiPrefix) 识别 apim 端点。
$apiPrefix="my-path"
$rgName="RG_NAME"
$apimS="APIM_SVC_NAME"
$apiDefinitionLocalPath="PATH_TO_APIM_DEFINITION_JSON"
$allAPIs= az apim api list --resource-group $rgName --service-name $apimS
$allAPIsJson= $allAPIs | ConvertFrom-Json
$apiWithMatchingPath=$allAPIsJson | Where-Object {$_.path -eq $apiPrefix }
if($apiWithMatchingPath){
#it only requires the ID. using $apiWithMatchingPath.id will return the
#fully qualified ID... which is not required.
az apim api import --api-id $apiWithMatchingPath.name --resource-group `
$rgName --service-name $apimS --path $apiPrefix --api-type http --protocols`
https --specification-format OpenApi --specification-path `
$apiDefinitionLocalPath
}else{
#IMPORT definition w/o name
az apim api import --resource-group $rgName --service-name $apimS --path `
$apiPrefix --api-type http --protocols https --specification-format `
OpenApi --specification-path $apiDefinitionLocalPath
}
于 2021-06-02T16:03:18.827 回答