Skip to content

Commit 69ef6cc

Browse files
committed
Merge branch 'main' into v2
2 parents 680471b + cfabb43 commit 69ef6cc

File tree

53 files changed

+837
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+837
-838
lines changed

.github/workflows/main-actions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
with:
2929
dotnet-version: '6.x'
3030

31+
- name: Setup .NET SDK 7 STS
32+
uses: actions/setup-dotnet@v1
33+
with:
34+
dotnet-version: '7.x'
35+
3136
- name: Restore NuGet packages
3237
shell: pwsh
3338
run: |

.github/workflows/main-build.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,26 @@ jobs:
3838
run: |
3939
npm install -g azure-functions-core-tools@4 --unsafe-perm true
4040
41-
- name: Setup .NET SDK 3.1 LTS
42-
uses: actions/setup-dotnet@v1
43-
with:
44-
dotnet-version: '3.1.x'
41+
# - name: Setup .NET SDK 3.1 LTS
42+
# uses: actions/setup-dotnet@v1
43+
# with:
44+
# dotnet-version: '3.1.x'
4545

46-
- name: Setup .NET SDK 5
47-
uses: actions/setup-dotnet@v1
48-
with:
49-
dotnet-version: '5.x'
46+
# - name: Setup .NET SDK 5
47+
# uses: actions/setup-dotnet@v1
48+
# with:
49+
# dotnet-version: '5.x'
5050

5151
- name: Setup .NET SDK 6 LTS
5252
uses: actions/setup-dotnet@v1
5353
with:
5454
dotnet-version: '6.x'
5555

56+
- name: Setup .NET SDK 7 STS
57+
uses: actions/setup-dotnet@v1
58+
with:
59+
dotnet-version: '7.x'
60+
5661
# - name: Add MSBuild to PATH
5762
# uses: microsoft/[email protected]
5863

.github/workflows/pr.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,26 @@ jobs:
3030
run: |
3131
npm install -g azure-functions-core-tools@4 --unsafe-perm true
3232
33-
- name: Setup .NET SDK 3.1 LTS
34-
uses: actions/setup-dotnet@v1
35-
with:
36-
dotnet-version: '3.1.x'
33+
# - name: Setup .NET SDK 3.1 LTS
34+
# uses: actions/setup-dotnet@v1
35+
# with:
36+
# dotnet-version: '3.1.x'
3737

38-
- name: Setup .NET SDK 5
39-
uses: actions/setup-dotnet@v1
40-
with:
41-
dotnet-version: '5.x'
38+
# - name: Setup .NET SDK 5
39+
# uses: actions/setup-dotnet@v1
40+
# with:
41+
# dotnet-version: '5.x'
4242

4343
- name: Setup .NET SDK 6 LTS
4444
uses: actions/setup-dotnet@v1
4545
with:
4646
dotnet-version: '6.x'
4747

48+
- name: Setup .NET SDK 7 STS
49+
uses: actions/setup-dotnet@v1
50+
with:
51+
dotnet-version: '7.x'
52+
4853
# - name: Add MSBuild to PATH
4954
# uses: microsoft/[email protected]
5055

