Skip to content

Commit 05ed244

Browse files
committed
feat(java): Introduce ConfigurationOverride class
1 parent 2602c5b commit 05ed244

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+694
-258
lines changed

.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ src/main/java/dev/openfga/sdk/api/client/BaseConfiguration.java
8383
src/main/java/dev/openfga/sdk/api/client/ClientCredentials.java
8484
src/main/java/dev/openfga/sdk/api/client/Configuration.java
8585
src/main/java/dev/openfga/sdk/api/client/Configuration.java
86+
src/main/java/dev/openfga/sdk/api/client/ConfigurationOverride.java
8687
src/main/java/dev/openfga/sdk/api/client/CredentialsMethod.java
8788
src/main/java/dev/openfga/sdk/api/client/JSON.java
8889
src/main/java/dev/openfga/sdk/api/client/Pair.java

src/main/java/dev/openfga/sdk/api/OpenFgaApi.java

Lines changed: 469 additions & 194 deletions
Large diffs are not rendered by default.

src/main/java/dev/openfga/sdk/api/client/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*/
5050
@javax.annotation.Generated(
5151
value = "org.openapitools.codegen.languages.JavaClientCodegen",
52-
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
52+
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
5353
public class ApiClient {
5454

5555
private HttpClient.Builder builder;

src/main/java/dev/openfga/sdk/api/client/ApiException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@javax.annotation.Generated(
1818
value = "org.openapitools.codegen.languages.JavaClientCodegen",
19-
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
19+
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
2020
public class ApiException extends Exception {
2121
private int code = 0;
2222
private HttpHeaders responseHeaders = null;

src/main/java/dev/openfga/sdk/api/client/BaseConfiguration.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
package dev.openfga.sdk.api.client;
1414

15-
import dev.openfga.sdk.errors.FgaInvalidParameterException;
1615
import java.time.Duration;
1716

1817
public interface BaseConfiguration {
19-
void assertValid() throws FgaInvalidParameterException;
20-
2118
String getApiUrl();
2219

2320
String getUserAgent();

src/main/java/dev/openfga/sdk/api/client/Configuration.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.time.Duration;
2525

2626
/**
27-
* Configurations for an ApiClient.
27+
* Configurations for an api client.
2828
*/
2929
public class Configuration implements BaseConfiguration {
3030
public static final String VERSION = "0.0.1";
@@ -49,7 +49,6 @@ public Configuration(String apiUrl) {
4949
/**
5050
* Assert that the configuration is valid.
5151
*/
52-
@Override
5352
public void assertValid() throws FgaInvalidParameterException {
5453
// If apiUrl is null/empty/whitespace it will resolve to
5554
// DEFAULT_API_URL when getApiUrl is called.
@@ -73,13 +72,39 @@ public void assertValid() throws FgaInvalidParameterException {
7372
}
7473
}
7574

75+
/**
76+
* Construct a new {@link Configuration} with any non-null values of a {@link ConfigurationOverride} and remaining values from this {@link Configuration}.
77+
*
78+
* @param configurationOverride The values to override
79+
* @return A new {@link Configuration} with values of this Configuration mixed with non-null values of configurationOverride
80+
*/
81+
public Configuration override(ConfigurationOverride configurationOverride) {
82+
Configuration result = new Configuration(apiUrl);
83+
84+
String overrideApiUrl = configurationOverride.getApiUrl();
85+
if (overrideApiUrl != null) {
86+
result.apiUrl(overrideApiUrl);
87+
}
88+
89+
String overrideUserAgent = configurationOverride.getUserAgent();
90+
result.userAgent(overrideUserAgent != null ? overrideUserAgent : userAgent);
91+
92+
Duration overrideReadTimeout = configurationOverride.getReadTimeout();
93+
result.readTimeout(overrideReadTimeout != null ? overrideReadTimeout : readTimeout);
94+
95+
Duration overrideConnectTimeout = configurationOverride.getConnectTimeout();
96+
result.connectTimeout(overrideConnectTimeout != null ? overrideConnectTimeout : connectTimeout);
97+
98+
return result;
99+
}
100+
76101
/**
77102
* Set the API URL for the http client.
78103
*
79104
* @param apiUrl The URL.
80105
* @return This object.
81106
*/
82-
public BaseConfiguration apiUrl(String apiUrl) {
107+
public Configuration apiUrl(String apiUrl) {
83108
this.apiUrl = apiUrl;
84109
return this;
85110
}
@@ -104,7 +129,7 @@ public String getApiUrl() {
104129
* @param userAgent The user agent.
105130
* @return This object.
106131
*/
107-
public BaseConfiguration userAgent(String userAgent) {
132+
public Configuration userAgent(String userAgent) {
108133
this.userAgent = userAgent;
109134
return this;
110135
}
@@ -130,7 +155,7 @@ public String getUserAgent() {
130155
* effectively infinite value.
131156
* @return This object.
132157
*/
133-
public BaseConfiguration readTimeout(Duration readTimeout) {
158+
public Configuration readTimeout(Duration readTimeout) {
134159
this.readTimeout = readTimeout;
135160
return this;
136161
}
@@ -162,7 +187,7 @@ public Duration getReadTimeout() {
162187
* @param connectTimeout connection timeout in milliseconds
163188
* @return This object.
164189
*/
165-
public BaseConfiguration connectTimeout(Duration connectTimeout) {
190+
public Configuration connectTimeout(Duration connectTimeout) {
166191
this.connectTimeout = connectTimeout;
167192
return this;
168193
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 0.1
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package dev.openfga.sdk.api.client;
14+
15+
import java.net.http.HttpClient;
16+
import java.net.http.HttpConnectTimeoutException;
17+
import java.net.http.HttpRequest;
18+
import java.time.Duration;
19+
20+
/**
21+
* Configuration overrides for an api client. Values are initialized to null, and any values unset are intended to fall
22+
* through to the values of a {@link Configuration}.
23+
* <p>
24+
* More details on intended usage of this class can be found in the documentation of the {@link Configuration#override(ConfigurationOverride)} method.
25+
*/
26+
public class ConfigurationOverride implements BaseConfiguration {
27+
private String apiUrl;
28+
private String userAgent;
29+
private Duration readTimeout;
30+
private Duration connectTimeout;
31+
32+
public ConfigurationOverride() {
33+
this.apiUrl = null;
34+
this.userAgent = null;
35+
this.readTimeout = null;
36+
this.connectTimeout = null;
37+
}
38+
39+
/**
40+
* Set the API URL for the http client.
41+
*
42+
* @param apiUrl The URL.
43+
* @return This object.
44+
*/
45+
public BaseConfiguration apiUrl(String apiUrl) {
46+
this.apiUrl = apiUrl;
47+
return this;
48+
}
49+
50+
/**
51+
* Get the API URL that was set.
52+
*
53+
* @return The url.
54+
*/
55+
@Override
56+
public String getApiUrl() {
57+
return apiUrl;
58+
}
59+
60+
/**
61+
* Set the user agent.
62+
*
63+
* @param userAgent The user agent.
64+
* @return This object.
65+
*/
66+
public BaseConfiguration userAgent(String userAgent) {
67+
this.userAgent = userAgent;
68+
return this;
69+
}
70+
71+
/**
72+
* Get the user agent.
73+
*
74+
* @return The user agent.
75+
*/
76+
@Override
77+
public String getUserAgent() {
78+
return userAgent;
79+
}
80+
81+
/**
82+
* Set the read timeout for the http client.
83+
*
84+
* <p>This is the value used by default for each request, though it can be
85+
* overridden on a per-request basis with a request interceptor.</p>
86+
*
87+
* @param readTimeout The read timeout used by default by the http client.
88+
* Setting this value to null resets the timeout to an
89+
* effectively infinite value.
90+
* @return This object.
91+
*/
92+
public BaseConfiguration readTimeout(Duration readTimeout) {
93+
this.readTimeout = readTimeout;
94+
return this;
95+
}
96+
97+
/**
98+
* Get the read timeout that was set.
99+
*
100+
* @return The read timeout, or null if no timeout was set. Null represents
101+
* an infinite wait time.
102+
*/
103+
@Override
104+
public Duration getReadTimeout() {
105+
return readTimeout;
106+
}
107+
108+
/**
109+
* Sets the connect timeout (in milliseconds) for the http client.
110+
*
111+
* <p> In the case where a new connection needs to be established, if
112+
* the connection cannot be established within the given {@code
113+
* duration}, then {@link HttpClient#send(HttpRequest, BodyHandler)
114+
* HttpClient::send} throws an {@link HttpConnectTimeoutException}, or
115+
* {@link HttpClient#sendAsync(HttpRequest, BodyHandler)
116+
* HttpClient::sendAsync} completes exceptionally with an
117+
* {@code HttpConnectTimeoutException}. If a new connection does not
118+
* need to be established, for example if a connection can be reused
119+
* from a previous request, then this timeout duration has no effect.
120+
*
121+
* @param connectTimeout connection timeout in milliseconds
122+
* @return This object.
123+
*/
124+
public BaseConfiguration connectTimeout(Duration connectTimeout) {
125+
this.connectTimeout = connectTimeout;
126+
return this;
127+
}
128+
129+
/**
130+
* Get connection timeout (in milliseconds).
131+
*
132+
* @return Timeout in milliseconds
133+
*/
134+
@Override
135+
public Duration getConnectTimeout() {
136+
return connectTimeout;
137+
}
138+
}

src/main/java/dev/openfga/sdk/api/client/JSON.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

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

src/main/java/dev/openfga/sdk/api/client/Pair.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@javax.annotation.Generated(
1616
value = "org.openapitools.codegen.languages.JavaClientCodegen",
17-
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
17+
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
1818
public class Pair {
1919
private String name = "";
2020
private String value = "";

src/main/java/dev/openfga/sdk/api/model/AbstractOpenApiSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
@javax.annotation.Generated(
2323
value = "org.openapitools.codegen.languages.JavaClientCodegen",
24-
date = "2023-08-21T23:45:26.204414Z[Etc/UTC]")
24+
date = "2023-08-22T23:54:43.912230Z[Etc/UTC]")
2525
public abstract class AbstractOpenApiSchema {
2626

2727
// store the actual instance of the schema/object

0 commit comments

Comments
 (0)