diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index f828c98..edee303 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -14,6 +14,7 @@ README.md VERSION.txt api/openapi.yaml build.gradle +docs/AbortedMessageResponse.md docs/Any.md docs/Assertion.md docs/AssertionTupleKey.md @@ -111,6 +112,7 @@ src/main/java/dev/openfga/sdk/api/client/ClientListStoresResponse.java src/main/java/dev/openfga/sdk/api/client/ClientReadAssertionsResponse.java src/main/java/dev/openfga/sdk/api/client/ClientReadAuthorizationModelResponse.java src/main/java/dev/openfga/sdk/api/client/ClientReadAuthorizationModelsResponse.java +src/main/java/dev/openfga/sdk/api/client/ClientReadChangesRequest.java src/main/java/dev/openfga/sdk/api/client/ClientReadChangesResponse.java src/main/java/dev/openfga/sdk/api/client/ClientReadRequest.java src/main/java/dev/openfga/sdk/api/client/ClientReadResponse.java @@ -123,13 +125,18 @@ src/main/java/dev/openfga/sdk/api/client/ClientWriteRequest.java src/main/java/dev/openfga/sdk/api/client/ClientWriteResponse.java src/main/java/dev/openfga/sdk/api/client/HttpRequestAttempt.java src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java +src/main/java/dev/openfga/sdk/api/configuration/AdditionalHeadersSupplier.java src/main/java/dev/openfga/sdk/api/configuration/ApiToken.java src/main/java/dev/openfga/sdk/api/configuration/BaseConfiguration.java src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientConfiguration.java +src/main/java/dev/openfga/sdk/api/configuration/ClientCreateStoreOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientCredentials.java +src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteStoreOptions.java +src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteTuplesOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java +src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java @@ -137,13 +144,17 @@ src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java +src/main/java/dev/openfga/sdk/api/configuration/ClientReadLatestAuthorizationModelOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java +src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAuthorizationModelOptions.java src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java +src/main/java/dev/openfga/sdk/api/configuration/ClientWriteTuplesOptions.java src/main/java/dev/openfga/sdk/api/configuration/Configuration.java src/main/java/dev/openfga/sdk/api/configuration/ConfigurationOverride.java src/main/java/dev/openfga/sdk/api/configuration/Credentials.java src/main/java/dev/openfga/sdk/api/configuration/CredentialsMethod.java +src/main/java/dev/openfga/sdk/api/model/AbortedMessageResponse.java src/main/java/dev/openfga/sdk/api/model/AbstractOpenApiSchema.java src/main/java/dev/openfga/sdk/api/model/Any.java src/main/java/dev/openfga/sdk/api/model/Assertion.java @@ -231,6 +242,7 @@ src/test/java/dev/openfga/sdk/api/auth/OAuth2ClientTest.java src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java src/test/java/dev/openfga/sdk/api/configuration/ClientCredentialsTest.java src/test/java/dev/openfga/sdk/api/configuration/ConfigurationTest.java +src/test/java/dev/openfga/sdk/api/model/AbortedMessageResponseTest.java src/test/java/dev/openfga/sdk/api/model/AnyTest.java src/test/java/dev/openfga/sdk/api/model/AssertionTest.java src/test/java/dev/openfga/sdk/api/model/AssertionTupleKeyTest.java diff --git a/README.md b/README.md index 0335407..679e556 100644 --- a/README.md +++ b/README.md @@ -736,6 +736,8 @@ fgaClient.writeAssertions(assertions, options).get(); ### Models +- [AbortedMessageResponse](https://github.com/openfga/java-sdk/blob/main/docs/AbortedMessageResponse.md) + - [Any](https://github.com/openfga/java-sdk/blob/main/docs/Any.md) - [Assertion](https://github.com/openfga/java-sdk/blob/main/docs/Assertion.md) diff --git a/docs/AbortedMessageResponse.md b/docs/AbortedMessageResponse.md new file mode 100644 index 0000000..e70c587 --- /dev/null +++ b/docs/AbortedMessageResponse.md @@ -0,0 +1,14 @@ + + +# AbortedMessageResponse + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +|**code** | **String** | | [optional] | +|**message** | **String** | | [optional] | + + + diff --git a/docs/OpenFgaApi.md b/docs/OpenFgaApi.md index 390227f..0406205 100644 --- a/docs/OpenFgaApi.md +++ b/docs/OpenFgaApi.md @@ -106,6 +106,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## checkWithHttpInfo @@ -187,6 +188,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -257,6 +259,7 @@ No authorization required | **201** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## createStoreWithHttpInfo @@ -336,6 +339,7 @@ No authorization required | **201** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -405,6 +409,7 @@ No authorization required | **204** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## deleteStoreWithHttpInfo @@ -483,6 +488,7 @@ No authorization required | **204** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -555,6 +561,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## expandWithHttpInfo @@ -636,6 +643,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -706,6 +714,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## getStoreWithHttpInfo @@ -785,6 +794,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -857,6 +867,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## listObjectsWithHttpInfo @@ -938,6 +949,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1010,6 +1022,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## listStoresWithHttpInfo @@ -1091,6 +1104,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1163,6 +1177,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## readWithHttpInfo @@ -1244,6 +1259,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1316,6 +1332,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## readAssertionsWithHttpInfo @@ -1397,6 +1414,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1469,6 +1487,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## readAuthorizationModelWithHttpInfo @@ -1550,6 +1569,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1624,6 +1644,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## readAuthorizationModelsWithHttpInfo @@ -1707,6 +1728,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1783,6 +1805,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## readChangesWithHttpInfo @@ -1868,6 +1891,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -1940,6 +1964,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## writeWithHttpInfo @@ -2021,6 +2046,7 @@ No authorization required | **200** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -2094,6 +2120,7 @@ No authorization required | **204** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## writeAssertionsWithHttpInfo @@ -2176,6 +2203,7 @@ No authorization required | **204** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | @@ -2248,6 +2276,7 @@ No authorization required | **201** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | ## writeAuthorizationModelWithHttpInfo @@ -2329,5 +2358,6 @@ No authorization required | **201** | A successful response. | - | | **400** | Request failed due to invalid input. | - | | **404** | Request failed due to incorrect path. | - | +| **409** | Request was aborted due a transaction conflict. | - | | **500** | Request failed due to internal server error. | - | diff --git a/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java b/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java index 9666ab8..8b48705 100644 --- a/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java +++ b/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java @@ -70,6 +70,11 @@ public OpenFgaApi(Configuration configuration, ApiClient apiClient) throws FgaIn } else { this.oAuth2Client = null; } + + var additionalHeaders = configuration.getAdditionalHeaders(); + if (additionalHeaders != null) { + apiClient.addRequestInterceptor(httpRequest -> additionalHeaders.forEach(httpRequest::setHeader)); + } } /** @@ -141,6 +146,10 @@ private HttpRequest.Builder checkRequestBuilder(String storeId, CheckRequest bod localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -218,6 +227,10 @@ private HttpRequest.Builder createStoreRequestBuilder(CreateStoreRequest body, C localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -294,6 +307,10 @@ private HttpRequest.Builder deleteStoreRequestBuilder(String storeId, Configurat localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("DELETE", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -375,6 +392,10 @@ private HttpRequest.Builder expandRequestBuilder(String storeId, ExpandRequest b localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -451,6 +472,10 @@ private HttpRequest.Builder getStoreRequestBuilder(String storeId, Configuration localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -533,6 +558,10 @@ private HttpRequest.Builder listObjectsRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -628,6 +657,10 @@ private HttpRequest.Builder listStoresRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -708,6 +741,10 @@ private HttpRequest.Builder readRequestBuilder(String storeId, ReadRequest body, localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -797,6 +834,10 @@ private HttpRequest.Builder readAssertionsRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -882,6 +923,10 @@ private HttpRequest.Builder readAuthorizationModelRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -988,6 +1033,10 @@ private HttpRequest.Builder readAuthorizationModelsRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -1095,6 +1144,10 @@ private HttpRequest.Builder readChangesRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); Duration readTimeout = configuration.getReadTimeout(); if (readTimeout != null) { @@ -1174,6 +1227,10 @@ private HttpRequest.Builder writeRequestBuilder(String storeId, WriteRequest bod localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -1273,6 +1330,10 @@ private HttpRequest.Builder writeAssertionsRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("PUT", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); @@ -1366,6 +1427,10 @@ private HttpRequest.Builder writeAuthorizationModelRequestBuilder( localVarRequestBuilder.header("Authorization", "Bearer " + accessToken); } + if (configuration.getAdditionalHeaders() != null) { + configuration.getAdditionalHeaders().forEach(localVarRequestBuilder::header); + } + try { byte[] localVarPostBody = apiClient.getObjectMapper().writeValueAsBytes(body); localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); diff --git a/src/main/java/dev/openfga/sdk/api/client/ApiClient.java b/src/main/java/dev/openfga/sdk/api/client/ApiClient.java index 89ae992..8fa1c79 100644 --- a/src/main/java/dev/openfga/sdk/api/client/ApiClient.java +++ b/src/main/java/dev/openfga/sdk/api/client/ApiClient.java @@ -318,6 +318,19 @@ public ApiClient setRequestInterceptor(Consumer interceptor return this; } + /** + * Add a custom request interceptor. This interceptor will be run after any + * other interceptor(s) already in place. + * + *