Microsoft.Azure.WebJobs.Extensions.OpenApi.sln

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Ext
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi", "src\Microsoft.Azure.WebJobs.Extensions.OpenApi\Microsoft.Azure.WebJobs.Extensions.OpenApi.csproj", "{D405655F-C8BE-4134-893C-ADB4918B0624}"
2424
EndProject
25-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI", "src\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.csproj", "{7AD094AA-01D6-4644-B9B6-E555A029D6D7}"
26-
EndProject
2725
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{66D8DEA8-B477-497F-95BB-E8F9A5BAC352}"
2826
EndProject
2927
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc", "samples\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc.csproj", "{7FD0AC53-E04D-41C6-9633-924A0D98A114}"
@@ -48,8 +46,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Ext
4846
EndProject
4947
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.Tests", "test\Microsoft.Azure.WebJobs.Extensions.OpenApi.Tests\Microsoft.Azure.WebJobs.Extensions.OpenApi.Tests.csproj", "{D787694D-B87B-4E11-9455-B5BF9306D8FC}"
5048
EndProject
51-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests", "test\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests.csproj", "{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}"
52-
EndProject
5349
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-integration", "test-integration", "{CBD9883B-134F-42CC-A201-EE06EBC48C3E}"
5450
EndProject
5551
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp", "test-integration\Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp\Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.csproj", "{7F6EC289-B516-455E-8E5F-324D5C9212B7}"
@@ -78,10 +74,6 @@ Global
7874
{D405655F-C8BE-4134-893C-ADB4918B0624}.Debug|Any CPU.Build.0 = Debug|Any CPU
7975
{D405655F-C8BE-4134-893C-ADB4918B0624}.Release|Any CPU.ActiveCfg = Release|Any CPU
8076
{D405655F-C8BE-4134-893C-ADB4918B0624}.Release|Any CPU.Build.0 = Release|Any CPU
81-
{7AD094AA-01D6-4644-B9B6-E555A029D6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82-
{7AD094AA-01D6-4644-B9B6-E555A029D6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
83-
{7AD094AA-01D6-4644-B9B6-E555A029D6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
84-
{7AD094AA-01D6-4644-B9B6-E555A029D6D7}.Release|Any CPU.Build.0 = Release|Any CPU
8577
{7FD0AC53-E04D-41C6-9633-924A0D98A114}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8678
{7FD0AC53-E04D-41C6-9633-924A0D98A114}.Debug|Any CPU.Build.0 = Debug|Any CPU
8779
{7FD0AC53-E04D-41C6-9633-924A0D98A114}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -122,10 +114,6 @@ Global
122114
{D787694D-B87B-4E11-9455-B5BF9306D8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
123115
{D787694D-B87B-4E11-9455-B5BF9306D8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
124116
{D787694D-B87B-4E11-9455-B5BF9306D8FC}.Release|Any CPU.Build.0 = Release|Any CPU
125-
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126-
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Debug|Any CPU.Build.0 = Debug|Any CPU
127-
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Release|Any CPU.ActiveCfg = Release|Any CPU
128-
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Release|Any CPU.Build.0 = Release|Any CPU
129117
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
130118
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
131119
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -143,7 +131,6 @@ Global
143131
{64A22A3C-D0C4-4DE9-A8D5-2CEF766EB500} = {810145E0-41CF-4E24-BD9C-E7517498BA29}
144132
{B18937F6-B39F-46BB-BB3C-86C0693993EF} = {810145E0-41CF-4E24-BD9C-E7517498BA29}
145133
{D405655F-C8BE-4134-893C-ADB4918B0624} = {810145E0-41CF-4E24-BD9C-E7517498BA29}
146-
{7AD094AA-01D6-4644-B9B6-E555A029D6D7} = {810145E0-41CF-4E24-BD9C-E7517498BA29}
147134
{66D8DEA8-B477-497F-95BB-E8F9A5BAC352} = {810145E0-41CF-4E24-BD9C-E7517498BA29}
148135
{7FD0AC53-E04D-41C6-9633-924A0D98A114} = {66D8DEA8-B477-497F-95BB-E8F9A5BAC352}
149136
{1E7232C2-8560-4030-9B5D-AD88A1680F62} = {66D8DEA8-B477-497F-95BB-E8F9A5BAC352}
@@ -155,7 +142,6 @@ Global
155142
{1D1A5ED5-A1A1-4082-ACAF-30079AF31AC6} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
156143
{968CD847-80D0-4740-92D5-F5553461EC04} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
157144
{D787694D-B87B-4E11-9455-B5BF9306D8FC} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
158-
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
159145
{CBD9883B-134F-42CC-A201-EE06EBC48C3E} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
160146
{7F6EC289-B516-455E-8E5F-324D5C9212B7} = {CBD9883B-134F-42CC-A201-EE06EBC48C3E}
161147
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB} = {CBD9883B-134F-42CC-A201-EE06EBC48C3E}

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
If you are using GitHub Actions as your preferred CI/CD pipeline, you can run the GitHub Action into your workflow to automatically generate the OpenAPI document. Find more details at the [Build OpenAPI](./actions/build-openapi/) action page.
2828

29+
30+
## Generic CI/CD Pipeline Support ##
31+
2932
Alternatively, you can run either PowerShell script or bash shell script to generate the OpenAPI document within your own CI/CD pipeline other than GitHub Actions. Here are two script files:
3033

3134
* PowerShell: [Get-OpenApiDocument.ps1](./actions/Get-OpenApiDocument.ps1)
@@ -43,6 +46,19 @@ Alternatively, you can run either PowerShell script or bash shell script to gene
4346
4447
For more details, run `Get-OpenApiDocument.ps1 -Help`
4548
49+
You can also remotely invoke this PowerShell script:
50+
51+
```powershell
52+
& $([Scriptblock]::Create($(Invoke-RestMethod https://aka.ms/azfunc-openapi/generate-openapi.ps1))) `
53+
-FunctionAppPath <function app directory> `
54+
-BaseUri <function app base URI> `
55+
-Endpoint <endpoint for OpenAPI document> `
56+
-OutputPath <output directory for generated OpenAPI document> `
57+
-OutputFilename <OpenAPI document name> `
58+
-Delay <delay in second between run function app and document generation> `
59+
-UseWindows <switch indicating whether to use Windows OS or not>
60+
```
61+
4662
* Bash shell: [get-openapi-document.sh](./actions/get-openapi-document.sh)
4763
4864
```bash
@@ -57,6 +73,19 @@ Alternatively, you can run either PowerShell script or bash shell script to gene
5773
5874
For more details, run `get-openapi-document.sh --help`
5975
76+
You can also remotely invoke this bash shell script:
77+
78+
```bash
79+
curl -fsSL https://aka.ms/azfunc-openapi/generate-openapi.sh \
80+
| bash -s -- \
81+
-p|--functionapp-path <function app directory> \
82+
-u|--base-uri <function app base URI> \
83+
-e|--endpoint <endpoint for OpenAPI document> \
84+
-o|--output-path <output directory for generated OpenAPI document> \
85+
-f|--output-filename <OpenAPI document name> \
86+
-d|--delay <delay in second between run function app and document generation>
87+
```
88+
6089
6190
## Sample Azure Function Apps with OpenAPI Document Enabled ##
6291

actions/Get-OpenApiDocument.ps1

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Param(
33
[string]
44
[Parameter(Mandatory=$false)]
5-
$FunctionAppPath = "bin/Debug/net6.0",
5+
$FunctionAppPath = ".",
66

77
[string]
88
[Parameter(Mandatory=$false)]
@@ -25,6 +25,10 @@ Param(
2525
[Parameter(Mandatory=$false)]
2626
$Delay = 30,
2727

28+
[switch]
29+
[Parameter(Mandatory=$false)]
30+
$UseCodespaces,
31+
2832
[switch]
2933
[Parameter(Mandatory=$false)]
3034
$UseWindows,
@@ -43,22 +47,24 @@ function Show-Usage {
4347
[-OutputPath <output directory for generated OpenAPI document>] ``
4448
[-OutputFilename <OpenAPI document name>] ``
4549
[-Delay <delay in second between run function app and document generation>] ``
50+
[-UseCodespaces] ``
4651
[-UseWindows] ``
4752
[-Help]
4853
Options:
49-
-FunctionAppPath Function app path. It can be the project directory or compiled app directory.
50-
Default: 'bin/Debug/net6.0'
54+
-FunctionAppPath Function app path, relative to the repository root. It can be the project directory or compiled app directory.
55+
Default: '.'
5156
-BaseUri Function app base URI.
5257
Default: 'http://localhost:7071/api/'
5358
-Endpoint OpenAPI document endpoint.
5459
Default: 'swagger.json'
55-
-OutputPath Output directory to store the generated OpenAPI document.
60+
-OutputPath Output directory to store the generated OpenAPI document, relative to the repository root.
5661
Default: 'generated'
5762
-OutputFilename Output filename for the generated OpenAPI document.
5863
Default: 'swagger.json'
5964
-Delay Delay in second between the function app run and document generation.
6065
Default: 30
61-
-UseWindows Switch that indicates using Windows OS.
66+
-UseCodespaces Switch indicating whether to use GitHub Codespaces or not.
67+
-UseWindows Switch indicating whether to run on Windows OS or not.
6268
-Help Show this message.
6369
"
6470

@@ -78,20 +84,27 @@ if ($UseWindows -eq $true) {
7884
$func = $func.Replace(".ps1", ".cmd")
7985
}
8086

81-
pushd $FunctionAppPath
87+
$currentDirectory = $(pwd).Path
88+
89+
$repositoryRoot = $env:GITHUB_WORKSPACE
90+
if ($UseCodespaces -eq $true) {
91+
$repositoryRoot = $env:CODESPACE_VSCODE_FOLDER
92+
}
93+
94+
cd "$repositoryRoot/$FunctionAppPath"
8295

8396
# Run the function app in the background
8497
Start-Process -NoNewWindow "$func" @("start","--verbose","false")
8598
Start-Sleep -s $Delay
8699

100+
# Download the OpenAPI document
87101
$requestUri = "$($BaseUri.TrimEnd('/'))/$($Endpoint.TrimStart('/'))"
88-
$filepath = "$($OutputPath.TrimEnd('/'))/$($OutputFilename.TrimStart('/'))"
102+
$filepath = "$repositoryRoot/$($OutputPath.TrimEnd('/'))/$($OutputFilename.TrimStart('/'))"
89103

90-
if ($(Test-Path -Path "$($OutputPath.TrimEnd('/'))" -PathType Container) -eq $false) {
91-
New-Item -Path "$($OutputPath.TrimEnd('/'))" -ItemType Directory
104+
if ($(Test-Path -Path "$repositoryRoot/$($OutputPath.TrimEnd('/'))" -PathType Container) -eq $false) {
105+
New-Item -Path "$repositoryRoot/$($OutputPath.TrimEnd('/'))" -ItemType Directory
92106
}
93107

94-
# Download the OpenAPI document
95108
Invoke-RestMethod -Method Get -Uri $requestUri | ConvertTo-Json -Depth 100 | Out-File -FilePath $filepath -Force
96109

97110
# Stop the function app
@@ -100,4 +113,4 @@ if ($process -ne $null) {
100113
Stop-Process -Id $process.Id
101114
}
102115

103-
popd
116+
cd $currentDirectory
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
### This add the GitHub Codespaces capability to your local.settings.json
2+
Param(
3+
[switch]
4+
[Parameter(Mandatory=$false)]
5+
$Help
6+
)
7+
8+
function Show-Usage {
9+
Write-Output "
10+
Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) [-Help]
11+
12+
Options:
13+
-Help: Show this message.
14+
15+
"
16+
17+
Exit 0
18+
}
19+
20+
# Show usage
21+
if ($Help -eq $true) {
22+
Show-Usage
23+
Exit 0
24+
}
25+
26+
function Get-CodespaceUrl {
27+
param (
28+
[string] $CodespaceName
29+
)
30+
31+
# $codespaceUrl = "https://$($CodespaceName)-7071.githubpreview.dev/api"
32+
$codespaceUrl = "https://$($CodespaceName)-7071.preview.app.github.dev/api"
33+
34+
return $codespaceUrl
35+
}
36+
37+
# Get .csproj files
38+
$csprojs = Get-ChildItem -Path $env:CODESPACE_VSCODE_FOLDER -Filter *.csproj -Recurse
39+
40+
# Get local.settings.json files
41+
$localSettingsJsons = @()
42+
$csprojs | ForEach-Object {
43+
$isInProcFunctionApp = $(Get-Content -Path $_.FullName -Raw) -like '*Microsoft.NET.Sdk.Functions*'
44+
$isOutOfProcFunctionApp = $(Get-Content -Path $_.FullName -Raw) -like '*Microsoft.Azure.Functions.Worker.Sdk*'
45+
$isFunctionApp = ($isInProcFunctionApp -eq $true) -or ($isOutOfProcFunctionApp -eq $true)
46+
if ($isFunctionApp -eq $false) {
47+
return
48+
}
49+
50+
if ($(Test-Path -Path "$($_.Directory.FullName)/local.settings.json") -eq $true) {
51+
$localSettingsJsons += Get-ChildItem -Path $_.Directory.FullName -Filter local.settings.json
52+
53+
return
54+
}
55+
56+
if ($(Test-Path -Path "$($_.Directory.FullName)/local.settings.sample.json") -eq $true) {
57+
Copy-Item -Path "$($_.Directory.FullName)/local.settings.sample.json" -Destination "$($_.Directory.FullName)/local.settings.json"
58+
$localSettingsJsons += Get-ChildItem -Path $_.Directory.FullName -Filter local.settings.json
59+
60+
return
61+
}
62+
63+
$localSettingsJson = @{ IsEncrypted = $false; Values = @{ AzureWebJobsStorage = "UseDevelopmentStorage=true"; FUNCTIONS_WORKER_RUNTIME = "dotnet"; } }
64+
if ($isOutOfProcFunctionApp -eq $true) {
65+
$localSettingsJson.Values.FUNCTIONS_WORKER_RUNTIME = "dotnet-isolated"
66+
}
67+
68+
$localSettingsJson | `
69+
ConvertTo-Json -Depth 10 | `
70+
Out-File -FilePath "$($_.Directory.FullName)/local.settings.json" -Force
71+
$localSettingsJsons += Get-ChildItem -Path $_.Directory.FullName -Filter local.settings.json
72+
}
73+
74+
# Update local.settings.json files
75+
$localSettingsJsons | ForEach-Object {
76+
# Get the app settings details.
77+
$appSettings = Get-Content -Path $_.FullName | ConvertFrom-Json
78+
79+
# Add OpenApi__ForceHttps to local.settings.json.
80+
if ($appSettings.Values.OpenApi__ForceHttps -eq $null) {
81+
$appSettings.Values | Add-Member -NotePropertyName OpenApi__ForceHttps -NotePropertyValue "true"
82+
} else {
83+
$appSettings.Values.OpenApi__ForceHttps = "true"
84+
}
85+
86+
# Add OpenApi__RunOnCodespaces to local.settings.json.
87+
if ($appSettings.Values.OpenApi__RunOnCodespaces -eq $null) {
88+
$appSettings.Values | Add-Member -NotePropertyName OpenApi__RunOnCodespaces -NotePropertyValue "true"
89+
} else {
90+
$appSettings.Values.OpenApi__RunOnCodespaces = "true"
91+
}
92+
93+
# Add OpenApi__HostNames to local.settings.json.
94+
$url = Get-CodespaceUrl -CodespaceName $env:CODESPACE_NAME
95+
if ($appSettings.Values.OpenApi__HostNames -eq $null) {
96+
$appSettings.Values | Add-Member -NotePropertyName OpenApi__HostNames -NotePropertyValue $url
97+
} else {
98+
$hostNames = $appSettings.Values.OpenApi__HostNames -split ","
99+
$hostNames = [System.Collections.ArrayList]$hostNames
100+
101+
if ($url -ne $null) {
102+
$hostNames.Remove($url)
103+
}
104+
$hostNames.Insert(0, $url)
105+
106+
$appSettings.Values.OpenApi__HostNames = $($hostNames -join ",").Trim(',')
107+
}
108+
109+
# Overwrite the existing local.settings.json
110+
$appSettings | ConvertTo-Json -Depth 100 | Out-File -Path $_.FullName -Force
111+
}

0 commit comments

Comments
 (0)