Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active March 1, 2022 14:57
Show Gist options
  • Save justinyoo/4b0138f38c8b15edbaa6fafe2c2a9e1e to your computer and use it in GitHub Desktop.
Save justinyoo/4b0138f38c8b15edbaa6fafe2c2a9e1e to your computer and use it in GitHub Desktop.
{
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
- name: Generate OpenAPI document
shell: pwsh
env:
OpenApi__HostNames: 'https://<azure-functions-app>.azurewebsites.net/api'
AZURE_FUNCTIONS_ENVIRONMENT: 'Production'
run: |
cd MyFunctionApp
mkdir outputs
# Create local.settings.json
cp ./local.settings.sample.json ./local.settings.json
Start-Process -NoNewWindow func @("start","--verbose","false")
Start-Sleep -s 60
Invoke-RestMethod -Method Get -Uri http://localhost:7071/api/swagger.json | ConvertTo-Json -Depth 100 | Out-File -FilePath outputs/swagger.json -Force
Get-Content -Path outputs/swagger.json -Raw
cd ..
// OpenAPI v2
{
"swagger": "2.0",
"host": "<azure-functions-app>.azurewebsites.net",
"basePath": "/api",
"schemes": [
"https"
]
}
// OpenAPI v3
{
"openapi": "3.0.1",
"servers": [
{
"url": "https://<azure-functions-app>.azurewebsites.net/api"
}
]
}
// azuredeploy.bicep
param servicename string
resource apim 'Microsoft.ApiManagement/service@2021-08-01' existing = {
name: servicename
scope: resourceGroup(apiManagement.groupName)
}
// azuredeploy.bicep
param openapidoc string
resource apimapi 'Microsoft.ApiManagement/service/apis@2021-08-01' = {
name: '${apim.name}/my-api'
properties: {
type: 'http'
displayName: 'My API'
description: 'This is my API.'
path: 'myapi'
subscriptionRequired: true
format: 'openapi+json-link'
value: openapidoc
}
}
$servicename = "<my_apim_service_name>"
$openapidoc = https://<my_blob_storage_name>.blob.core.windows.net/<container>/openapi.json
az deployment group create `
-g <resource_group_name> `
-n <deployment_name> `
-f ./azuredeploy.bicep `
-p servicename=$servicename `
-p openapidoc=$openapidoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment