Created
April 27, 2020 07:13
-
-
Save bradygaster/7caacd363af3f7739b443bac4699f404 to your computer and use it in GitHub Desktop.
Import a REST API described by a Open API Specification (the artist formerly known as Swagger) file using the PowerShell cmdlets for Azure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Variables | |
Set-Variable -Name ResourceGroupName "SomeApi" | |
Set-Variable -Name ApimInstance "my-app-apis" | |
Set-Variable -Name SwaggerFilePath "C:\Users\brady\source\repos\brady\SomeApi\bin\Debug\netcoreapp3.1\swagger.json" | |
Set-Variable -Name ServiceUrl "https://some-api-123.azurewebsites.net" | |
Set-Variable -Name ApiId "SomeApi" | |
Set-Variable -Name ApiVersion "v1" | |
Set-Variable -Name AzureSubscriptionId "" | |
# select the subscription | |
Set-AzContext -SubscriptionId $AzureSubscriptionId | |
# import the api | |
Write-Output "Setting API Management Context" | |
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ApimInstance | |
# remove the old api | |
Write-Output "Removing the old API" | |
Remove-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId | |
# import the new api | |
Write-Output "Importing Swagger into a new API" | |
Import-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -ServiceUrl $ServiceUrl -SpecificationFormat "Swagger" -SpecificationPath $SwaggerFilePath -Path $ApiVersion | |
# get the api | |
$api = Get-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId | |
# disable the subscription requirement | |
Write-Output "Disabling the subscription header requirement" | |
$api.SubscriptionRequired = $false | |
Set-AzApiManagementApi -InputObject $api |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment