Skip to content

Commit 66a014d

Browse files
authored
dan/per-11119-add-rebac-native-support-for-dotnet-sdk (#31)
* Changed .net to 9 * Changed test token to env variable * Changed OpenAPI generation flow * Added workflow to generate OpenAPI specs * Added tests on PR * Added skip commit when no changes * Fixed tests * Added kwarg based bypass to OpenAPI calls * Added relationship tuple APIs * Changed SyncUser to use Replace_userAsync (aka PUT method) * Added docs to APIs * Changed test sleep to 10 sec * Fixed PDP run command * Fixed PDP run command
1 parent 4544aee commit 66a014d

23 files changed

+65484
-5695
lines changed

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"csharpier": {
6+
"version": "0.30.3",
7+
"commands": [
8+
"dotnet-csharpier"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/dotnet-sdk-publish.yml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ jobs:
88
test-dotnet-sdk:
99
runs-on: ubuntu-latest
1010
timeout-minutes: 15
11+
services:
12+
pdp:
13+
image: permitio/pdp-v2:latest
14+
ports:
15+
- 7766:7000
16+
env:
17+
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
18+
PDP_DEBUG: true
1119
steps:
1220
- name: Checkout code
1321
uses: actions/checkout@v3
@@ -16,29 +24,16 @@ jobs:
1624
uses: actions/setup-dotnet@v4
1725
with:
1826
dotnet-version: |
19-
8.0.x
27+
9.0.x
2028
2129
- name: Restore dependencies
2230
working-directory: ./src/permit
2331
run: dotnet restore
2432

25-
- name: Insert Token to tests file by secret API key
26-
run: |
27-
sed -i 's/private string testToken = "";/private string testToken = "${{ secrets.PERMIT_API_KEY }}";/' ./tests/PermitTests/PermitClientTests.cs
28-
cat ./tests/PermitTests/PermitClientTests.cs
29-
30-
- name: Install Docker
31-
uses: docker-practice/actions-setup-docker@master
32-
33-
- name: Run local PDP
34-
env:
35-
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
36-
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
37-
PDP_DEBUG: true
38-
run: docker run -d -p 7766:7000 permitio/pdp-v2:latest
39-
4033
- name: Run Tests
4134
working-directory: ./tests/PermitTests
35+
env:
36+
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
4237
run: dotnet test
4338

4439
# Job for building and publishing the NuGet package
@@ -54,7 +49,7 @@ jobs:
5449
uses: actions/setup-dotnet@v4
5550
with:
5651
dotnet-version: |
57-
8.0.x
52+
9.0.x
5853
5954
- name: Restore dependencies
6055
working-directory: ./src/permit
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Generate SDK and Open PR
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 12 * * 0' # Runs every Sunday at 12:00 UTC
7+
8+
9+
jobs:
10+
generate-sdk:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.11'
21+
22+
- name: Run SDK generation script
23+
run: generate_openapi.sh
24+
25+
- name: Check for changes
26+
id: check_changes
27+
run: |
28+
git diff --exit-code || echo "changes"
29+
30+
- name: Commit changes
31+
if: steps.check_changes.outputs.changes == 'changes'
32+
run: |
33+
git config user.name "github-actions"
34+
git config user.email "[email protected]"
35+
git checkout -b feat/sdk-update-$(date +'%Y%m%d')
36+
git add .
37+
git commit -m "Update SDK from OpenAPI specs"
38+
39+
- name: Push changes to a new branch
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
git push origin feat/sdk-update-$(date +'%Y%m%d')
44+
45+
- name: Create a pull request
46+
id: create_pr
47+
uses: peter-evans/create-pull-request@v7
48+
with:
49+
token: ${{ secrets.GITHUB_TOKEN }}
50+
branch: sdk-update-$(date +'%Y%m%d')
51+
title: "OpenAPI SDK Update"
52+
body: "This PR updates the SDK based on the latest OpenAPI specifications."
53+
54+
- name: Output PR URL
55+
if: steps.create_pr.outputs.pull-request-url != ''
56+
run: |
57+
echo "Pull Request URL: ${{ steps.create_pr.outputs.pull-request-url }}"
58+

.github/workflows/tests.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test-dotnet-sdk:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 15
15+
services:
16+
pdp:
17+
image: permitio/pdp-v2:latest
18+
ports:
19+
- 7766:7000
20+
env:
21+
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
22+
PDP_DEBUG: true
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Setup .NET Core SDK
28+
uses: actions/setup-dotnet@v4
29+
with:
30+
dotnet-version: |
31+
9.0.x
32+
33+
- name: Restore dependencies
34+
working-directory: ./src/permit
35+
run: dotnet restore
36+
37+
38+
- name: Run Tests
39+
working-directory: ./tests/PermitTests
40+
env:
41+
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
42+
run: dotnet test

examples/PermitOnboardingApp/PermitOnboardingApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

generate_openapi.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo "Downloading OpenAPI schema files"
2+
curl https://api.permit.io/v2/openapi.json -o openapi.json
3+
curl https://pdp-api.permit.io/openapi.json -o pdp-openapi.json
4+
5+
echo "Transforming OpenAPI union types to simple types"
6+
python transform_openapi.py openapi.json openapi.json
7+
python transform_openapi.py pdp-openapi.json pdp-openapi.json
8+
9+
echo "Generating OpenAPI client"
10+
npm run update-api
11+
npm run update-pdp-api
12+
13+
echo "Fixing status code checks"
14+
sed -i '' -f update_status_check.sed ./src/permit/PermitOpenAPI.cs
15+
sed -i '' -f update_status_check.sed ./src/permit/PermitPDPOpenAPI.cs
16+
17+
echo "Done"

nswag-pdp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"runtime": "Net70",
2+
"runtime": "Net90",
33
"defaultVariables": "Configuration=Debug",
44
"documentGenerator": {
55
"fromDocument": {
@@ -8,6 +8,7 @@
88
},
99
"codeGenerators": {
1010
"openApiToCSharpClient": {
11+
"output": "./src/permit/PermitPDPOpenAPI.cs",
1112
"generateClientInterfaces": false,
1213
"exceptionClass": "PermitApiException",
1314
"useBaseUrl": true,
@@ -18,7 +19,6 @@
1819
"className": "PermitClient",
1920
"operationGenerationMode": "SingleClientFromOperationId",
2021
"namespace": "PermitSDK.PDP.OpenAPI",
21-
"output": "src/permit/PermitPDPOpenAPI.cs",
2222
"classStyle": "poco",
2323
"generateOptionalParameters": true,
2424
"generateOptionalPropertiesAsNullable": true,

nswag.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"runtime": "Net60",
2+
"runtime": "Net90",
33
"defaultVariables": "Configuration=Debug",
44
"documentGenerator": {
55
"fromDocument": {
@@ -18,11 +18,19 @@
1818
"className": "PermitClient",
1919
"operationGenerationMode": "SingleClientFromOperationId",
2020
"namespace": "PermitSDK.OpenAPI",
21-
"output": "src/permit/PermitOpenAPI.cs",
21+
"output": "./src/permit/PermitOpenAPI.cs",
2222
"classStyle": "poco",
2323
"generateOptionalParameters": true,
2424
"generateOptionalPropertiesAsNullable": true,
25-
"generateNullableReferenceTypes": true
25+
"generateNullableReferenceTypes": true,
26+
"nullableReferenceTypes": true,
27+
"requiredPropertiesMustBeDefined": false,
28+
"generateNullableProperties": true,
29+
"generateResponseClasses": false,
30+
"responseClass": "SwaggerResponse",
31+
"generateContractsOutput": true,
32+
"contractsOutputFilePath": "./src/permit/PermitOpenAPIModels.cs",
33+
"contractsNamespace": "PermitSDK.OpenAPI.Models"
2634
}
2735
}
28-
}
36+
}

openapi.json

Lines changed: 32141 additions & 1 deletion
Large diffs are not rendered by default.

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)