api - Azure API 管理 - 更新 Swagger 架构

标签 api azure-api-management

我已经导入了我的 swagger 模式,并且管理服务已经为我的 API 构建了所有文档。我现在已经进行了更改并重新部署了更改。我是否从 API 管理中删除了 API 并重新导入,或者有没有办法“更新”现有的 API?

最佳答案

好吧,伙计们,我将履行我对人类的责任,并向你们展示实现这一目标的真正方法。 “真实”我的意思是,让我们面对现实,现实世界中没有人会继续点击门户来刷新对他们的 API 的更改。每个人都想要的是自动化这个烦人的手动任务。

所以我写了这个我们目前在生产中使用的 Powershell 脚本。这肯定会让你到达那里。

先决条件:您需要一个服务主体才能自动登录。 I used this guide to do that.

param(
[String]$pass,
[String]$swaggerUrl,
[String]$apiId,
[String]$apiName,
[String]$apiServiceUrl
)
Try
{
    $azureAccountName = "[YOUR AZURE AD APPLICATION ID FOR THE SERVICE PRINCIPAL]"
    $azurePassword = ConvertTo-SecureString $pass -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword)
    Add-AzureRmAccount -Credential $psCred -TenantId "[YOUR AZURE TENANT ID]" -ServicePrincipal

    $azcontext = New-AzureRmApiManagementContext -ResourceGroupName "[YOUR RESOURCE GROUP NAME]" -ServiceName "[THE NAME OF YOUR API MANAGEMENT INSTANCE]"
    Import-AzureRmApiManagementApi -Context $azcontext -SpecificationFormat "Swagger" -SpecificationUrl $swaggerUrl -ApiId $apiId
    Set-AzureRmApiManagementApi -Context $azcontext -ApiId $apiId -ServiceUrl $apiServiceUrl -Protocols @("https") -Name $apiName
}
Catch
{
  Write-Host "FAILURE! An error occurred!!! Aborting script..." 
  exit 
}

显然,您需要替换上面括号中的字符串。参数说明:

"pass": 您的服务主体的密码

"swaggerUrl": 应用程序的 swagger json 文档的路径

"apiId":从您的 API 管理实例获取此值,如果您检查现有 API,它将显示在门户的仪表板中

"apiName": 无论你想给它起什么名字

"apiServiceUrl":API 的 Azure 应用服务 URL(或 API 所在的任何位置)

关于api - Azure API 管理 - 更新 Swagger 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35799763/

相关文章:

c# - HttpClient PutAsync 使用 RestAPI 更新字段

python - WordPress Api 请求错误 : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:700)

azure - 如何访问 Azure API 管理中的路由参数

Azure API 管理 - 自定义域特定 API?

azure - 调试ARM模板

javascript - 包装脚本以接收 api 函数调用

python - GAE Python - 访问响应对象中的值

api - Web 部署 API(部署 .zip 包)说明

Azure 应用程序网关运行状况检查证书不匹配

Azure Api 管理从 swagger 导入 API