Skip to content

Commit

Permalink
dan/per-11119-add-rebac-native-support-for-dotnet-sdk (#31)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
danyi1212 authored Dec 15, 2024
1 parent 4544aee commit 66a014d
Show file tree
Hide file tree
Showing 23 changed files with 65,484 additions and 5,695 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.30.3",
"commands": [
"dotnet-csharpier"
],
"rollForward": false
}
}
}
29 changes: 12 additions & 17 deletions .github/workflows/dotnet-sdk-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ jobs:
test-dotnet-sdk:
runs-on: ubuntu-latest
timeout-minutes: 15
services:
pdp:
image: permitio/pdp-v2:latest
ports:
- 7766:7000
env:
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
PDP_DEBUG: true
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -16,29 +24,16 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore dependencies
working-directory: ./src/permit
run: dotnet restore

- name: Insert Token to tests file by secret API key
run: |
sed -i 's/private string testToken = "";/private string testToken = "${{ secrets.PERMIT_API_KEY }}";/' ./tests/PermitTests/PermitClientTests.cs
cat ./tests/PermitTests/PermitClientTests.cs
- name: Install Docker
uses: docker-practice/actions-setup-docker@master

- name: Run local PDP
env:
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
PDP_DEBUG: true
run: docker run -d -p 7766:7000 permitio/pdp-v2:latest

- name: Run Tests
working-directory: ./tests/PermitTests
env:
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
run: dotnet test

# Job for building and publishing the NuGet package
Expand All @@ -54,7 +49,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore dependencies
working-directory: ./src/permit
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/generate-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Generate SDK and Open PR

on:
workflow_dispatch:
schedule:
- cron: '0 12 * * 0' # Runs every Sunday at 12:00 UTC


jobs:
generate-sdk:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Run SDK generation script
run: generate_openapi.sh

- name: Check for changes
id: check_changes
run: |
git diff --exit-code || echo "changes"
- name: Commit changes
if: steps.check_changes.outputs.changes == 'changes'
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git checkout -b feat/sdk-update-$(date +'%Y%m%d')
git add .
git commit -m "Update SDK from OpenAPI specs"
- name: Push changes to a new branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin feat/sdk-update-$(date +'%Y%m%d')
- name: Create a pull request
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: sdk-update-$(date +'%Y%m%d')
title: "OpenAPI SDK Update"
body: "This PR updates the SDK based on the latest OpenAPI specifications."

- name: Output PR URL
if: steps.create_pr.outputs.pull-request-url != ''
run: |
echo "Pull Request URL: ${{ steps.create_pr.outputs.pull-request-url }}"
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Run tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-dotnet-sdk:
runs-on: ubuntu-latest
timeout-minutes: 15
services:
pdp:
image: permitio/pdp-v2:latest
ports:
- 7766:7000
env:
PDP_API_KEY: ${{ secrets.PERMIT_API_KEY }}
PDP_DEBUG: true
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.x
- name: Restore dependencies
working-directory: ./src/permit
run: dotnet restore


- name: Run Tests
working-directory: ./tests/PermitTests
env:
PERMIT_API_KEY: ${{ secrets.PERMIT_API_KEY }}
run: dotnet test
2 changes: 1 addition & 1 deletion examples/PermitOnboardingApp/PermitOnboardingApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions generate_openapi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
echo "Downloading OpenAPI schema files"
curl https://api.permit.io/v2/openapi.json -o openapi.json
curl https://pdp-api.permit.io/openapi.json -o pdp-openapi.json

echo "Transforming OpenAPI union types to simple types"
python transform_openapi.py openapi.json openapi.json
python transform_openapi.py pdp-openapi.json pdp-openapi.json

echo "Generating OpenAPI client"
npm run update-api
npm run update-pdp-api

echo "Fixing status code checks"
sed -i '' -f update_status_check.sed ./src/permit/PermitOpenAPI.cs
sed -i '' -f update_status_check.sed ./src/permit/PermitPDPOpenAPI.cs

echo "Done"
4 changes: 2 additions & 2 deletions nswag-pdp.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"runtime": "Net70",
"runtime": "Net90",
"defaultVariables": "Configuration=Debug",
"documentGenerator": {
"fromDocument": {
Expand All @@ -8,6 +8,7 @@
},
"codeGenerators": {
"openApiToCSharpClient": {
"output": "./src/permit/PermitPDPOpenAPI.cs",
"generateClientInterfaces": false,
"exceptionClass": "PermitApiException",
"useBaseUrl": true,
Expand All @@ -18,7 +19,6 @@
"className": "PermitClient",
"operationGenerationMode": "SingleClientFromOperationId",
"namespace": "PermitSDK.PDP.OpenAPI",
"output": "src/permit/PermitPDPOpenAPI.cs",
"classStyle": "poco",
"generateOptionalParameters": true,
"generateOptionalPropertiesAsNullable": true,
Expand Down
16 changes: 12 additions & 4 deletions nswag.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"runtime": "Net60",
"runtime": "Net90",
"defaultVariables": "Configuration=Debug",
"documentGenerator": {
"fromDocument": {
Expand All @@ -18,11 +18,19 @@
"className": "PermitClient",
"operationGenerationMode": "SingleClientFromOperationId",
"namespace": "PermitSDK.OpenAPI",
"output": "src/permit/PermitOpenAPI.cs",
"output": "./src/permit/PermitOpenAPI.cs",
"classStyle": "poco",
"generateOptionalParameters": true,
"generateOptionalPropertiesAsNullable": true,
"generateNullableReferenceTypes": true
"generateNullableReferenceTypes": true,
"nullableReferenceTypes": true,
"requiredPropertiesMustBeDefined": false,
"generateNullableProperties": true,
"generateResponseClasses": false,
"responseClass": "SwaggerResponse",
"generateContractsOutput": true,
"contractsOutputFilePath": "./src/permit/PermitOpenAPIModels.cs",
"contractsNamespace": "PermitSDK.OpenAPI.Models"
}
}
}
}
32,142 changes: 32,141 additions & 1 deletion openapi.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install",
"update-openapi.json": "curl https://api.permit.io/v2/openapi.json -o openapi.json",
"update-api": "nswag run nswag.json",
"update-status-check": "pwd; sed -i -f update_status_check.sed PermitOpenAPI.cs",
"update-pdp-openapi": "curl https://pdp-api.permit.io/openapi.json -o pdp-openapi.json",
"update-pdp-api": "nswag run nswag-pdp.json",
"update-status-check-pdp": "pwd; sed -i -f update_status_check.sed PermitPDPOpenAPI.cs"
"update-pdp-api": "nswag run nswag-pdp.json"
},
"lint-staged": {
"*.cs": "dotnet csharpier "
Expand All @@ -32,6 +28,6 @@
"lint-staged": "^12.2.2"
},
"dependencies": {
"nswag": "^13.1.0"
"nswag": "^14.2.0"
}
}
2,483 changes: 2,482 additions & 1 deletion pdp-openapi.json

Large diffs are not rendered by default.

Loading

0 comments on commit 66a014d

Please sign in to comment.