Skip to content

Commit

Permalink
feat(java): Introduce ConfigurationOverride class
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Aug 23, 2023
1 parent 2602c5b commit 05ed244
Show file tree
Hide file tree
Showing 60 changed files with 694 additions and 258 deletions.
1 change: 1 addition & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ src/main/java/dev/openfga/sdk/api/client/BaseConfiguration.java
src/main/java/dev/openfga/sdk/api/client/ClientCredentials.java
src/main/java/dev/openfga/sdk/api/client/Configuration.java
src/main/java/dev/openfga/sdk/api/client/Configuration.java
src/main/java/dev/openfga/sdk/api/client/ConfigurationOverride.java
src/main/java/dev/openfga/sdk/api/client/CredentialsMethod.java
src/main/java/dev/openfga/sdk/api/client/JSON.java
src/main/java/dev/openfga/sdk/api/client/Pair.java
Expand Down
663 changes: 469 additions & 194 deletions src/main/java/dev/openfga/sdk/api/OpenFgaApi.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class ApiClient {

private HttpClient.Builder builder;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/client/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class ApiException extends Exception {
private int code = 0;
private HttpHeaders responseHeaders = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.errors.FgaInvalidParameterException;
import java.time.Duration;

public interface BaseConfiguration {
void assertValid() throws FgaInvalidParameterException;

String getApiUrl();

String getUserAgent();
Expand Down
37 changes: 31 additions & 6 deletions src/main/java/dev/openfga/sdk/api/client/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.time.Duration;

/**
* Configurations for an ApiClient.
* Configurations for an api client.
*/
public class Configuration implements BaseConfiguration {
public static final String VERSION = "0.0.1";
Expand All @@ -49,7 +49,6 @@ public Configuration(String apiUrl) {
/**
* Assert that the configuration is valid.
*/
@Override
public void assertValid() throws FgaInvalidParameterException {
// If apiUrl is null/empty/whitespace it will resolve to
// DEFAULT_API_URL when getApiUrl is called.
Expand All @@ -73,13 +72,39 @@ public void assertValid() throws FgaInvalidParameterException {
}
}

/**
* Construct a new {@link Configuration} with any non-null values of a {@link ConfigurationOverride} and remaining values from this {@link Configuration}.
*
* @param configurationOverride The values to override
* @return A new {@link Configuration} with values of this Configuration mixed with non-null values of configurationOverride
*/
public Configuration override(ConfigurationOverride configurationOverride) {
Configuration result = new Configuration(apiUrl);

String overrideApiUrl = configurationOverride.getApiUrl();
if (overrideApiUrl != null) {
result.apiUrl(overrideApiUrl);
}

String overrideUserAgent = configurationOverride.getUserAgent();
result.userAgent(overrideUserAgent != null ? overrideUserAgent : userAgent);

Duration overrideReadTimeout = configurationOverride.getReadTimeout();
result.readTimeout(overrideReadTimeout != null ? overrideReadTimeout : readTimeout);

Duration overrideConnectTimeout = configurationOverride.getConnectTimeout();
result.connectTimeout(overrideConnectTimeout != null ? overrideConnectTimeout : connectTimeout);

return result;
}

/**
* Set the API URL for the http client.
*
* @param apiUrl The URL.
* @return This object.
*/
public BaseConfiguration apiUrl(String apiUrl) {
public Configuration apiUrl(String apiUrl) {
this.apiUrl = apiUrl;
return this;
}
Expand All @@ -104,7 +129,7 @@ public String getApiUrl() {
* @param userAgent The user agent.
* @return This object.
*/
public BaseConfiguration userAgent(String userAgent) {
public Configuration userAgent(String userAgent) {
this.userAgent = userAgent;
return this;
}
Expand All @@ -130,7 +155,7 @@ public String getUserAgent() {
* effectively infinite value.
* @return This object.
*/
public BaseConfiguration readTimeout(Duration readTimeout) {
public Configuration readTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
return this;
}
Expand Down Expand Up @@ -162,7 +187,7 @@ public Duration getReadTimeout() {
* @param connectTimeout connection timeout in milliseconds
* @return This object.
*/
public BaseConfiguration connectTimeout(Duration connectTimeout) {
public Configuration connectTimeout(Duration connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}
Expand Down
138 changes: 138 additions & 0 deletions src/main/java/dev/openfga/sdk/api/client/ConfigurationOverride.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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: [email protected]
*
* 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;

import java.net.http.HttpClient;
import java.net.http.HttpConnectTimeoutException;
import java.net.http.HttpRequest;
import java.time.Duration;

/**
* Configuration overrides for an api client. Values are initialized to null, and any values unset are intended to fall
* through to the values of a {@link Configuration}.
* <p>
* More details on intended usage of this class can be found in the documentation of the {@link Configuration#override(ConfigurationOverride)} method.
*/
public class ConfigurationOverride implements BaseConfiguration {
private String apiUrl;
private String userAgent;
private Duration readTimeout;
private Duration connectTimeout;

public ConfigurationOverride() {
this.apiUrl = null;
this.userAgent = null;
this.readTimeout = null;
this.connectTimeout = null;
}

/**
* Set the API URL for the http client.
*
* @param apiUrl The URL.
* @return This object.
*/
public BaseConfiguration apiUrl(String apiUrl) {
this.apiUrl = apiUrl;
return this;
}

/**
* Get the API URL that was set.
*
* @return The url.
*/
@Override
public String getApiUrl() {
return apiUrl;
}

/**
* Set the user agent.
*
* @param userAgent The user agent.
* @return This object.
*/
public BaseConfiguration userAgent(String userAgent) {
this.userAgent = userAgent;
return this;
}

/**
* Get the user agent.
*
* @return The user agent.
*/
@Override
public String getUserAgent() {
return userAgent;
}

/**
* Set the read timeout for the http client.
*
* <p>This is the value used by default for each request, though it can be
* overridden on a per-request basis with a request interceptor.</p>
*
* @param readTimeout The read timeout used by default by the http client.
* Setting this value to null resets the timeout to an
* effectively infinite value.
* @return This object.
*/
public BaseConfiguration readTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
return this;
}

/**
* Get the read timeout that was set.
*
* @return The read timeout, or null if no timeout was set. Null represents
* an infinite wait time.
*/
@Override
public Duration getReadTimeout() {
return readTimeout;
}

/**
* Sets the connect timeout (in milliseconds) for the http client.
*
* <p> In the case where a new connection needs to be established, if
* the connection cannot be established within the given {@code
* duration}, then {@link HttpClient#send(HttpRequest, BodyHandler)
* HttpClient::send} throws an {@link HttpConnectTimeoutException}, or
* {@link HttpClient#sendAsync(HttpRequest, BodyHandler)
* HttpClient::sendAsync} completes exceptionally with an
* {@code HttpConnectTimeoutException}. If a new connection does not
* need to be established, for example if a connection can be reused
* from a previous request, then this timeout duration has no effect.
*
* @param connectTimeout connection timeout in milliseconds
* @return This object.
*/
public BaseConfiguration connectTimeout(Duration connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}

/**
* Get connection timeout (in milliseconds).
*
* @return Timeout in milliseconds
*/
@Override
public Duration getConnectTimeout() {
return connectTimeout;
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/client/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class JSON {
private ObjectMapper mapper;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/client/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class Pair {
private String name = "";
private String value = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public abstract class AbstractOpenApiSchema {

// store the actual instance of the schema/object
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/Any.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@JsonPropertyOrder({Any.JSON_PROPERTY_AT_TYPE})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class Any extends HashMap<String, Object> {
public static final String JSON_PROPERTY_AT_TYPE = "@type";
private String atType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/Assertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({Assertion.JSON_PROPERTY_TUPLE_KEY, Assertion.JSON_PROPERTY_EXPECTATION})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class Assertion {
public static final String JSON_PROPERTY_TUPLE_KEY = "tuple_key";
private TupleKey tupleKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class AuthorizationModel {
public static final String JSON_PROPERTY_ID = "id";
private String id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/CheckRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class CheckRequest {
public static final String JSON_PROPERTY_TUPLE_KEY = "tuple_key";
private TupleKey tupleKey;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/CheckResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({CheckResponse.JSON_PROPERTY_ALLOWED, CheckResponse.JSON_PROPERTY_RESOLUTION})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class CheckResponse {
public static final String JSON_PROPERTY_ALLOWED = "allowed";
private Boolean allowed;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/Computed.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({Computed.JSON_PROPERTY_USERSET})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class Computed {
public static final String JSON_PROPERTY_USERSET = "userset";
private String userset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({ContextualTupleKeys.JSON_PROPERTY_TUPLE_KEYS})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class ContextualTupleKeys {
public static final String JSON_PROPERTY_TUPLE_KEYS = "tuple_keys";
private List<TupleKey> tupleKeys = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({CreateStoreRequest.JSON_PROPERTY_NAME})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class CreateStoreRequest {
public static final String JSON_PROPERTY_NAME = "name";
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class CreateStoreResponse {
public static final String JSON_PROPERTY_ID = "id";
private String id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/Difference.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@JsonPropertyOrder({Difference.JSON_PROPERTY_BASE, Difference.JSON_PROPERTY_SUBTRACT})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class Difference {
public static final String JSON_PROPERTY_BASE = "base";
private Userset base;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfga/sdk/api/model/ExpandRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@JsonPropertyOrder({ExpandRequest.JSON_PROPERTY_TUPLE_KEY, ExpandRequest.JSON_PROPERTY_AUTHORIZATION_MODEL_ID})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class ExpandRequest {
public static final String JSON_PROPERTY_TUPLE_KEY = "tuple_key";
private TupleKey tupleKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@JsonPropertyOrder({ExpandResponse.JSON_PROPERTY_TREE})
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
public class ExpandResponse {
public static final String JSON_PROPERTY_TREE = "tree";
private UsersetTree tree;
Expand Down
Loading

0 comments on commit 05ed244

Please sign in to comment.