Skip to content

Commit

Permalink
Merge pull request #40 from openfga/add-example
Browse files Browse the repository at this point in the history
chore: add example java/kotlin projects
  • Loading branch information
rhamzeh authored Jan 10, 2024
2 parents e973561 + 500a2af commit 29a70ae
Show file tree
Hide file tree
Showing 22 changed files with 1,275 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ By submitting an issue to this repository, you agree to the terms within the [Op
> A clear and concise description of what you expected to happen.
### Additional context
> Add any other context about the problem here.
> Add any other context about the problem here.
15 changes: 15 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ docs/WriteAuthorizationModelResponse.md
docs/WriteRequest.md
docs/WriteRequestDeletes.md
docs/WriteRequestWrites.md
example/Makefile
example/README.md
example/example1/README.md
example/example1/build.gradle
example/example1/gradle.properties
example/example1/gradle/wrapper/gradle-wrapper.jar
example/example1/gradle/wrapper/gradle-wrapper.properties
example/example1/gradlew
example/example1/settings.gradle
example/example1/src/main/java/dev/openfga/sdk/example/Example1.java
example/example1/src/main/kotlin/dev/openfga/sdk/example/KotlinExample1.kt
example/example1/src/main/resources/example1-auth-model.json
gradle.properties
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
Expand Down Expand Up @@ -235,8 +247,11 @@ src/main/java/dev/openfga/sdk/util/StringUtil.java
src/main/java/dev/openfga/sdk/util/Validation.java
src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java
src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java
src/test-integration/java/dev/openfga/sdk/example/Example1.java
src/test-integration/java/dev/openfga/sdk/example/ExampleTest.java
src/test-integration/java/package-info.java
src/test-integration/resources/auth-model.json
src/test-integration/resources/example1-auth-model.json
src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java
src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java
src/test/java/dev/openfga/sdk/api/auth/OAuth2ClientTest.java
Expand Down
1 change: 1 addition & 0 deletions docs/GetStoreResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
|**name** | **String** | | |
|**createdAt** | **OffsetDateTime** | | |
|**updatedAt** | **OffsetDateTime** | | |
|**deletedAt** | **OffsetDateTime** | | [optional] |



2 changes: 1 addition & 1 deletion docs/Store.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|**name** | **String** | | |
|**createdAt** | **OffsetDateTime** | | |
|**updatedAt** | **OffsetDateTime** | | |
|**deletedAt** | **OffsetDateTime** | | |
|**deletedAt** | **OffsetDateTime** | | [optional] |



17 changes: 17 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
all: build

project_name=example1
openfga_version=latest
language=java

build:
cd "${project_name}" && \
./gradlew -P language=$(language) build

run:
cd "${project_name}" && \
./gradlew -P language=$(language) run

run-openfga:
docker pull docker.io/openfga/openfga:${openfga_version} && \
docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run
49 changes: 49 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Examples of using the OpenFGA Java SDK

A set of Examples on how to call the OpenFGA Java SDK

### Examples
Example 1:
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access.
This example is implemented in both Java and Kotlin.


### Running the Examples

Prerequisites:
- `docker`
- `make`
- A Java Runtime Environment (JRE)

#### Run using a published SDK

Steps
1. Clone/Copy the example folder
2. Run `make` to build the project
3. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done)
4. Run `make run` to run the example

#### Run using a local unpublished SDK build

Steps
1. Build the SDK
2. In the Example project file (e.g. `build.gradle`), comment out the part that specifies the remote SDK, e.g.
```groovy
dependencies {
implementation("dev.openfga:openfga-sdk:0.3.+")
// ...etc
}
```
and replace it with one pointing to the local gradle project, e.g.
```groovy
dependencies {
// implementation("dev.openfga:openfga-sdk:0.3.+")
implementation project(path: ':')
// ...etc
}
```
3. Run `make` to build the project
4. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done)
5. Run `make run` to run the example
50 changes: 50 additions & 0 deletions example/example1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Examples of using the OpenFGA Java SDK

A set of Examples on how to call the OpenFGA Java SDK

### Examples
Example 1:
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access.
This example is implemented in both Java and Kotlin.


### Running the Examples

Prerequisites:
- `docker`
- `make`
- A Java Runtime Environment (JRE)

#### Run using a published SDK

Steps
1. Clone/Copy the example folder
2. Run `make` to build the project
3. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done)
4. Run `make run` to run the example
* This should run a Java example by default. Where implemented, it's possible to specify an alternate JVM language too, like `make run language=kotlin`.

#### Run using a local unpublished SDK build

Steps
1. Build the SDK
2. In the Example project file (e.g. `build.gradle`), comment out the part that specifies the remote SDK, e.g.
```groovy
dependencies {
implementation("dev.openfga:openfga-sdk:0.3.+")
// ...etc
}
```
and replace it with one pointing to the local gradle project, e.g.
```groovy
dependencies {
// implementation("dev.openfga:openfga-sdk:0.3.+")
implementation project(path: ':')
// ...etc
}
```
3. Run `make` to build the project
4. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done)
5. Run `make run` to run the example
77 changes: 77 additions & 0 deletions example/example1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'application'
id 'com.diffplug.spotless' version '6.23.3'
id 'org.jetbrains.kotlin.jvm' version '2.0.0-Beta2'
}

application {
switch (language) {
case 'kotlin':
mainClass = 'dev.openfga.sdk.example.KotlinExample1'
break
default:
mainClass = 'dev.openfga.sdk.example.Example1'
}
}

repositories {
mavenCentral()
}

ext {
jacksonVersion = "2.16.0"
}

dependencies {
implementation("dev.openfga:openfga-sdk:0.3.+")

// Serialization
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("org.openapitools:jackson-databind-nullable:0.2.+")

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
spotless {
// comment out below to run spotless as part of the `check` task
enforceCheck false
format 'misc', {
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
target '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // Takes an integer argument if you don't like 4
endWithNewline()
}
java {
palantirJavaFormat()
removeUnusedImports()
importOrder()
}
}

// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
tasks.register('fmt') {
dependsOn 'spotlessApply'
}

compileKotlin {
kotlinOptions {
jvmTarget = "17"
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "17"
}
}
1 change: 1 addition & 0 deletions example/example1/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language=java
Binary file not shown.
6 changes: 6 additions & 0 deletions example/example1/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 29a70ae

Please sign in to comment.