For details on request interceptors, see {@link ApiClient#setRequestInterceptor(Consumer)}

+ * + * @param interceptor A function invoked before creating each request. A value + * of null resets the interceptor to a no-op. + */ + public void addRequestInterceptor(Consumer interceptor) { + this.interceptor = this.interceptor != null ? this.interceptor.andThen(interceptor) : interceptor; + } + /** * Get the custom interceptor. * diff --git a/src/main/java/dev/openfga/sdk/api/client/ClientReadChangesRequest.java b/src/main/java/dev/openfga/sdk/api/client/ClientReadChangesRequest.java new file mode 100644 index 0000000..30fb60f --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/client/ClientReadChangesRequest.java @@ -0,0 +1,26 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.client; + +public class ClientReadChangesRequest { + private String type; + + public ClientReadChangesRequest type(String type) { + this.type = type; + return this; + } + + public String getType() { + return type; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java b/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java index 0f301a5..b5f9bbe 100644 --- a/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java +++ b/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java @@ -13,12 +13,14 @@ package dev.openfga.sdk.api.client; import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace; +import static java.util.UUID.randomUUID; import dev.openfga.sdk.api.*; import dev.openfga.sdk.api.configuration.*; import dev.openfga.sdk.api.model.*; import dev.openfga.sdk.errors.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.concurrent.*; import java.util.function.Consumer; @@ -73,10 +75,14 @@ public CompletableFuture listStores() throws FgaInvali return call(() -> api.listStores(null, null)).thenApply(ClientListStoresResponse::new); } + /** + * ListStores - Get a paginated list of stores. + */ public CompletableFuture listStores(ClientListStoresOptions options) throws FgaInvalidParameterException { configuration.assertValid(); - return call(() -> api.listStores(options.getPageSize(), options.getContinuationToken())) + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.listStores(options.getPageSize(), options.getContinuationToken(), overrides)) .thenApply(ClientListStoresResponse::new); } @@ -85,8 +91,17 @@ public CompletableFuture listStores(ClientListStoresOp */ public CompletableFuture createStore(CreateStoreRequest request) throws FgaInvalidParameterException { + return createStore(request, null); + } + + /** + * CreateStore - Initialize a store + */ + public CompletableFuture createStore( + CreateStoreRequest request, ClientCreateStoreOptions options) throws FgaInvalidParameterException { configuration.assertValid(); - return call(() -> api.createStore(request)).thenApply(ClientCreateStoreResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.createStore(request, overrides)).thenApply(ClientCreateStoreResponse::new); } /** @@ -94,9 +109,19 @@ public CompletableFuture createStore(CreateStoreReque * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace */ public CompletableFuture getStore() throws FgaInvalidParameterException { + return getStore(null); + } + + /** + * GetStore - Get information about the current store. + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture getStore(ClientGetStoreOptions options) + throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); - return call(() -> api.getStore(storeId)).thenApply(ClientGetStoreResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.getStore(storeId, overrides)).thenApply(ClientGetStoreResponse::new); } /** @@ -105,9 +130,20 @@ public CompletableFuture getStore() throws FgaInvalidPar * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace */ public CompletableFuture deleteStore() throws FgaInvalidParameterException { + return deleteStore(null); + } + + /** + * DeleteStore - Delete a store + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture deleteStore(ClientDeleteStoreOptions options) + throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); - return call(() -> api.deleteStore(storeId)).thenApply(ClientDeleteStoreResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.deleteStore(storeId, overrides)).thenApply(ClientDeleteStoreResponse::new); } /* ********************** @@ -146,7 +182,9 @@ public CompletableFuture readAuthorizatio pageSize = null; } - return call(() -> api.readAuthorizationModels(storeId, pageSize, continuationToken)) + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.readAuthorizationModels(storeId, pageSize, continuationToken, overrides)) .thenApply(ClientReadAuthorizationModelsResponse::new); } @@ -157,9 +195,21 @@ public CompletableFuture readAuthorizatio */ public CompletableFuture writeAuthorizationModel( WriteAuthorizationModelRequest request) throws FgaInvalidParameterException { + return writeAuthorizationModel(request, null); + } + + /** + * WriteAuthorizationModel - Create a new version of the authorization model + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture writeAuthorizationModel( + WriteAuthorizationModelRequest request, ClientWriteAuthorizationModelOptions options) + throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); - return call(() -> api.writeAuthorizationModel(storeId, request)) + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.writeAuthorizationModel(storeId, request, overrides)) .thenApply(ClientWriteAuthorizationModelResponse::new); } @@ -187,7 +237,8 @@ public CompletableFuture readAuthorization configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); String authorizationModelId = options.getAuthorizationModelIdChecked(); - return call(() -> api.readAuthorizationModel(storeId, authorizationModelId)) + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.readAuthorizationModel(storeId, authorizationModelId, overrides)) .thenApply(ClientReadAuthorizationModelResponse::new); } @@ -198,9 +249,20 @@ public CompletableFuture readAuthorization */ public CompletableFuture readLatestAuthorizationModel() throws FgaInvalidParameterException { + return readLatestAuthorizationModel(null); + } + + /** + * ReadLatestAuthorizationModel - Read the latest authorization model for the current store + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture readLatestAuthorizationModel( + ClientReadLatestAuthorizationModelOptions options) throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); - return call(() -> api.readAuthorizationModels(storeId, 1, null)) + var overrides = new ConfigurationOverride().addHeaders(options); + return call(() -> api.readAuthorizationModels(storeId, 1, null, overrides)) .thenApply(ClientReadAuthorizationModelResponse::latestOf); } @@ -213,12 +275,25 @@ public CompletableFuture readLatestAuthori * * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace */ - public CompletableFuture readChanges(ClientReadChangesOptions options) + public CompletableFuture readChanges(ClientReadChangesRequest request) + throws FgaInvalidParameterException { + return readChanges(request, null); + } + + /** + * Read Changes - Read the list of historical relationship tuple writes and deletes + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture readChanges( + ClientReadChangesRequest request, ClientReadChangesOptions readChangesOptions) throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); + var options = readChangesOptions != null ? readChangesOptions : new ClientReadChangesOptions(); + var overrides = new ConfigurationOverride().addHeaders(options); return call(() -> api.readChanges( - storeId, options.getType(), options.getPageSize(), options.getContinuationToken())) + storeId, request.getType(), options.getPageSize(), options.getContinuationToken(), overrides)) .thenApply(ClientReadChangesResponse::new); } @@ -255,7 +330,9 @@ public CompletableFuture read(ClientReadRequest request, Cli body.pageSize(options.getPageSize()).continuationToken(options.getContinuationToken()); } - return call(() -> api.read(storeId, body)).thenApply(ClientReadResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.read(storeId, body, overrides)).thenApply(ClientReadResponse::new); } /** @@ -307,14 +384,26 @@ private CompletableFuture writeNonTransaction( body.authorizationModelId(authorizationModelId); } - return call(() -> api.write(storeId, body)).thenApply(ClientWriteResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.write(storeId, body, overrides)).thenApply(ClientWriteResponse::new); } private CompletableFuture writeTransactions( - String storeId, ClientWriteRequest request, ClientWriteOptions options) { + String storeId, ClientWriteRequest request, ClientWriteOptions writeOptions) { + + var options = writeOptions != null + ? writeOptions + : new ClientWriteOptions().transactionChunkSize(DEFAULT_MAX_METHOD_PARALLEL_REQS); - int chunkSize = options == null ? DEFAULT_MAX_METHOD_PARALLEL_REQS : options.getTransactionChunkSize(); + if (options.getAdditionalHeaders() == null) { + options.additionalHeaders(new HashMap<>()); + } + options.getAdditionalHeaders().putIfAbsent(CLIENT_METHOD_HEADER, "Write"); + options.getAdditionalHeaders() + .putIfAbsent(CLIENT_BULK_REQUEST_ID_HEADER, randomUUID().toString()); + int chunkSize = options.getTransactionChunkSize(); var writeTransactions = chunksOf(chunkSize, request.getWrites()).map(ClientWriteRequest::ofWrites); var deleteTransactions = chunksOf(chunkSize, request.getDeletes()).map(ClientWriteRequest::ofDeletes); @@ -359,6 +448,16 @@ private Stream> chunksOf(int chunkSize, List list) { */ public CompletableFuture writeTuples(List tupleKeys) throws FgaInvalidParameterException { + return writeTuples(tupleKeys, null); + } + + /** + * WriteTuples - Utility method to write tuples, wraps Write + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture writeTuples( + List tupleKeys, ClientWriteTuplesOptions options) throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); @@ -371,7 +470,9 @@ public CompletableFuture writeTuples(List t body.authorizationModelId(authorizationModelId); } - return call(() -> api.write(storeId, body)).thenApply(ClientWriteResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.write(storeId, body, overrides)).thenApply(ClientWriteResponse::new); } /** @@ -381,6 +482,17 @@ public CompletableFuture writeTuples(List t */ public CompletableFuture deleteTuples(List tupleKeys) throws FgaInvalidParameterException { + return deleteTuples(tupleKeys, null); + } + + /** + * DeleteTuples - Utility method to delete tuples, wraps Write + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture deleteTuples( + List tupleKeys, ClientDeleteTuplesOptions options) + throws FgaInvalidParameterException { configuration.assertValid(); String storeId = configuration.getStoreIdChecked(); @@ -393,7 +505,9 @@ public CompletableFuture deleteTuples(List api.write(storeId, body)).thenApply(ClientWriteResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.write(storeId, body, overrides)).thenApply(ClientWriteResponse::new); } /* ********************** @@ -438,7 +552,19 @@ public CompletableFuture check(ClientCheckRequest request, body.authorizationModelId(authorizationModelId); } - return call(() -> api.check(storeId, body)).thenApply(ClientCheckResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.check(storeId, body, overrides)).thenApply(ClientCheckResponse::new); + } + + /** + * BatchCheck - Run a set of checks (evaluates) + * + * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace + */ + public CompletableFuture> batchCheck(List requests) + throws FgaInvalidParameterException { + return batchCheck(requests, null); } /** @@ -447,10 +573,21 @@ public CompletableFuture check(ClientCheckRequest request, * @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace */ public CompletableFuture> batchCheck( - List requests, ClientBatchCheckOptions options) throws FgaInvalidParameterException { + List requests, ClientBatchCheckOptions batchCheckOptions) + throws FgaInvalidParameterException { configuration.assertValid(); configuration.assertValidStoreId(); + var options = batchCheckOptions != null + ? batchCheckOptions + : new ClientBatchCheckOptions().maxParallelRequests(DEFAULT_MAX_METHOD_PARALLEL_REQS); + if (options.getAdditionalHeaders() == null) { + options.additionalHeaders(new HashMap<>()); + } + options.getAdditionalHeaders().putIfAbsent(CLIENT_METHOD_HEADER, "BatchCheck"); + options.getAdditionalHeaders() + .putIfAbsent(CLIENT_BULK_REQUEST_ID_HEADER, randomUUID().toString()); + int maxParallelRequests = options.getMaxParallelRequests() != null ? options.getMaxParallelRequests() : DEFAULT_MAX_METHOD_PARALLEL_REQS; @@ -510,7 +647,9 @@ public CompletableFuture expand(ClientExpandRequest reques body.authorizationModelId(authorizationModelId); } - return call(() -> api.expand(storeId, body)).thenApply(ClientExpandResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.expand(storeId, body, overrides)).thenApply(ClientExpandResponse::new); } /** @@ -551,20 +690,40 @@ public CompletableFuture listObjects( body.authorizationModelId(authorizationModelId); } - return call(() -> api.listObjects(storeId, body)).thenApply(ClientListObjectsResponse::new); + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.listObjects(storeId, body, overrides)).thenApply(ClientListObjectsResponse::new); + } + + /** + * ListRelations - List allowed relations a user has with an object (evaluates) + */ + public CompletableFuture listRelations(ClientListRelationsRequest request) + throws FgaInvalidParameterException { + return listRelations(request, null); } - /* + /** * ListRelations - List allowed relations a user has with an object (evaluates) */ public CompletableFuture listRelations( - ClientListRelationsRequest request, ClientListRelationsOptions options) + ClientListRelationsRequest request, ClientListRelationsOptions listRelationsOptions) throws FgaInvalidParameterException { if (request.getRelations() == null || request.getRelations().isEmpty()) { throw new FgaInvalidParameterException( "At least 1 relation to check has to be provided when calling ListRelations"); } + var options = listRelationsOptions != null + ? listRelationsOptions + : new ClientListRelationsOptions().maxParallelRequests(DEFAULT_MAX_METHOD_PARALLEL_REQS); + if (options.getAdditionalHeaders() == null) { + options.additionalHeaders(new HashMap<>()); + } + options.getAdditionalHeaders().putIfAbsent(CLIENT_METHOD_HEADER, "ListRelations"); + options.getAdditionalHeaders() + .putIfAbsent(CLIENT_BULK_REQUEST_ID_HEADER, randomUUID().toString()); + var batchCheckRequests = request.getRelations().stream() .map(relation -> new ClientCheckRequest() .user(request.getUser()) @@ -572,7 +731,7 @@ public CompletableFuture listRelations( ._object(request.getObject())) .collect(Collectors.toList()); - return batchCheck(batchCheckRequests, options.asClientBatchCheckOptions()) + return this.batchCheck(batchCheckRequests, options.asClientBatchCheckOptions()) .thenCompose(responses -> call(() -> ClientListRelationsResponse.fromBatchCheckResponses(responses))); } @@ -606,7 +765,9 @@ public CompletableFuture readAssertions(ClientRead authorizationModelId = configuration.getAuthorizationModelIdChecked(); } - return call(() -> api.readAssertions(storeId, authorizationModelId)) + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.readAssertions(storeId, authorizationModelId, overrides)) .thenApply(ClientReadAssertionsResponse::new); } @@ -640,7 +801,9 @@ public CompletableFuture writeAssertions( WriteAssertionsRequest body = new WriteAssertionsRequest().assertions(ClientAssertion.asAssertions(assertions)); - return call(() -> api.writeAssertions(storeId, authorizationModelId, body)) + var overrides = new ConfigurationOverride().addHeaders(options); + + return call(() -> api.writeAssertions(storeId, authorizationModelId, body, overrides)) .thenApply(ClientWriteAssertionsResponse::new); } diff --git a/src/main/java/dev/openfga/sdk/api/configuration/AdditionalHeadersSupplier.java b/src/main/java/dev/openfga/sdk/api/configuration/AdditionalHeadersSupplier.java new file mode 100644 index 0000000..c500d72 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/AdditionalHeadersSupplier.java @@ -0,0 +1,19 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public interface AdditionalHeadersSupplier { + Map getAdditionalHeaders(); +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java index abc4a80..5ba3f3d 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java @@ -12,10 +12,23 @@ package dev.openfga.sdk.api.configuration; -public class ClientBatchCheckOptions { +import java.util.Map; + +public class ClientBatchCheckOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer maxParallelRequests; private String authorizationModelId; + public ClientBatchCheckOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientBatchCheckOptions maxParallelRequests(Integer maxParallelRequests) { this.maxParallelRequests = maxParallelRequests; return this; @@ -35,6 +48,6 @@ public String getAuthorizationModelId() { } public ClientCheckOptions asClientCheckOptions() { - return new ClientCheckOptions().authorizationModelId(authorizationModelId); + return new ClientCheckOptions().additionalHeaders(additionalHeaders).authorizationModelId(authorizationModelId); } } diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java index b69a4cf..1b0e374 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java @@ -12,9 +12,22 @@ package dev.openfga.sdk.api.configuration; -public class ClientCheckOptions { +import java.util.Map; + +public class ClientCheckOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientCheckOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientCheckOptions authorizationModelId(String authorizationModelId) { this.authorizationModelId = authorizationModelId; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientCreateStoreOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientCreateStoreOptions.java new file mode 100644 index 0000000..363ee22 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientCreateStoreOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientCreateStoreOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientCreateStoreOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteStoreOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteStoreOptions.java new file mode 100644 index 0000000..2776b6d --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteStoreOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientDeleteStoreOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientDeleteStoreOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteTuplesOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteTuplesOptions.java new file mode 100644 index 0000000..de548cd --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteTuplesOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientDeleteTuplesOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientDeleteTuplesOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java index 66dc5b5..5b3487d 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java @@ -12,9 +12,22 @@ package dev.openfga.sdk.api.configuration; -public class ClientExpandOptions { +import java.util.Map; + +public class ClientExpandOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientExpandOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientExpandOptions authorizationModelId(String authorizationModelId) { this.authorizationModelId = authorizationModelId; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java new file mode 100644 index 0000000..c8adf6e --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientGetStoreOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientGetStoreOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java index 67ba5f4..1d51072 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java @@ -12,9 +12,22 @@ package dev.openfga.sdk.api.configuration; -public class ClientListObjectsOptions { +import java.util.Map; + +public class ClientListObjectsOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientListObjectsOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientListObjectsOptions authorizationModelId(String authorizationModelId) { this.authorizationModelId = authorizationModelId; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java index 344379c..6d9cc2d 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java @@ -12,10 +12,23 @@ package dev.openfga.sdk.api.configuration; -public class ClientListRelationsOptions { +import java.util.Map; + +public class ClientListRelationsOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer maxParallelRequests; private String authorizationModelId; + public ClientListRelationsOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientListRelationsOptions maxParallelRequests(Integer maxParallelRequests) { this.maxParallelRequests = maxParallelRequests; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java index 7ada22d..d427a53 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java @@ -12,10 +12,23 @@ package dev.openfga.sdk.api.configuration; -public class ClientListStoresOptions { +import java.util.Map; + +public class ClientListStoresOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer pageSize; private String continuationToken; + public ClientListStoresOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientListStoresOptions pageSize(Integer pageSize) { this.pageSize = pageSize; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java index f639b3f..c02ec03 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java @@ -15,10 +15,22 @@ import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace; import dev.openfga.sdk.errors.FgaInvalidParameterException; +import java.util.Map; -public class ClientReadAssertionsOptions { +public class ClientReadAssertionsOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientReadAssertionsOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public boolean hasValidAuthorizationModelId() throws FgaInvalidParameterException { return !isNullOrWhitespace(authorizationModelId); } diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java index 478de20..e1716a9 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java @@ -15,10 +15,22 @@ import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace; import dev.openfga.sdk.errors.FgaInvalidParameterException; +import java.util.Map; -public class ClientReadAuthorizationModelOptions { +public class ClientReadAuthorizationModelOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientReadAuthorizationModelOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public void assertValidAuthorizationModelId() throws FgaInvalidParameterException { if (isNullOrWhitespace(authorizationModelId)) { throw new FgaInvalidParameterException("authorizationModelId", "ClientConfiguration"); diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java index 2cf80bb..f4c81d6 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java @@ -12,10 +12,23 @@ package dev.openfga.sdk.api.configuration; -public class ClientReadAuthorizationModelsOptions { +import java.util.Map; + +public class ClientReadAuthorizationModelsOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer pageSize; private String continuationToken; + public ClientReadAuthorizationModelsOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientReadAuthorizationModelsOptions pageSize(Integer pageSize) { this.pageSize = pageSize; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java index 612049c..2321386 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java @@ -12,18 +12,21 @@ package dev.openfga.sdk.api.configuration; -public class ClientReadChangesOptions { - private String type; +import java.util.Map; + +public class ClientReadChangesOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer pageSize; private String continuationToken; - public ClientReadChangesOptions type(String type) { - this.type = type; + public ClientReadChangesOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; return this; } - public String getType() { - return type; + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; } public ClientReadChangesOptions pageSize(Integer pageSize) { diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadLatestAuthorizationModelOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadLatestAuthorizationModelOptions.java new file mode 100644 index 0000000..2f96351 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadLatestAuthorizationModelOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientReadLatestAuthorizationModelOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientReadLatestAuthorizationModelOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java index c3a44b2..3daff2a 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java @@ -12,10 +12,23 @@ package dev.openfga.sdk.api.configuration; -public class ClientReadOptions { +import java.util.Map; + +public class ClientReadOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private Integer pageSize; private String continuationToken; + public ClientReadOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientReadOptions pageSize(Integer pageSize) { this.pageSize = pageSize; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java index 1755e20..ac88c7f 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java @@ -15,10 +15,22 @@ import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace; import dev.openfga.sdk.errors.FgaInvalidParameterException; +import java.util.Map; -public class ClientWriteAssertionsOptions { +public class ClientWriteAssertionsOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; + public ClientWriteAssertionsOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public boolean hasValidAuthorizationModelId() throws FgaInvalidParameterException { return !isNullOrWhitespace(authorizationModelId); } diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAuthorizationModelOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAuthorizationModelOptions.java new file mode 100644 index 0000000..a6b56f9 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAuthorizationModelOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientWriteAuthorizationModelOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientWriteAuthorizationModelOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java index fde80af..c18634b 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java @@ -12,11 +12,24 @@ package dev.openfga.sdk.api.configuration; -public class ClientWriteOptions { +import java.util.Map; + +public class ClientWriteOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; private String authorizationModelId; private Boolean disableTransactions = false; private int transactionChunkSize; + public ClientWriteOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } + public ClientWriteOptions authorizationModelId(String authorizationModelId) { this.authorizationModelId = authorizationModelId; return this; diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteTuplesOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteTuplesOptions.java new file mode 100644 index 0000000..1dca679 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteTuplesOptions.java @@ -0,0 +1,29 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.configuration; + +import java.util.Map; + +public class ClientWriteTuplesOptions implements AdditionalHeadersSupplier { + private Map additionalHeaders; + + public ClientWriteTuplesOptions additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + @Override + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } +} diff --git a/src/main/java/dev/openfga/sdk/api/configuration/Configuration.java b/src/main/java/dev/openfga/sdk/api/configuration/Configuration.java index 1cb7058..3c2a820 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/Configuration.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/Configuration.java @@ -22,6 +22,7 @@ import java.net.http.HttpConnectTimeoutException; import java.net.http.HttpRequest; import java.time.Duration; +import java.util.Map; /** * Configurations for an api client. @@ -41,6 +42,7 @@ public class Configuration implements BaseConfiguration { private Duration connectTimeout; private int maxRetries; private Duration minimumRetryDelay; + private Map additionalHeaders; public Configuration() { this.apiUrl = DEFAULT_API_URL; @@ -109,6 +111,15 @@ public Configuration override(ConfigurationOverride configurationOverride) { Duration overrideMinimumRetryDelay = configurationOverride.getMinimumRetryDelay(); result.minimumRetryDelay(overrideMinimumRetryDelay != null ? overrideMinimumRetryDelay : minimumRetryDelay); + Map overrideAdditionalHeaders = configurationOverride.getAdditionalHeaders(); + if (overrideAdditionalHeaders != null) { + if (this.additionalHeaders == null) { + this.additionalHeaders = overrideAdditionalHeaders; + } else { + this.additionalHeaders.putAll(overrideAdditionalHeaders); + } + } + return result; } @@ -259,4 +270,13 @@ public Configuration minimumRetryDelay(Duration minimumRetryDelay) { public Duration getMinimumRetryDelay() { return minimumRetryDelay; } + + public Configuration additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } } diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ConfigurationOverride.java b/src/main/java/dev/openfga/sdk/api/configuration/ConfigurationOverride.java index 1d54a00..ba7e5ae 100644 --- a/src/main/java/dev/openfga/sdk/api/configuration/ConfigurationOverride.java +++ b/src/main/java/dev/openfga/sdk/api/configuration/ConfigurationOverride.java @@ -16,6 +16,7 @@ import java.net.http.HttpConnectTimeoutException; import java.net.http.HttpRequest; import java.time.Duration; +import java.util.Map; /** * Configuration overrides for an api client. Values are initialized to null, and any values unset are intended to fall @@ -31,6 +32,7 @@ public class ConfigurationOverride implements BaseConfiguration { private Duration connectTimeout; private Integer maxRetries; private Duration minimumRetryDelay; + private Map additionalHeaders; public ConfigurationOverride() { this.apiUrl = null; @@ -38,6 +40,7 @@ public ConfigurationOverride() { this.userAgent = null; this.readTimeout = null; this.connectTimeout = null; + this.additionalHeaders = null; } /** @@ -179,4 +182,28 @@ public ConfigurationOverride minimumRetryDelay(Duration minimumRetryDelay) { public Duration getMinimumRetryDelay() { return minimumRetryDelay; } + + public ConfigurationOverride additionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + public ConfigurationOverride addHeaders(AdditionalHeadersSupplier supplier) { + if (supplier == null || supplier.getAdditionalHeaders() == null) { + // No headers to add. + return this; + } + + var additionalHeaders = supplier.getAdditionalHeaders(); + if (this.additionalHeaders != null) { + this.additionalHeaders.putAll(additionalHeaders); + } else { + this.additionalHeaders = additionalHeaders; + } + return this; + } + + public Map getAdditionalHeaders() { + return this.additionalHeaders; + } } diff --git a/src/main/java/dev/openfga/sdk/api/model/AbortedMessageResponse.java b/src/main/java/dev/openfga/sdk/api/model/AbortedMessageResponse.java new file mode 100644 index 0000000..90527a9 --- /dev/null +++ b/src/main/java/dev/openfga/sdk/api/model/AbortedMessageResponse.java @@ -0,0 +1,176 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.StringJoiner; + +/** + * AbortedMessageResponse + */ +@JsonPropertyOrder({AbortedMessageResponse.JSON_PROPERTY_CODE, AbortedMessageResponse.JSON_PROPERTY_MESSAGE}) +public class AbortedMessageResponse { + public static final String JSON_PROPERTY_CODE = "code"; + private String code; + + public static final String JSON_PROPERTY_MESSAGE = "message"; + private String message; + + public AbortedMessageResponse() {} + + public AbortedMessageResponse code(String code) { + this.code = code; + return this; + } + + /** + * Get code + * @return code + **/ + @javax.annotation.Nullable + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getCode() { + return code; + } + + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setCode(String code) { + this.code = code; + } + + public AbortedMessageResponse message(String message) { + this.message = message; + return this; + } + + /** + * Get message + * @return message + **/ + @javax.annotation.Nullable + @JsonProperty(JSON_PROPERTY_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getMessage() { + return message; + } + + @JsonProperty(JSON_PROPERTY_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setMessage(String message) { + this.message = message; + } + + /** + * Return true if this AbortedMessageResponse object is equal to o. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AbortedMessageResponse abortedMessageResponse = (AbortedMessageResponse) o; + return Objects.equals(this.code, abortedMessageResponse.code) + && Objects.equals(this.message, abortedMessageResponse.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AbortedMessageResponse {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Convert the instance into URL query string. + * + * @return URL query string + */ + public String toUrlQueryString() { + return toUrlQueryString(null); + } + + /** + * Convert the instance into URL query string. + * + * @param prefix prefix of the query string + * @return URL query string + */ + public String toUrlQueryString(String prefix) { + String suffix = ""; + String containerSuffix = ""; + String containerPrefix = ""; + if (prefix == null) { + // style=form, explode=true, e.g. /pet?name=cat&type=manx + prefix = ""; + } else { + // deepObject style e.g. /pet?id[name]=cat&id[type]=manx + prefix = prefix + "["; + suffix = "]"; + containerSuffix = "]"; + containerPrefix = "["; + } + + StringJoiner joiner = new StringJoiner("&"); + + // add `code` to the URL query string + if (getCode() != null) { + joiner.add(String.format( + "%scode%s=%s", + prefix, + suffix, + URLEncoder.encode(String.valueOf(getCode()), StandardCharsets.UTF_8) + .replaceAll("\\+", "%20"))); + } + + // add `message` to the URL query string + if (getMessage() != null) { + joiner.add(String.format( + "%smessage%s=%s", + prefix, + suffix, + URLEncoder.encode(String.valueOf(getMessage()), StandardCharsets.UTF_8) + .replaceAll("\\+", "%20"))); + } + + return joiner.toString(); + } +} diff --git a/src/main/java/dev/openfga/sdk/api/model/NullValue.java b/src/main/java/dev/openfga/sdk/api/model/NullValue.java index d2718bf..d72381e 100644 --- a/src/main/java/dev/openfga/sdk/api/model/NullValue.java +++ b/src/main/java/dev/openfga/sdk/api/model/NullValue.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.annotation.JsonValue; /** - * `NullValue` is a singleton enumeration to represent the null value for the `Value` type union. The JSON representation for `NullValue` is JSON `null`. - NULL_VALUE: Null value. + * `NullValue` is a singleton enumeration to represent the null value for the `Value` type union. The JSON representation for `NullValue` is JSON `null`. - NULL_VALUE: Null value. */ public enum NullValue { NULL_VALUE("NULL_VALUE"), diff --git a/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java b/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java index a113a7d..b4f3bd3 100644 --- a/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java +++ b/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java @@ -25,11 +25,15 @@ import java.time.Duration; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,6 +54,8 @@ public class OpenFgaClientTest { new ClientRelationshipCondition().name("condition").context(Map.of("some", "context")); private static final int DEFAULT_MAX_RETRIES = 3; private static final Duration DEFAULT_RETRY_DELAY = Duration.ofMillis(100); + private static final String CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method"; + private static final String CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id"; private OpenFgaClient fga; private ClientConfiguration clientConfiguration; @@ -639,7 +645,7 @@ public void readChanges() throws Exception { String continuationToken = "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ"; - ClientReadChangesOptions options = new ClientReadChangesOptions().type(changeType); + ClientReadChangesRequest request = new ClientReadChangesRequest().type(changeType); String getUrl = String.format("https://localhost/stores/%s/changes?type=%s", DEFAULT_STORE_ID, changeType); String responseBody = String.format( "{\"changes\":[{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"operation\":\"TUPLE_OPERATION_WRITE\"}],\"continuation_token\":\"%s\"}", @@ -647,7 +653,7 @@ public void readChanges() throws Exception { mockHttpClient.onGet(getUrl).doReturn(200, responseBody); // When - ClientReadChangesResponse response = fga.readChanges(options).get(); + ClientReadChangesResponse response = fga.readChanges(request).get(); // Then mockHttpClient.verify().get(getUrl).called(1); @@ -1125,6 +1131,8 @@ public void writeTest_transactions() throws Exception { mockHttpClient .onPost(postPath) .withBody(isOneOf(write2Body, write1Body, delete2Body, delete1Body)) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .doReturn(200, EMPTY_RESPONSE_BODY); ClientWriteRequest request = new ClientWriteRequest() .writes(List.of(writeTuple, writeTuple, writeTuple, writeTuple, writeTuple)) @@ -1136,10 +1144,34 @@ public void writeTest_transactions() throws Exception { var response = fga.write(request, options).get(); // Then - mockHttpClient.verify().post(postPath).withBody(is(write2Body)).called(2); - mockHttpClient.verify().post(postPath).withBody(is(write1Body)).called(1); - mockHttpClient.verify().post(postPath).withBody(is(delete2Body)).called(2); - mockHttpClient.verify().post(postPath).withBody(is(delete1Body)).called(1); + mockHttpClient + .verify() + .post(postPath) + .withBody(is(write2Body)) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(2); + mockHttpClient + .verify() + .post(postPath) + .withBody(is(write1Body)) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(1); + mockHttpClient + .verify() + .post(postPath) + .withBody(is(delete2Body)) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(2); + mockHttpClient + .verify() + .post(postPath) + .withBody(is(delete1Body)) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(1); assertEquals(200, response.getStatusCode()); } @@ -1156,10 +1188,14 @@ public void writeTest_transactionsWithFailure() throws Exception { mockHttpClient .onPost(postPath) .withBody(isOneOf(writeBody.apply(firstUser), writeBody.apply(skippedUser))) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .doReturn(200, EMPTY_RESPONSE_BODY); mockHttpClient .onPost(postPath) .withBody(is(writeBody.apply(failedUser))) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .doReturn(400, "{\"code\":\"validation_error\",\"message\":\"Generic validation error\"}"); ClientWriteRequest request = new ClientWriteRequest() .writes(Stream.of(firstUser, failedUser, skippedUser) @@ -1181,16 +1217,22 @@ public void writeTest_transactionsWithFailure() throws Exception { .verify() .post(postPath) .withBody(is(writeBody.apply(firstUser))) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .called(1); mockHttpClient .verify() .post(postPath) .withBody(is(writeBody.apply(failedUser))) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .called(1); mockHttpClient .verify() .post(postPath) .withBody(is(writeBody.apply(skippedUser))) + .withHeader(CLIENT_METHOD_HEADER, "Write") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) .called(0); var exception = assertInstanceOf(FgaApiValidationError.class, execException.getCause()); assertEquals(400, exception.getStatusCode()); @@ -1538,7 +1580,12 @@ public void batchCheck() throws Exception { String expectedBody = String.format( "{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"contextual_tuples\":null,\"authorization_model_id\":\"01G5JAVJ41T49E9TT3SKVS7X1J\",\"trace\":null,\"context\":null}", DEFAULT_USER, DEFAULT_RELATION, DEFAULT_OBJECT); - mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, "{\"allowed\":true}"); + mockHttpClient + .onPost(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .doReturn(200, "{\"allowed\":true}"); ClientCheckRequest request = new ClientCheckRequest() ._object(DEFAULT_OBJECT) .relation(DEFAULT_RELATION) @@ -1550,7 +1597,13 @@ public void batchCheck() throws Exception { fga.batchCheck(List.of(request), options).get(); // Then - mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1); + mockHttpClient + .verify() + .post(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(1); assertEquals(Boolean.TRUE, response.get(0).getAllowed()); } @@ -1561,7 +1614,12 @@ public void batchCheck_twentyTimes() throws Exception { String expectedBody = String.format( "{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"contextual_tuples\":null,\"authorization_model_id\":\"01G5JAVJ41T49E9TT3SKVS7X1J\",\"trace\":null,\"context\":null}", DEFAULT_USER, DEFAULT_RELATION, DEFAULT_OBJECT); - mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, "{\"allowed\":true}"); + mockHttpClient + .onPost(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .doReturn(200, "{\"allowed\":true}"); List requests = IntStream.range(0, 20) .mapToObj(ignored -> new ClientCheckRequest() ._object(DEFAULT_OBJECT) @@ -1574,7 +1632,13 @@ public void batchCheck_twentyTimes() throws Exception { fga.batchCheck(requests, options).get(); // Then - mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(20); + mockHttpClient + .verify() + .post(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(20); } @Test @@ -1898,7 +1962,12 @@ public void listRelations() throws Exception { String expectedBody = String.format( "{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"contextual_tuples\":null,\"authorization_model_id\":\"01G5JAVJ41T49E9TT3SKVS7X1J\",\"trace\":null,\"context\":null}", DEFAULT_USER, DEFAULT_RELATION, DEFAULT_OBJECT); - mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, "{\"allowed\":true}"); + mockHttpClient + .onPost(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .doReturn(200, "{\"allowed\":true}"); ClientListRelationsRequest request = new ClientListRelationsRequest() .relations(List.of(DEFAULT_RELATION)) .user(DEFAULT_USER) @@ -1911,7 +1980,13 @@ public void listRelations() throws Exception { fga.listRelations(request, options).get(); // Then - mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1); + mockHttpClient + .verify() + .post(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(1); assertNotNull(response); assertNotNull(response.getRelations()); assertEquals(1, response.getRelations().size()); @@ -1925,7 +2000,12 @@ public void listRelations_deny() throws Exception { String expectedBody = String.format( "{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"contextual_tuples\":null,\"authorization_model_id\":\"%s\",\"trace\":null,\"context\":null}", DEFAULT_USER, "owner", DEFAULT_OBJECT, DEFAULT_AUTH_MODEL_ID); - mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, "{\"allowed\":false}"); + mockHttpClient + .onPost(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .doReturn(200, "{\"allowed\":false}"); ClientListRelationsRequest request = new ClientListRelationsRequest() .relations(List.of("owner")) ._object(DEFAULT_OBJECT) @@ -1938,7 +2018,13 @@ public void listRelations_deny() throws Exception { fga.listRelations(request, options).get(); // Then - mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1); + mockHttpClient + .verify() + .post(postUrl) + .withBody(is(expectedBody)) + .withHeader(CLIENT_METHOD_HEADER, "BatchCheck") + .withHeader(CLIENT_BULK_REQUEST_ID_HEADER, isUUID()) + .called(1); assertNotNull(response); assertNotNull(response.getRelations()); assertTrue(response.getRelations().isEmpty()); @@ -2380,4 +2466,42 @@ public void setAuthorizationModelId() throws Exception { "OpenFgaClient.setAuthorizationModelId(String) is expected to persist its Authorization Model ID in its ClientConfiguration." + "If this behavior ever changes, it could be a subtle breaking change."); } + + private Matcher isUUID() { + return new UUIDMatcher(); + } + + private static class UUIDMatcher extends BaseMatcher { + private boolean wasNotString = false; + private boolean wasInvalidUUID = false; + + @Override + public void describeTo(Description description) {} + + @Override + public boolean matches(Object item) { + if (!(item instanceof String)) { + return wasNotString = false; + } + + var string = (String) item; + + try { + UUID.fromString(string); + return true; + } catch (IllegalArgumentException ex) { + wasInvalidUUID = true; + return false; + } + } + + @Override + public void describeMismatch(Object item, Description mismatchDescription) { + if (wasNotString) { + System.err.printf("Expected an instance of String but found class: %s\n", item.getClass()); + } else if (wasInvalidUUID) { + System.err.printf("Expected a valid UUID but found \"%s\"\n", item); + } + } + } } diff --git a/src/test/java/dev/openfga/sdk/api/model/AbortedMessageResponseTest.java b/src/test/java/dev/openfga/sdk/api/model/AbortedMessageResponseTest.java new file mode 100644 index 0000000..7058a78 --- /dev/null +++ b/src/test/java/dev/openfga/sdk/api/model/AbortedMessageResponseTest.java @@ -0,0 +1,46 @@ +/* + * OpenFGA + * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. + * + * The version of the OpenAPI document: 0.1 + * Contact: community@openfga.dev + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package dev.openfga.sdk.api.model; + +import org.junit.jupiter.api.Test; + +/** + * Model tests for AbortedMessageResponse + */ +public class AbortedMessageResponseTest { + private final AbortedMessageResponse model = new AbortedMessageResponse(); + + /** + * Model tests for AbortedMessageResponse + */ + @Test + public void testAbortedMessageResponse() { + // TODO: test AbortedMessageResponse + } + + /** + * Test the property 'code' + */ + @Test + public void codeTest() { + // TODO: test code + } + + /** + * Test the property 'message' + */ + @Test + public void messageTest() { + // TODO: test message + } +}