From d1b44507ca9a142cf5b4307c1f956f15e347899f Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Mon, 16 Nov 2026 09:44:51 -0800 Subject: [PATCH 1/2] fix(SDK-6627): Avoid duplicate `jti` errors by signing a new JWT assertion on token request retries (box/box-codegen#1001) --- .codegen.json | 2 +- docs/sdkgen/client.md | 2 + .../test/BoxNetworkClientRetryTest.java | 388 ++++++++++++++++++ .../box/sdkgen/box/jwtauth/BoxJWTAuth.java | 58 ++- .../jwtauth/JwtAccessTokenDataFactory.java | 101 +++++ .../sdkgen/internal/utils/UtilsManager.java | 2 +- .../boxnetworkclient/BoxNetworkClient.java | 46 ++- .../networking/fetchoptions/FetchOptions.java | 17 + .../fetchoptions/RequestDataFactory.java | 9 + 9 files changed, 582 insertions(+), 43 deletions(-) create mode 100644 src/intTest/java/com/box/sdkgen/test/BoxNetworkClientRetryTest.java create mode 100644 src/main/java/com/box/sdkgen/box/jwtauth/JwtAccessTokenDataFactory.java create mode 100644 src/main/java/com/box/sdkgen/networking/fetchoptions/RequestDataFactory.java diff --git a/.codegen.json b/.codegen.json index b488f3bb6..06dd81ce5 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "0eab570", "specHash": "7f8494a", "version": "5.20.0" } +{ "engineHash": "6772894", "specHash": "7f8494a", "version": "5.20.0" } diff --git a/docs/sdkgen/client.md b/docs/sdkgen/client.md index c78e51b7e..c87258e57 100644 --- a/docs/sdkgen/client.md +++ b/docs/sdkgen/client.md @@ -29,6 +29,8 @@ This method allows you to make any HTTP request to the Box API. It will automati network configuration settings from the client. The method accepts a `FetchOptions` object as an argument and returns a `FetchResponse` object. +For request bodies that cannot be safely replayed, such as a JWT assertion with a one-time `jti`, `FetchOptions` also accepts `dataFactory`. `dataFactory.create()` is called on the first attempt when `data` is not set and on each retry so each retry can send a fresh body. + ## JSON request The following example demonstrates how to make a custom POST request to create a new folder in the root folder. diff --git a/src/intTest/java/com/box/sdkgen/test/BoxNetworkClientRetryTest.java b/src/intTest/java/com/box/sdkgen/test/BoxNetworkClientRetryTest.java new file mode 100644 index 000000000..13dc52822 --- /dev/null +++ b/src/intTest/java/com/box/sdkgen/test/BoxNetworkClientRetryTest.java @@ -0,0 +1,388 @@ +package com.box.sdkgen.test; + +import static com.box.sdkgen.serialization.json.JsonManager.jsonToSerializedData; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.box.sdkgen.box.jwtauth.BoxJWTAuth; +import com.box.sdkgen.box.jwtauth.JWTConfig; +import com.box.sdkgen.internal.utils.PrivateKeyDecryptor; +import com.box.sdkgen.networking.baseurls.BaseUrls; +import com.box.sdkgen.networking.boxnetworkclient.BoxNetworkClient; +import com.box.sdkgen.networking.fetchoptions.FetchOptions; +import com.box.sdkgen.networking.fetchoptions.RequestDataFactory; +import com.box.sdkgen.networking.fetchoptions.ResponseFormat; +import com.box.sdkgen.networking.fetchresponse.FetchResponse; +import com.box.sdkgen.networking.interceptors.Interceptor; +import com.box.sdkgen.networking.network.NetworkSession; +import com.box.sdkgen.networking.retries.RetryStrategy; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; +import okhttp3.ConnectionSpec; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.Test; + +public class BoxNetworkClientRetryTest { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Test + public void testNetworkExceptionRetryRegeneratesRequestData() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(200, "{\"ok\":true}")); + server.start(); + + List bodies = new ArrayList<>(); + CountingDataFactory dataFactory = new CountingDataFactory(); + testNetworkClientThatFailsFirstRequest(bodies) + .fetch( + baseOptions(server.url("/").toString(), jsonToSerializedData("{\"attempt\":\"D1\"}")) + .dataFactory(dataFactory) + .networkSession( + new NetworkSession() + .withRetryStrategy( + retryWhen( + (options, response, attempt) -> + response.getStatus() == 0 && attempt < 2))) + .build()); + + assertEquals(Arrays.asList("attempt=D1", "attempt=D2"), bodies); + assertEquals(1, dataFactory.calls); + } + } + + @Test + public void test500RetryRegeneratesRequestData() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(500, "{\"error\":\"retry\"}")); + server.enqueue(jsonResponse(200, "{\"ok\":true}")); + server.start(); + + CountingDataFactory dataFactory = new CountingDataFactory(); + testNetworkClient() + .fetch( + baseOptions(server.url("/").toString(), jsonToSerializedData("{\"attempt\":\"D1\"}")) + .dataFactory(dataFactory) + .networkSession( + new NetworkSession() + .withRetryStrategy( + retryWhen( + (options, response, attempt) -> response.getStatus() == 500))) + .build()); + + assertEquals("attempt=D1", takeBody(server)); + assertEquals("attempt=D2", takeBody(server)); + assertEquals(1, dataFactory.calls); + } + } + + @Test + public void testRetryStrategyReceivesRegeneratedRequestData() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(500, "{\"error\":\"retry\"}")); + server.enqueue(jsonResponse(200, "{\"ok\":true}")); + server.start(); + + List retryData = new ArrayList<>(); + CountingDataFactory dataFactory = new CountingDataFactory(); + testNetworkClient() + .fetch( + baseOptions(server.url("/").toString(), jsonToSerializedData("{\"attempt\":\"D1\"}")) + .dataFactory(dataFactory) + .networkSession( + new NetworkSession() + .withRetryStrategy( + retryWhen( + (options, response, attempt) -> { + retryData.add(options.getData().get("attempt").asText()); + return response.getStatus() == 500; + }))) + .build()); + + assertEquals(Arrays.asList("D1", "D2"), retryData); + } + } + + @Test + public void testInterceptorRunsOnEachRetryWithRebuiltData() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(500, "{\"error\":\"retry\"}")); + server.enqueue(jsonResponse(200, "{\"ok\":true}")); + server.start(); + + List interceptorData = new ArrayList<>(); + NetworkSession networkSession = + new NetworkSession() + .withInterceptors( + Arrays.asList( + new Interceptor() { + @Override + public FetchOptions beforeRequest(FetchOptions options) { + interceptorData.add(options.getData().get("attempt").asText()); + return options; + } + + @Override + public FetchResponse afterRequest(FetchResponse response) { + return response; + } + })) + .withRetryStrategy( + retryWhen((options, response, attempt) -> response.getStatus() == 500)); + + CountingDataFactory dataFactory = new CountingDataFactory(); + testNetworkClient() + .fetch( + baseOptions(server.url("/").toString(), jsonToSerializedData("{\"attempt\":\"D1\"}")) + .dataFactory(dataFactory) + .networkSession(networkSession) + .build()); + + assertEquals(Arrays.asList("D1", "D2"), interceptorData); + assertEquals(1, dataFactory.calls); + } + } + + @Test + public void testRetryWithoutDataFactoryResendsSameRequestData() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(500, "{\"error\":\"retry\"}")); + server.enqueue(jsonResponse(200, "{\"ok\":true}")); + server.start(); + + testNetworkClient() + .fetch( + baseOptions(server.url("/").toString(), jsonToSerializedData("{\"attempt\":\"D1\"}")) + .networkSession( + new NetworkSession() + .withRetryStrategy( + retryWhen( + (options, response, attempt) -> response.getStatus() == 500))) + .build()); + + assertEquals("attempt=D1", takeBody(server)); + assertEquals("attempt=D1", takeBody(server)); + } + } + + @Test + public void testWithDataCopiesFetchOptionsExceptData() throws Exception { + RequestDataFactory dataFactory = new CountingDataFactory(); + NetworkSession networkSession = new NetworkSession(); + FetchOptions options = + baseOptions("https://example.com", jsonToSerializedData("{\"attempt\":\"D1\"}")) + .dataFactory(dataFactory) + .fileStream(new ByteArrayInputStream("file".getBytes(StandardCharsets.UTF_8))) + .responseFormat(ResponseFormat.JSON) + .networkSession(networkSession) + .followRedirects(false) + .build(); + + Method withData = + BoxNetworkClient.class.getDeclaredMethod("withData", FetchOptions.class, JsonNode.class); + withData.setAccessible(true); + FetchOptions copied = + (FetchOptions) withData.invoke(null, options, jsonToSerializedData("{\"attempt\":\"D2\"}")); + + for (Field field : FetchOptions.class.getDeclaredFields()) { + field.setAccessible(true); + if (field.getName().equals("data")) { + assertEquals("D2", ((JsonNode) field.get(copied)).get("attempt").asText()); + } else { + assertEquals(field.get(options), field.get(copied), "FetchOptions." + field.getName()); + } + } + } + + @Test + public void testBoxJWTAuthRegeneratesAssertionOnRetry() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(jsonResponse(500, "{\"error\":\"retry\"}")); + server.enqueue( + jsonResponse( + 200, "{\"access_token\":\"token\",\"expires_in\":3600,\"token_type\":\"bearer\"}")); + server.start(); + + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + KeyPair keyPair = generator.generateKeyPair(); + JWTConfig config = + new JWTConfig.Builder( + "client-id", "client-secret", "jwt-key-id", "unused-private-key", "passphrase") + .enterpriseId("enterprise-id") + .privateKeyDecryptor(new FixedPrivateKeyDecryptor(keyPair.getPrivate())) + .build(); + + new BoxJWTAuth(config) + .refreshToken( + new NetworkSession() + .withCustomBaseUrls( + new BaseUrls.Builder() + .baseUrl(server.url("").toString().replaceAll("/$", "")) + .uploadUrl(server.url("").toString()) + .oauth2Url(server.url("").toString()) + .build()) + .withNetworkClient(testNetworkClient()) + .withRetryStrategy( + new RetryStrategy() { + @Override + public boolean shouldRetry( + FetchOptions options, FetchResponse response, int attemptNumber) { + return response.getStatus() == 500; + } + + @Override + public double retryAfter( + FetchOptions options, FetchResponse response, int attemptNumber) { + return 1; + } + })); + + JwtPayload firstPayload = decodePayload(assertionFrom(takeBody(server))); + JwtPayload secondPayload = decodePayload(assertionFrom(takeBody(server))); + assertNotEquals(firstPayload.jti, secondPayload.jti); + assertTrue(secondPayload.exp > firstPayload.exp); + } + } + + private FetchOptions.Builder baseOptions(String url, JsonNode data) { + return new FetchOptions.Builder(url, "POST") + .contentType("application/x-www-form-urlencoded") + .responseFormat(ResponseFormat.JSON) + .data(data); + } + + private MockResponse jsonResponse(int status, String body) { + return new MockResponse() + .setResponseCode(status) + .setHeader("Content-Type", "application/json") + .setHeader("Retry-After", "0") + .setBody(body); + } + + private BoxNetworkClient testNetworkClient() { + return new BoxNetworkClient( + new OkHttpClient.Builder() + .connectionSpecs(Arrays.asList(ConnectionSpec.CLEARTEXT)) + .followRedirects(false) + .retryOnConnectionFailure(false) + .build()); + } + + private BoxNetworkClient testNetworkClientThatFailsFirstRequest(List bodies) { + AtomicBoolean firstRequest = new AtomicBoolean(true); + return new BoxNetworkClient( + new OkHttpClient.Builder() + .connectionSpecs(Arrays.asList(ConnectionSpec.CLEARTEXT)) + .followRedirects(false) + .retryOnConnectionFailure(false) + .addInterceptor( + chain -> { + Request request = chain.request(); + bodies.add(requestBodyToString(request)); + if (firstRequest.getAndSet(false)) { + throw new IOException("Simulated network exception"); + } + return chain.proceed(request); + }) + .build()); + } + + private String requestBodyToString(Request request) throws IOException { + if (request.body() == null) { + return ""; + } + okio.Buffer buffer = new okio.Buffer(); + request.body().writeTo(buffer); + return buffer.readUtf8(); + } + + private String takeBody(MockWebServer server) throws Exception { + RecordedRequest request = server.takeRequest(); + return request.getBody().readUtf8(); + } + + private RetryStrategy retryWhen(RetryPredicate predicate) { + return new RetryStrategy() { + @Override + public boolean shouldRetry(FetchOptions options, FetchResponse response, int attemptNumber) { + return predicate.shouldRetry(options, response, attemptNumber); + } + + @Override + public double retryAfter(FetchOptions options, FetchResponse response, int attemptNumber) { + return 0; + } + }; + } + + private String assertionFrom(String body) throws java.io.UnsupportedEncodingException { + for (String part : body.split("&")) { + String[] keyValue = part.split("=", 2); + if (keyValue.length == 2 && Objects.equals(keyValue[0], "assertion")) { + return java.net.URLDecoder.decode(keyValue[1], StandardCharsets.UTF_8.name()); + } + } + throw new AssertionError("Missing JWT assertion"); + } + + private JwtPayload decodePayload(String assertion) throws Exception { + String[] parts = assertion.split("\\."); + assertEquals(3, parts.length); + byte[] payload = Base64.getUrlDecoder().decode(parts[1]); + return objectMapper.readValue(payload, JwtPayload.class); + } + + private interface RetryPredicate { + boolean shouldRetry(FetchOptions options, FetchResponse response, int attemptNumber); + } + + private static class CountingDataFactory implements RequestDataFactory { + int calls = 0; + + @Override + public JsonNode create() { + calls += 1; + return jsonToSerializedData("{\"attempt\":\"D" + (calls + 1) + "\"}"); + } + } + + private static class FixedPrivateKeyDecryptor implements PrivateKeyDecryptor { + private final PrivateKey privateKey; + + FixedPrivateKeyDecryptor(PrivateKey privateKey) { + this.privateKey = privateKey; + } + + @Override + public PrivateKey decryptPrivateKey(String encryptedPrivateKey, String passphrase) { + return privateKey; + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class JwtPayload { + public String jti; + public long exp; + } +} diff --git a/src/main/java/com/box/sdkgen/box/jwtauth/BoxJWTAuth.java b/src/main/java/com/box/sdkgen/box/jwtauth/BoxJWTAuth.java index edb1637a5..d306e5de2 100644 --- a/src/main/java/com/box/sdkgen/box/jwtauth/BoxJWTAuth.java +++ b/src/main/java/com/box/sdkgen/box/jwtauth/BoxJWTAuth.java @@ -1,27 +1,23 @@ package com.box.sdkgen.box.jwtauth; -import static com.box.sdkgen.internal.utils.UtilsManager.createJwtAssertion; -import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; -import static com.box.sdkgen.internal.utils.UtilsManager.getEpochTimeInSeconds; -import static com.box.sdkgen.internal.utils.UtilsManager.getUuid; import static com.box.sdkgen.internal.utils.UtilsManager.isBrowser; -import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; import com.box.sdkgen.box.errors.BoxSDKError; import com.box.sdkgen.box.tokenstorage.InMemoryTokenStorage; import com.box.sdkgen.box.tokenstorage.TokenStorage; -import com.box.sdkgen.internal.utils.JwtKey; -import com.box.sdkgen.internal.utils.JwtSignOptions; import com.box.sdkgen.managers.authorization.AuthorizationManager; import com.box.sdkgen.networking.auth.Authentication; +import com.box.sdkgen.networking.fetchoptions.FetchOptions; +import com.box.sdkgen.networking.fetchoptions.ResponseFormat; +import com.box.sdkgen.networking.fetchresponse.FetchResponse; import com.box.sdkgen.networking.network.NetworkSession; import com.box.sdkgen.schemas.accesstoken.AccessToken; import com.box.sdkgen.schemas.postoauth2revoke.PostOAuth2Revoke; import com.box.sdkgen.schemas.postoauth2token.PostOAuth2Token; import com.box.sdkgen.schemas.postoauth2token.PostOAuth2TokenGrantTypeField; import com.box.sdkgen.schemas.postoauth2token.PostOAuth2TokenSubjectTokenTypeField; +import com.box.sdkgen.serialization.json.JsonManager; import java.util.List; -import java.util.Map; public class BoxJWTAuth implements Authentication { @@ -68,33 +64,27 @@ public AccessToken refreshToken(NetworkSession networkSession) { if (isBrowser()) { throw new BoxSDKError("JWT auth is not supported in browser environment."); } - Map claims = - mapOf( - entryOf("exp", getEpochTimeInSeconds() + 30), - entryOf("box_sub_type", this.subjectType)); - JwtSignOptions jwtOptions = - new JwtSignOptions( - this.config.getAlgorithm(), - "https://api.box.com/oauth2/token", - this.config.getClientId(), - this.subjectId, - getUuid(), - this.config.getJwtKeyId(), - this.config.getPrivateKeyDecryptor()); - JwtKey jwtKey = new JwtKey(this.config.getPrivateKey(), this.config.getPrivateKeyPassphrase()); - String assertion = createJwtAssertion(claims, jwtKey, jwtOptions); - AuthorizationManager authManager = - new AuthorizationManager.Builder() - .networkSession((!(networkSession == null) ? networkSession : new NetworkSession())) + NetworkSession networkSessionToUse = + (!(networkSession == null) ? networkSession : new NetworkSession()); + JwtAccessTokenDataFactory dataFactory = + new JwtAccessTokenDataFactory.Builder(this.config) + .subjectId(this.subjectId) + .subjectType(this.subjectType) .build(); - AccessToken token = - authManager.requestAccessToken( - new PostOAuth2Token.Builder( - PostOAuth2TokenGrantTypeField.URN_IETF_PARAMS_OAUTH_GRANT_TYPE_JWT_BEARER) - .assertion(assertion) - .clientId(this.config.getClientId()) - .clientSecret(this.config.getClientSecret()) - .build()); + FetchResponse response = + networkSessionToUse + .getNetworkClient() + .fetch( + new FetchOptions.Builder( + String.join( + "", networkSessionToUse.getBaseUrls().getBaseUrl(), "/oauth2/token"), + "POST") + .dataFactory(dataFactory) + .contentType("application/x-www-form-urlencoded") + .responseFormat(ResponseFormat.JSON) + .networkSession(networkSessionToUse) + .build()); + AccessToken token = JsonManager.deserialize(response.getData(), AccessToken.class); this.tokenStorage.store(token); return token; } diff --git a/src/main/java/com/box/sdkgen/box/jwtauth/JwtAccessTokenDataFactory.java b/src/main/java/com/box/sdkgen/box/jwtauth/JwtAccessTokenDataFactory.java new file mode 100644 index 000000000..805784923 --- /dev/null +++ b/src/main/java/com/box/sdkgen/box/jwtauth/JwtAccessTokenDataFactory.java @@ -0,0 +1,101 @@ +package com.box.sdkgen.box.jwtauth; + +import static com.box.sdkgen.internal.utils.UtilsManager.createJwtAssertion; +import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; +import static com.box.sdkgen.internal.utils.UtilsManager.getEpochTimeInSeconds; +import static com.box.sdkgen.internal.utils.UtilsManager.getUuid; +import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; + +import com.box.sdkgen.internal.utils.JwtKey; +import com.box.sdkgen.internal.utils.JwtSignOptions; +import com.box.sdkgen.networking.fetchoptions.RequestDataFactory; +import com.box.sdkgen.schemas.postoauth2token.PostOAuth2Token; +import com.box.sdkgen.schemas.postoauth2token.PostOAuth2TokenGrantTypeField; +import com.box.sdkgen.serialization.json.JsonManager; +import com.fasterxml.jackson.databind.JsonNode; +import java.util.Map; + +/** + * Builds the body of a JWT bearer access token request. Each call signs a new assertion with a + * unique `jti`, so a retried request is not rejected as a replay. + */ +public class JwtAccessTokenDataFactory implements RequestDataFactory { + + /** JWT configuration used to sign the assertion */ + public final JWTConfig config; + + /** The ID of the user or enterprise to authenticate as */ + public String subjectId; + + /** The type of the subject ID, either 'user' or 'enterprise' */ + public String subjectType; + + public JwtAccessTokenDataFactory(JWTConfig config) { + this.config = config; + } + + protected JwtAccessTokenDataFactory(Builder builder) { + this.config = builder.config; + this.subjectId = builder.subjectId; + this.subjectType = builder.subjectType; + } + + /** Creates the access token request body with a newly signed JWT assertion. */ + @Override + public JsonNode create() { + Map claims = + mapOf( + entryOf("exp", getEpochTimeInSeconds() + 30), + entryOf("box_sub_type", this.subjectType)); + JwtSignOptions jwtOptions = + new JwtSignOptions( + this.config.getAlgorithm(), + "https://api.box.com/oauth2/token", + this.config.getClientId(), + this.subjectId, + getUuid(), + this.config.getJwtKeyId(), + this.config.getPrivateKeyDecryptor()); + JwtKey jwtKey = new JwtKey(this.config.getPrivateKey(), this.config.getPrivateKeyPassphrase()); + String assertion = createJwtAssertion(claims, jwtKey, jwtOptions); + PostOAuth2Token requestBody = + new PostOAuth2Token.Builder( + PostOAuth2TokenGrantTypeField.URN_IETF_PARAMS_OAUTH_GRANT_TYPE_JWT_BEARER) + .assertion(assertion) + .clientId(this.config.getClientId()) + .clientSecret(this.config.getClientSecret()) + .build(); + return JsonManager.serialize(requestBody); + } + + public JWTConfig getConfig() { + return config; + } + + public static class Builder { + + protected final JWTConfig config; + + protected String subjectId; + + protected String subjectType; + + public Builder(JWTConfig config) { + this.config = config; + } + + public Builder subjectId(String subjectId) { + this.subjectId = subjectId; + return this; + } + + public Builder subjectType(String subjectType) { + this.subjectType = subjectType; + return this; + } + + public JwtAccessTokenDataFactory build() { + return new JwtAccessTokenDataFactory(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/internal/utils/UtilsManager.java b/src/main/java/com/box/sdkgen/internal/utils/UtilsManager.java index a19d4f41a..d36a08824 100644 --- a/src/main/java/com/box/sdkgen/internal/utils/UtilsManager.java +++ b/src/main/java/com/box/sdkgen/internal/utils/UtilsManager.java @@ -268,7 +268,7 @@ public static String createJwtAssertion( jwtClaims.setSubject(jwtOptions.getSubject()); jwtClaims.setClaim("box_sub_type", claims.get("box_sub_type")); - jwtClaims.setGeneratedJwtId(64); + jwtClaims.setJwtId(jwtOptions.getJwtid()); JsonWebSignature jws = new JsonWebSignature(); jws.setPayload(jwtClaims.toJson()); diff --git a/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java b/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java index 208cd0603..dd203170e 100644 --- a/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java +++ b/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java @@ -135,13 +135,6 @@ public FetchResponse fetch(FetchOptions options) { NetworkSession networkSession = options.getNetworkSession() == null ? new NetworkSession() : options.getNetworkSession(); - FetchOptions fetchOptions = - networkSession.getInterceptors().stream() - .reduce( - options, - (modifiedOptions, interceptor) -> interceptor.beforeRequest(modifiedOptions), - (o1, o2) -> o2); - boolean authenticationNeeded = false; Request request; FetchResponse fetchResponse = new FetchResponse.Builder(0, new TreeMap<>()).build(); @@ -153,6 +146,20 @@ public FetchResponse fetch(FetchOptions options) { boolean shouldRetry = false; while (true) { + FetchOptions attemptOptions = + (attemptNumber > 1 || numberOfRetriesOnException > 0 || options.getData() == null) + && options.getDataFactory() != null + ? withData(options, options.getDataFactory().create()) + : options; + FetchOptions fetchOptions = applyInterceptors(attemptOptions, networkSession); + if (fetchOptions.getDataFactory() != null + && options.getDataFactory() == null + && (attemptNumber > 1 + || numberOfRetriesOnException > 0 + || fetchOptions.getData() == null)) { + fetchOptions = withData(fetchOptions, fetchOptions.getDataFactory().create()); + } + request = prepareRequest(fetchOptions, authenticationNeeded, networkSession); Response response = null; @@ -268,6 +275,31 @@ public FetchResponse fetch(FetchOptions options) { } } + private static FetchOptions applyInterceptors( + FetchOptions options, NetworkSession networkSession) { + return networkSession.getInterceptors().stream() + .reduce( + options, + (modifiedOptions, interceptor) -> interceptor.beforeRequest(modifiedOptions), + (o1, o2) -> o2); + } + + private static FetchOptions withData(FetchOptions options, JsonNode data) { + return new FetchOptions.Builder(options.getUrl(), options.getMethod()) + .params(options.getParams()) + .headers(options.getHeaders()) + .data(data) + .dataFactory(options.getDataFactory()) + .fileStream(options.getFileStream()) + .multipartData(options.getMultipartData()) + .contentType(options.getContentType()) + .responseFormat(options.getResponseFormat()) + .auth(options.getAuth()) + .networkSession(options.getNetworkSession()) + .followRedirects(options.getFollowRedirects()) + .build(); + } + private static Request prepareRequest( FetchOptions options, boolean reauthenticate, NetworkSession networkSession) { Request.Builder requestBuilder = new Request.Builder().url(options.getUrl()); diff --git a/src/main/java/com/box/sdkgen/networking/fetchoptions/FetchOptions.java b/src/main/java/com/box/sdkgen/networking/fetchoptions/FetchOptions.java index 6cf853922..bdc2f9a3d 100644 --- a/src/main/java/com/box/sdkgen/networking/fetchoptions/FetchOptions.java +++ b/src/main/java/com/box/sdkgen/networking/fetchoptions/FetchOptions.java @@ -25,6 +25,11 @@ public class FetchOptions { /** Request body of the request */ public JsonNode data; + /** + * Factory that builds a request body when `data` is not provided and rebuilds it for each retry. + */ + public RequestDataFactory dataFactory; + /** Stream data of the request */ public InputStream fileStream; @@ -63,6 +68,7 @@ protected FetchOptions(Builder builder) { this.params = builder.params; this.headers = builder.headers; this.data = builder.data; + this.dataFactory = builder.dataFactory; this.fileStream = builder.fileStream; this.multipartData = builder.multipartData; this.contentType = builder.contentType; @@ -92,6 +98,10 @@ public JsonNode getData() { return data; } + public RequestDataFactory getDataFactory() { + return dataFactory; + } + public InputStream getFileStream() { return fileStream; } @@ -132,6 +142,8 @@ public static class Builder { protected JsonNode data; + protected RequestDataFactory dataFactory; + protected InputStream fileStream; protected List multipartData; @@ -166,6 +178,11 @@ public Builder data(JsonNode data) { return this; } + public Builder dataFactory(RequestDataFactory dataFactory) { + this.dataFactory = dataFactory; + return this; + } + public Builder fileStream(InputStream fileStream) { this.fileStream = fileStream; return this; diff --git a/src/main/java/com/box/sdkgen/networking/fetchoptions/RequestDataFactory.java b/src/main/java/com/box/sdkgen/networking/fetchoptions/RequestDataFactory.java new file mode 100644 index 000000000..72975d17b --- /dev/null +++ b/src/main/java/com/box/sdkgen/networking/fetchoptions/RequestDataFactory.java @@ -0,0 +1,9 @@ +package com.box.sdkgen.networking.fetchoptions; + +import com.fasterxml.jackson.databind.JsonNode; + +public interface RequestDataFactory { + + /** Creates a new request body */ + JsonNode create(); +} From 1ce8ed24b4260f62ede0035d9ea36e97f8bce83c Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Tue, 17 Nov 2026 11:46:01 -0800 Subject: [PATCH 2/2] docs: publish ai_session docs (AGNTPLAT-3186) (box/box-openapi#630) --- .codegen.json | 2 +- docs/sdkgen/README.md | 1 + docs/sdkgen/aisessions.md | 74 +++++ .../java/com/box/sdkgen/client/BoxClient.java | 11 + .../aisessions/AiSessionsManager.java | 180 +++++++++++ .../DeleteAiSessionByIdV2026R0Headers.java | 68 +++++ .../GetAiSessionsV2026R0Headers.java | 68 +++++ .../GetAiSessionsV2026R0QueryParams.java | 147 +++++++++ ...sionsV2026R0QueryParamsDirectionField.java | 65 ++++ ...AiSessionsV2026R0QueryParamsSortField.java | 66 ++++ ...SessionsV2026R0QueryParamsSourceField.java | 64 ++++ .../signrequestbase/SignRequestBase.java | 8 +- .../aisessionsv2026r0/AiSessionsV2026R0.java | 117 +++++++ .../aisessionv2026r0/AiSessionV2026R0.java | 289 ++++++++++++++++++ .../AiSessionV2026R0SourceField.java | 64 ++++ .../AiSessionV2026R0TypeField.java | 64 ++++ 16 files changed, 1283 insertions(+), 5 deletions(-) create mode 100644 docs/sdkgen/aisessions.md create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/AiSessionsManager.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/DeleteAiSessionByIdV2026R0Headers.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0Headers.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParams.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsDirectionField.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSortField.java create mode 100644 src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSourceField.java create mode 100644 src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionsv2026r0/AiSessionsV2026R0.java create mode 100644 src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0.java create mode 100644 src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0SourceField.java create mode 100644 src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0TypeField.java diff --git a/.codegen.json b/.codegen.json index 06dd81ce5..32c0a240a 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "6772894", "specHash": "7f8494a", "version": "5.20.0" } +{ "engineHash": "6772894", "specHash": "7cec401", "version": "5.20.0" } diff --git a/docs/sdkgen/README.md b/docs/sdkgen/README.md index 6da729c0c..ce93ff79c 100644 --- a/docs/sdkgen/README.md +++ b/docs/sdkgen/README.md @@ -14,6 +14,7 @@ General explanations of the available functionality and examples of how to use the SDK are available by topic: * [Ai](ai.md) +* [Aisessions](aisessions.md) * [Aistudio](aistudio.md) * [Appitemassociations](appitemassociations.md) * [Archives](archives.md) diff --git a/docs/sdkgen/aisessions.md b/docs/sdkgen/aisessions.md new file mode 100644 index 000000000..a288f080b --- /dev/null +++ b/docs/sdkgen/aisessions.md @@ -0,0 +1,74 @@ +# AiSessionsManager + + +- [List AI sessions](#list-ai-sessions) +- [Delete AI session](#delete-ai-session) + +## List AI sessions + +Returns a marker-paginated list of the AI sessions that the authenticated +user can read and that were created through the Box public API. Entries are +ordered by `sort` and `direction`, defaulting to `updated_at` descending so +the most recently active session appears first. + +The access token must have both the `ai.readwrite` and `root_readwrite` +scopes. + +A page may contain fewer than `limit` entries while further pages remain. +Treat a non-null `next_marker` as the only signal that more results exist. + +This operation is performed by calling function `getAiSessionsV2026R0`. + +See the endpoint docs at +[API Reference](https://developer.box.com/reference/v2026.0/get-ai-sessions/). + +*Currently we don't have an example for calling `getAiSessionsV2026R0` in integration tests* + +### Arguments + +- queryParams `GetAiSessionsV2026R0QueryParams` + - Query parameters of getAiSessionsV2026R0 method +- headers `GetAiSessionsV2026R0Headers` + - Headers of getAiSessionsV2026R0 method + + +### Returns + +This function returns a value of type `AiSessionsV2026R0`. + +Returns a paginated list of AI sessions. + + +## Delete AI session + +Deletes an AI session created through the Box public API, together with its +agent tasks. The session's agent-generated files and uploaded files are +moved to the trash. Files attached as sources from elsewhere in Box are not +affected. Deleting a session does not stop a running task or notify the +agent. + +The access token must have both the `ai.readwrite` and `root_readwrite` +scopes. + +This operation is performed by calling function `deleteAiSessionByIdV2026R0`. + +See the endpoint docs at +[API Reference](https://developer.box.com/reference/v2026.0/delete-ai-sessions-id/). + +*Currently we don't have an example for calling `deleteAiSessionByIdV2026R0` in integration tests* + +### Arguments + +- aiSessionId `String` + - The unique identifier of the AI session. This is the same value returned as `id` by the list endpoint and used as the A2A `contextId`. Example: "23489723" +- headers `DeleteAiSessionByIdV2026R0Headers` + - Headers of deleteAiSessionByIdV2026R0 method + + +### Returns + +This function returns a value of type `void`. + +Returns an empty response when the AI session was successfully deleted. + + diff --git a/src/main/java/com/box/sdkgen/client/BoxClient.java b/src/main/java/com/box/sdkgen/client/BoxClient.java index a46b0c350..5cc1e6b45 100644 --- a/src/main/java/com/box/sdkgen/client/BoxClient.java +++ b/src/main/java/com/box/sdkgen/client/BoxClient.java @@ -4,6 +4,7 @@ import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; import com.box.sdkgen.managers.ai.AiManager; +import com.box.sdkgen.managers.aisessions.AiSessionsManager; import com.box.sdkgen.managers.aistudio.AiStudioManager; import com.box.sdkgen.managers.appitemassociations.AppItemAssociationsManager; import com.box.sdkgen.managers.archives.ArchivesManager; @@ -285,6 +286,8 @@ public class BoxClient { public final ShuttleManager shuttle; + public final AiSessionsManager aiSessions; + public BoxClient(Authentication auth) { this.auth = auth; this.networkSession = new NetworkSession.Builder().baseUrls(new BaseUrls()).build(); @@ -649,6 +652,8 @@ public BoxClient(Authentication auth) { new QueryManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); this.shuttle = new ShuttleManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); + this.aiSessions = + new AiSessionsManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); } protected BoxClient(Builder builder) { @@ -1015,6 +1020,8 @@ protected BoxClient(Builder builder) { new QueryManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); this.shuttle = new ShuttleManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); + this.aiSessions = + new AiSessionsManager.Builder().auth(this.auth).networkSession(this.networkSession).build(); } /** @@ -1490,6 +1497,10 @@ public ShuttleManager getShuttle() { return shuttle; } + public AiSessionsManager getAiSessions() { + return aiSessions; + } + public static class Builder { protected final Authentication auth; diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/AiSessionsManager.java b/src/main/java/com/box/sdkgen/managers/aisessions/AiSessionsManager.java new file mode 100644 index 000000000..50bc8ee3f --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/AiSessionsManager.java @@ -0,0 +1,180 @@ +package com.box.sdkgen.managers.aisessions; + +import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; +import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; +import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; +import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; +import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; + +import com.box.sdkgen.networking.auth.Authentication; +import com.box.sdkgen.networking.fetchoptions.FetchOptions; +import com.box.sdkgen.networking.fetchoptions.ResponseFormat; +import com.box.sdkgen.networking.fetchresponse.FetchResponse; +import com.box.sdkgen.networking.network.NetworkSession; +import com.box.sdkgen.schemas.v2026r0.aisessionsv2026r0.AiSessionsV2026R0; +import com.box.sdkgen.serialization.json.JsonManager; +import java.util.Map; + +public class AiSessionsManager { + + public Authentication auth; + + public NetworkSession networkSession; + + public AiSessionsManager() { + this.networkSession = new NetworkSession(); + } + + protected AiSessionsManager(Builder builder) { + this.auth = builder.auth; + this.networkSession = builder.networkSession; + } + + /** + * Returns a marker-paginated list of the AI sessions that the authenticated user can read and + * that were created through the Box public API. Entries are ordered by `sort` and `direction`, + * defaulting to `updated_at` descending so the most recently active session appears first. + * + *

The access token must have both the `ai.readwrite` and `root_readwrite` scopes. + * + *

A page may contain fewer than `limit` entries while further pages remain. Treat a non-null + * `next_marker` as the only signal that more results exist. + * + * @param queryParams Query parameters of getAiSessionsV2026R0 method + */ + public AiSessionsV2026R0 getAiSessionsV2026R0(GetAiSessionsV2026R0QueryParams queryParams) { + return getAiSessionsV2026R0(queryParams, new GetAiSessionsV2026R0Headers()); + } + + /** + * Returns a marker-paginated list of the AI sessions that the authenticated user can read and + * that were created through the Box public API. Entries are ordered by `sort` and `direction`, + * defaulting to `updated_at` descending so the most recently active session appears first. + * + *

The access token must have both the `ai.readwrite` and `root_readwrite` scopes. + * + *

A page may contain fewer than `limit` entries while further pages remain. Treat a non-null + * `next_marker` as the only signal that more results exist. + * + * @param queryParams Query parameters of getAiSessionsV2026R0 method + * @param headers Headers of getAiSessionsV2026R0 method + */ + public AiSessionsV2026R0 getAiSessionsV2026R0( + GetAiSessionsV2026R0QueryParams queryParams, GetAiSessionsV2026R0Headers headers) { + Map queryParamsMap = + prepareParams( + mapOf( + entryOf("source", convertToString(queryParams.getSource())), + entryOf("marker", convertToString(queryParams.getMarker())), + entryOf("sort", convertToString(queryParams.getSort())), + entryOf("direction", convertToString(queryParams.getDirection())), + entryOf("limit", convertToString(queryParams.getLimit())), + entryOf("client_ids", convertToString(queryParams.getClientIds())))); + Map headersMap = + prepareParams( + mergeMaps( + mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), + headers.getExtraHeaders())); + FetchResponse response = + this.networkSession + .getNetworkClient() + .fetch( + new FetchOptions.Builder( + String.join( + "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai_sessions"), + "GET") + .params(queryParamsMap) + .headers(headersMap) + .responseFormat(ResponseFormat.JSON) + .auth(this.auth) + .networkSession(this.networkSession) + .build()); + return JsonManager.deserialize(response.getData(), AiSessionsV2026R0.class); + } + + /** + * Deletes an AI session created through the Box public API, together with its agent tasks. The + * session's agent-generated files and uploaded files are moved to the trash. Files attached as + * sources from elsewhere in Box are not affected. Deleting a session does not stop a running task + * or notify the agent. + * + *

The access token must have both the `ai.readwrite` and `root_readwrite` scopes. + * + * @param aiSessionId The unique identifier of the AI session. This is the same value returned as + * `id` by the list endpoint and used as the A2A `contextId`. Example: "23489723" + */ + public void deleteAiSessionByIdV2026R0(String aiSessionId) { + deleteAiSessionByIdV2026R0(aiSessionId, new DeleteAiSessionByIdV2026R0Headers()); + } + + /** + * Deletes an AI session created through the Box public API, together with its agent tasks. The + * session's agent-generated files and uploaded files are moved to the trash. Files attached as + * sources from elsewhere in Box are not affected. Deleting a session does not stop a running task + * or notify the agent. + * + *

The access token must have both the `ai.readwrite` and `root_readwrite` scopes. + * + * @param aiSessionId The unique identifier of the AI session. This is the same value returned as + * `id` by the list endpoint and used as the A2A `contextId`. Example: "23489723" + * @param headers Headers of deleteAiSessionByIdV2026R0 method + */ + public void deleteAiSessionByIdV2026R0( + String aiSessionId, DeleteAiSessionByIdV2026R0Headers headers) { + Map headersMap = + prepareParams( + mergeMaps( + mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), + headers.getExtraHeaders())); + FetchResponse response = + this.networkSession + .getNetworkClient() + .fetch( + new FetchOptions.Builder( + String.join( + "", + this.networkSession.getBaseUrls().getBaseUrl(), + "/2.0/ai_sessions/", + convertToString(aiSessionId)), + "DELETE") + .headers(headersMap) + .responseFormat(ResponseFormat.NO_CONTENT) + .auth(this.auth) + .networkSession(this.networkSession) + .build()); + } + + public Authentication getAuth() { + return auth; + } + + public NetworkSession getNetworkSession() { + return networkSession; + } + + public static class Builder { + + protected Authentication auth; + + protected NetworkSession networkSession; + + public Builder() {} + + public Builder auth(Authentication auth) { + this.auth = auth; + return this; + } + + public Builder networkSession(NetworkSession networkSession) { + this.networkSession = networkSession; + return this; + } + + public AiSessionsManager build() { + if (this.networkSession == null) { + this.networkSession = new NetworkSession(); + } + return new AiSessionsManager(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/DeleteAiSessionByIdV2026R0Headers.java b/src/main/java/com/box/sdkgen/managers/aisessions/DeleteAiSessionByIdV2026R0Headers.java new file mode 100644 index 000000000..08eda388d --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/DeleteAiSessionByIdV2026R0Headers.java @@ -0,0 +1,68 @@ +package com.box.sdkgen.managers.aisessions; + +import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; + +import com.box.sdkgen.parameters.v2026r0.boxversionheaderv2026r0.BoxVersionHeaderV2026R0; +import com.box.sdkgen.serialization.json.EnumWrapper; +import java.util.Map; + +public class DeleteAiSessionByIdV2026R0Headers { + + /** Version header. */ + public EnumWrapper boxVersion; + + /** Extra headers that will be included in the HTTP request. */ + public Map extraHeaders; + + public DeleteAiSessionByIdV2026R0Headers() { + this.boxVersion = new EnumWrapper(BoxVersionHeaderV2026R0._2026_0); + this.extraHeaders = mapOf(); + } + + protected DeleteAiSessionByIdV2026R0Headers(Builder builder) { + this.boxVersion = builder.boxVersion; + this.extraHeaders = builder.extraHeaders; + } + + public EnumWrapper getBoxVersion() { + return boxVersion; + } + + public Map getExtraHeaders() { + return extraHeaders; + } + + public static class Builder { + + protected EnumWrapper boxVersion; + + protected Map extraHeaders; + + public Builder() {} + + public Builder boxVersion(BoxVersionHeaderV2026R0 boxVersion) { + this.boxVersion = new EnumWrapper(boxVersion); + return this; + } + + public Builder boxVersion(EnumWrapper boxVersion) { + this.boxVersion = boxVersion; + return this; + } + + public Builder extraHeaders(Map extraHeaders) { + this.extraHeaders = extraHeaders; + return this; + } + + public DeleteAiSessionByIdV2026R0Headers build() { + if (this.boxVersion == null) { + this.boxVersion = new EnumWrapper(BoxVersionHeaderV2026R0._2026_0); + } + if (this.extraHeaders == null) { + this.extraHeaders = mapOf(); + } + return new DeleteAiSessionByIdV2026R0Headers(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0Headers.java b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0Headers.java new file mode 100644 index 000000000..a2ab1a8b8 --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0Headers.java @@ -0,0 +1,68 @@ +package com.box.sdkgen.managers.aisessions; + +import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; + +import com.box.sdkgen.parameters.v2026r0.boxversionheaderv2026r0.BoxVersionHeaderV2026R0; +import com.box.sdkgen.serialization.json.EnumWrapper; +import java.util.Map; + +public class GetAiSessionsV2026R0Headers { + + /** Version header. */ + public EnumWrapper boxVersion; + + /** Extra headers that will be included in the HTTP request. */ + public Map extraHeaders; + + public GetAiSessionsV2026R0Headers() { + this.boxVersion = new EnumWrapper(BoxVersionHeaderV2026R0._2026_0); + this.extraHeaders = mapOf(); + } + + protected GetAiSessionsV2026R0Headers(Builder builder) { + this.boxVersion = builder.boxVersion; + this.extraHeaders = builder.extraHeaders; + } + + public EnumWrapper getBoxVersion() { + return boxVersion; + } + + public Map getExtraHeaders() { + return extraHeaders; + } + + public static class Builder { + + protected EnumWrapper boxVersion; + + protected Map extraHeaders; + + public Builder() {} + + public Builder boxVersion(BoxVersionHeaderV2026R0 boxVersion) { + this.boxVersion = new EnumWrapper(boxVersion); + return this; + } + + public Builder boxVersion(EnumWrapper boxVersion) { + this.boxVersion = boxVersion; + return this; + } + + public Builder extraHeaders(Map extraHeaders) { + this.extraHeaders = extraHeaders; + return this; + } + + public GetAiSessionsV2026R0Headers build() { + if (this.boxVersion == null) { + this.boxVersion = new EnumWrapper(BoxVersionHeaderV2026R0._2026_0); + } + if (this.extraHeaders == null) { + this.extraHeaders = mapOf(); + } + return new GetAiSessionsV2026R0Headers(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParams.java b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParams.java new file mode 100644 index 000000000..882d158c9 --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParams.java @@ -0,0 +1,147 @@ +package com.box.sdkgen.managers.aisessions; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import java.util.List; + +public class GetAiSessionsV2026R0QueryParams { + + /** Restricts the list to AI sessions with this origin. The only supported value is `api`. */ + public final EnumWrapper source; + + /** + * The position marker at which to begin returning results, as returned in `next_marker` by the + * previous page. Omit it for the first page. All other parameters must match the request that + * returned the marker. + */ + public String marker; + + /** + * The field to sort results by. Possible values are `created_at`, `updated_at`, and `name`. + * Default is `updated_at`, which advances on each turn of session activity. + */ + public EnumWrapper sort; + + /** + * The direction to sort results in, either ascending (`asc`) or descending (`desc`). Default is + * `desc`. + */ + public EnumWrapper direction; + + /** + * The maximum number of AI sessions to return per page. The maximum is `100`; larger values are + * treated as `100`. The server may return fewer entries than requested. + */ + public Integer limit; + + /** + * A comma-separated list of OAuth client IDs. Restricts the list to AI sessions created by any of + * these applications. Client IDs that match no application are ignored, so the response is an + * empty list if none of them match. Empty entries are ignored, and an empty value is treated as + * if the parameter were not provided. + */ + public List clientIds; + + public GetAiSessionsV2026R0QueryParams(GetAiSessionsV2026R0QueryParamsSourceField source) { + this.source = new EnumWrapper(source); + } + + public GetAiSessionsV2026R0QueryParams( + EnumWrapper source) { + this.source = source; + } + + protected GetAiSessionsV2026R0QueryParams(Builder builder) { + this.source = builder.source; + this.marker = builder.marker; + this.sort = builder.sort; + this.direction = builder.direction; + this.limit = builder.limit; + this.clientIds = builder.clientIds; + } + + public EnumWrapper getSource() { + return source; + } + + public String getMarker() { + return marker; + } + + public EnumWrapper getSort() { + return sort; + } + + public EnumWrapper getDirection() { + return direction; + } + + public Integer getLimit() { + return limit; + } + + public List getClientIds() { + return clientIds; + } + + public static class Builder { + + protected final EnumWrapper source; + + protected String marker; + + protected EnumWrapper sort; + + protected EnumWrapper direction; + + protected Integer limit; + + protected List clientIds; + + public Builder(GetAiSessionsV2026R0QueryParamsSourceField source) { + this.source = new EnumWrapper(source); + } + + public Builder(EnumWrapper source) { + this.source = source; + } + + public Builder marker(String marker) { + this.marker = marker; + return this; + } + + public Builder sort(GetAiSessionsV2026R0QueryParamsSortField sort) { + this.sort = new EnumWrapper(sort); + return this; + } + + public Builder sort(EnumWrapper sort) { + this.sort = sort; + return this; + } + + public Builder direction(GetAiSessionsV2026R0QueryParamsDirectionField direction) { + this.direction = new EnumWrapper(direction); + return this; + } + + public Builder direction(EnumWrapper direction) { + this.direction = direction; + return this; + } + + public Builder limit(Integer limit) { + this.limit = limit; + return this; + } + + public Builder clientIds(List clientIds) { + this.clientIds = clientIds; + return this; + } + + public GetAiSessionsV2026R0QueryParams build() { + return new GetAiSessionsV2026R0QueryParams(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsDirectionField.java b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsDirectionField.java new file mode 100644 index 000000000..c7c77b9ce --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsDirectionField.java @@ -0,0 +1,65 @@ +package com.box.sdkgen.managers.aisessions; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.box.sdkgen.serialization.json.Valuable; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.util.Arrays; + +public enum GetAiSessionsV2026R0QueryParamsDirectionField implements Valuable { + ASC("asc"), + DESC("desc"); + + private final String value; + + GetAiSessionsV2026R0QueryParamsDirectionField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + public static class GetAiSessionsV2026R0QueryParamsDirectionFieldDeserializer + extends JsonDeserializer> { + + public GetAiSessionsV2026R0QueryParamsDirectionFieldDeserializer() { + super(); + } + + @Override + public EnumWrapper deserialize( + JsonParser p, DeserializationContext ctxt) throws IOException { + String value = p.getValueAsString(); + return Arrays.stream(GetAiSessionsV2026R0QueryParamsDirectionField.values()) + .filter((v) -> v.getValue().equalsIgnoreCase(value)) + .findFirst() + .map(EnumWrapper::new) + .orElse(new EnumWrapper(value)); + } + } + + public static class GetAiSessionsV2026R0QueryParamsDirectionFieldSerializer + extends JsonSerializer> { + + public GetAiSessionsV2026R0QueryParamsDirectionFieldSerializer() { + super(); + } + + @Override + public void serialize( + EnumWrapper value, + JsonGenerator gen, + SerializerProvider serializers) + throws IOException { + gen.writeString(value.getStringValue()); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSortField.java b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSortField.java new file mode 100644 index 000000000..2fd9d26ab --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSortField.java @@ -0,0 +1,66 @@ +package com.box.sdkgen.managers.aisessions; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.box.sdkgen.serialization.json.Valuable; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.util.Arrays; + +public enum GetAiSessionsV2026R0QueryParamsSortField implements Valuable { + CREATED_AT("created_at"), + UPDATED_AT("updated_at"), + NAME("name"); + + private final String value; + + GetAiSessionsV2026R0QueryParamsSortField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + public static class GetAiSessionsV2026R0QueryParamsSortFieldDeserializer + extends JsonDeserializer> { + + public GetAiSessionsV2026R0QueryParamsSortFieldDeserializer() { + super(); + } + + @Override + public EnumWrapper deserialize( + JsonParser p, DeserializationContext ctxt) throws IOException { + String value = p.getValueAsString(); + return Arrays.stream(GetAiSessionsV2026R0QueryParamsSortField.values()) + .filter((v) -> v.getValue().equalsIgnoreCase(value)) + .findFirst() + .map(EnumWrapper::new) + .orElse(new EnumWrapper(value)); + } + } + + public static class GetAiSessionsV2026R0QueryParamsSortFieldSerializer + extends JsonSerializer> { + + public GetAiSessionsV2026R0QueryParamsSortFieldSerializer() { + super(); + } + + @Override + public void serialize( + EnumWrapper value, + JsonGenerator gen, + SerializerProvider serializers) + throws IOException { + gen.writeString(value.getStringValue()); + } + } +} diff --git a/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSourceField.java b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSourceField.java new file mode 100644 index 000000000..767d9eb60 --- /dev/null +++ b/src/main/java/com/box/sdkgen/managers/aisessions/GetAiSessionsV2026R0QueryParamsSourceField.java @@ -0,0 +1,64 @@ +package com.box.sdkgen.managers.aisessions; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.box.sdkgen.serialization.json.Valuable; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.util.Arrays; + +public enum GetAiSessionsV2026R0QueryParamsSourceField implements Valuable { + API("api"); + + private final String value; + + GetAiSessionsV2026R0QueryParamsSourceField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + public static class GetAiSessionsV2026R0QueryParamsSourceFieldDeserializer + extends JsonDeserializer> { + + public GetAiSessionsV2026R0QueryParamsSourceFieldDeserializer() { + super(); + } + + @Override + public EnumWrapper deserialize( + JsonParser p, DeserializationContext ctxt) throws IOException { + String value = p.getValueAsString(); + return Arrays.stream(GetAiSessionsV2026R0QueryParamsSourceField.values()) + .filter((v) -> v.getValue().equalsIgnoreCase(value)) + .findFirst() + .map(EnumWrapper::new) + .orElse(new EnumWrapper(value)); + } + } + + public static class GetAiSessionsV2026R0QueryParamsSourceFieldSerializer + extends JsonSerializer> { + + public GetAiSessionsV2026R0QueryParamsSourceFieldSerializer() { + super(); + } + + @Override + public void serialize( + EnumWrapper value, + JsonGenerator gen, + SerializerProvider serializers) + throws IOException { + gen.writeString(value.getStringValue()); + } + } +} diff --git a/src/main/java/com/box/sdkgen/schemas/signrequestbase/SignRequestBase.java b/src/main/java/com/box/sdkgen/schemas/signrequestbase/SignRequestBase.java index b144af275..c02786273 100644 --- a/src/main/java/com/box/sdkgen/schemas/signrequestbase/SignRequestBase.java +++ b/src/main/java/com/box/sdkgen/schemas/signrequestbase/SignRequestBase.java @@ -48,10 +48,10 @@ public class SignRequestBase extends SerializableObject { * Message to include in sign request email. The field is cleaned through sanitization of specific * characters. However, some html tags are allowed. Links included in the message are also * converted to hyperlinks in the email. The message may contain the following html tags including - * `a`, `abbr`, `acronym`, `b`, `blockquote`, `code`, `em`, `i`, `ul`, `li`, `ol`, and `strong`. - * Be aware that when the text to html ratio is too high, the email may end up in spam filters. - * Custom styles on these tags are not allowed. If this field is not passed, a default message - * will be used. + * `a`, `abbr`, `b`, `blockquote`, `code`, `em`, `i`, `ul`, `li`, `ol`, and `strong`. Be aware + * that when the text to html ratio is too high, the email may end up in spam filters. Custom + * styles on these tags are not allowed. If this field is not passed, a default message will be + * used. */ @JsonProperty("email_message") @Nullable diff --git a/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionsv2026r0/AiSessionsV2026R0.java b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionsv2026r0/AiSessionsV2026R0.java new file mode 100644 index 000000000..9918160b7 --- /dev/null +++ b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionsv2026r0/AiSessionsV2026R0.java @@ -0,0 +1,117 @@ +package com.box.sdkgen.schemas.v2026r0.aisessionsv2026r0; + +import com.box.sdkgen.internal.Nullable; +import com.box.sdkgen.internal.NullableFieldTracker; +import com.box.sdkgen.internal.SerializableObject; +import com.box.sdkgen.schemas.v2026r0.aisessionv2026r0.AiSessionV2026R0; +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Objects; + +/** A paginated list of AI sessions. */ +@JsonFilter("nullablePropertyFilter") +public class AiSessionsV2026R0 extends SerializableObject { + + /** A list of AI sessions. The list is empty when there are no results. */ + protected final List entries; + + /** + * The limit that was used for these entries. This will be the same as the `limit` query parameter + * unless that value exceeded the maximum value allowed. The maximum value varies by API. + */ + protected final long limit; + + /** The marker for the start of the next page of results. */ + @JsonProperty("next_marker") + @Nullable + protected String nextMarker; + + public AiSessionsV2026R0( + @JsonProperty("entries") List entries, @JsonProperty("limit") long limit) { + super(); + this.entries = entries; + this.limit = limit; + } + + protected AiSessionsV2026R0(Builder builder) { + super(); + this.entries = builder.entries; + this.limit = builder.limit; + this.nextMarker = builder.nextMarker; + markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); + } + + public List getEntries() { + return entries; + } + + public long getLimit() { + return limit; + } + + public String getNextMarker() { + return nextMarker; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AiSessionsV2026R0 casted = (AiSessionsV2026R0) o; + return Objects.equals(entries, casted.entries) + && Objects.equals(limit, casted.limit) + && Objects.equals(nextMarker, casted.nextMarker); + } + + @Override + public int hashCode() { + return Objects.hash(entries, limit, nextMarker); + } + + @Override + public String toString() { + return "AiSessionsV2026R0{" + + "entries='" + + entries + + '\'' + + ", " + + "limit='" + + limit + + '\'' + + ", " + + "nextMarker='" + + nextMarker + + '\'' + + "}"; + } + + public static class Builder extends NullableFieldTracker { + + protected final List entries; + + protected final long limit; + + protected String nextMarker; + + public Builder(List entries, long limit) { + super(); + this.entries = entries; + this.limit = limit; + } + + public Builder nextMarker(String nextMarker) { + this.nextMarker = nextMarker; + this.markNullableFieldAsSet("next_marker"); + return this; + } + + public AiSessionsV2026R0 build() { + return new AiSessionsV2026R0(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0.java b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0.java new file mode 100644 index 000000000..ee4513536 --- /dev/null +++ b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0.java @@ -0,0 +1,289 @@ +package com.box.sdkgen.schemas.v2026r0.aisessionv2026r0; + +import com.box.sdkgen.internal.Nullable; +import com.box.sdkgen.internal.NullableFieldTracker; +import com.box.sdkgen.internal.SerializableObject; +import com.box.sdkgen.internal.utils.DateTimeUtils; +import com.box.sdkgen.schemas.v2026r0.userbasev2026r0.UserBaseV2026R0; +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.time.OffsetDateTime; +import java.util.Objects; + +/** + * A standard representation of an AI session. An AI session holds the conversation state for a + * series of interactions with a Box AI agent. Its `id` is the A2A context identifier for that + * conversation. + */ +@JsonFilter("nullablePropertyFilter") +public class AiSessionV2026R0 extends SerializableObject { + + /** The value is always `ai_session`. */ + @JsonDeserialize(using = AiSessionV2026R0TypeField.AiSessionV2026R0TypeFieldDeserializer.class) + @JsonSerialize(using = AiSessionV2026R0TypeField.AiSessionV2026R0TypeFieldSerializer.class) + protected EnumWrapper type; + + /** + * The unique identifier for the AI session. This is also the A2A `contextId` for the + * conversation. Treat the value as opaque. + */ + protected final String id; + + /** + * The display name of the AI session. Sessions created through the A2A API are named + * automatically. The value is `null` only when no name was recorded. + */ + @Nullable protected String name; + + /** + * The origin of the AI session. Currently always `api`. New values may be added, so clients must + * tolerate values they do not recognize. + */ + @JsonDeserialize( + using = AiSessionV2026R0SourceField.AiSessionV2026R0SourceFieldDeserializer.class) + @JsonSerialize(using = AiSessionV2026R0SourceField.AiSessionV2026R0SourceFieldSerializer.class) + protected EnumWrapper source; + + /** + * The OAuth client ID of the application that created the AI session, as shown in the Developer + * Console. The value is `null` if the application is not known. + */ + @JsonProperty("client_id") + @Nullable + protected String clientId; + + @JsonProperty("created_by") + protected final UserBaseV2026R0 createdBy; + + @JsonProperty("updated_by") + protected final UserBaseV2026R0 updatedBy; + + /** The date and time when the AI session was created. */ + @JsonProperty("created_at") + @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) + @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) + protected final OffsetDateTime createdAt; + + /** + * The date and time when the AI session was last updated. It advances on each turn of session + * activity, so it also serves as the most recently used ordering. + */ + @JsonProperty("updated_at") + @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) + @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) + protected final OffsetDateTime updatedAt; + + public AiSessionV2026R0( + @JsonProperty("id") String id, + @JsonProperty("created_by") UserBaseV2026R0 createdBy, + @JsonProperty("updated_by") UserBaseV2026R0 updatedBy, + @JsonProperty("created_at") OffsetDateTime createdAt, + @JsonProperty("updated_at") OffsetDateTime updatedAt) { + super(); + this.id = id; + this.createdBy = createdBy; + this.updatedBy = updatedBy; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.type = new EnumWrapper(AiSessionV2026R0TypeField.AI_SESSION); + this.source = new EnumWrapper(AiSessionV2026R0SourceField.API); + } + + protected AiSessionV2026R0(Builder builder) { + super(); + this.type = builder.type; + this.id = builder.id; + this.name = builder.name; + this.source = builder.source; + this.clientId = builder.clientId; + this.createdBy = builder.createdBy; + this.updatedBy = builder.updatedBy; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); + } + + public EnumWrapper getType() { + return type; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public EnumWrapper getSource() { + return source; + } + + public String getClientId() { + return clientId; + } + + public UserBaseV2026R0 getCreatedBy() { + return createdBy; + } + + public UserBaseV2026R0 getUpdatedBy() { + return updatedBy; + } + + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AiSessionV2026R0 casted = (AiSessionV2026R0) o; + return Objects.equals(type, casted.type) + && Objects.equals(id, casted.id) + && Objects.equals(name, casted.name) + && Objects.equals(source, casted.source) + && Objects.equals(clientId, casted.clientId) + && Objects.equals(createdBy, casted.createdBy) + && Objects.equals(updatedBy, casted.updatedBy) + && Objects.equals(createdAt, casted.createdAt) + && Objects.equals(updatedAt, casted.updatedAt); + } + + @Override + public int hashCode() { + return Objects.hash( + type, id, name, source, clientId, createdBy, updatedBy, createdAt, updatedAt); + } + + @Override + public String toString() { + return "AiSessionV2026R0{" + + "type='" + + type + + '\'' + + ", " + + "id='" + + id + + '\'' + + ", " + + "name='" + + name + + '\'' + + ", " + + "source='" + + source + + '\'' + + ", " + + "clientId='" + + clientId + + '\'' + + ", " + + "createdBy='" + + createdBy + + '\'' + + ", " + + "updatedBy='" + + updatedBy + + '\'' + + ", " + + "createdAt='" + + createdAt + + '\'' + + ", " + + "updatedAt='" + + updatedAt + + '\'' + + "}"; + } + + public static class Builder extends NullableFieldTracker { + + protected EnumWrapper type; + + protected final String id; + + protected String name; + + protected EnumWrapper source; + + protected String clientId; + + protected final UserBaseV2026R0 createdBy; + + protected final UserBaseV2026R0 updatedBy; + + protected final OffsetDateTime createdAt; + + protected final OffsetDateTime updatedAt; + + public Builder( + String id, + UserBaseV2026R0 createdBy, + UserBaseV2026R0 updatedBy, + OffsetDateTime createdAt, + OffsetDateTime updatedAt) { + super(); + this.id = id; + this.createdBy = createdBy; + this.updatedBy = updatedBy; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public Builder type(AiSessionV2026R0TypeField type) { + this.type = new EnumWrapper(type); + return this; + } + + public Builder type(EnumWrapper type) { + this.type = type; + return this; + } + + public Builder name(String name) { + this.name = name; + this.markNullableFieldAsSet("name"); + return this; + } + + public Builder source(AiSessionV2026R0SourceField source) { + this.source = new EnumWrapper(source); + return this; + } + + public Builder source(EnumWrapper source) { + this.source = source; + return this; + } + + public Builder clientId(String clientId) { + this.clientId = clientId; + this.markNullableFieldAsSet("client_id"); + return this; + } + + public AiSessionV2026R0 build() { + if (this.type == null) { + this.type = + new EnumWrapper(AiSessionV2026R0TypeField.AI_SESSION); + } + if (this.source == null) { + this.source = new EnumWrapper(AiSessionV2026R0SourceField.API); + } + return new AiSessionV2026R0(this); + } + } +} diff --git a/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0SourceField.java b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0SourceField.java new file mode 100644 index 000000000..d63f712b4 --- /dev/null +++ b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0SourceField.java @@ -0,0 +1,64 @@ +package com.box.sdkgen.schemas.v2026r0.aisessionv2026r0; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.box.sdkgen.serialization.json.Valuable; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.util.Arrays; + +public enum AiSessionV2026R0SourceField implements Valuable { + API("api"); + + private final String value; + + AiSessionV2026R0SourceField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + public static class AiSessionV2026R0SourceFieldDeserializer + extends JsonDeserializer> { + + public AiSessionV2026R0SourceFieldDeserializer() { + super(); + } + + @Override + public EnumWrapper deserialize( + JsonParser p, DeserializationContext ctxt) throws IOException { + String value = p.getValueAsString(); + return Arrays.stream(AiSessionV2026R0SourceField.values()) + .filter((v) -> v.getValue().equalsIgnoreCase(value)) + .findFirst() + .map(EnumWrapper::new) + .orElse(new EnumWrapper(value)); + } + } + + public static class AiSessionV2026R0SourceFieldSerializer + extends JsonSerializer> { + + public AiSessionV2026R0SourceFieldSerializer() { + super(); + } + + @Override + public void serialize( + EnumWrapper value, + JsonGenerator gen, + SerializerProvider serializers) + throws IOException { + gen.writeString(value.getStringValue()); + } + } +} diff --git a/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0TypeField.java b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0TypeField.java new file mode 100644 index 000000000..ad1bcfb11 --- /dev/null +++ b/src/main/java/com/box/sdkgen/schemas/v2026r0/aisessionv2026r0/AiSessionV2026R0TypeField.java @@ -0,0 +1,64 @@ +package com.box.sdkgen.schemas.v2026r0.aisessionv2026r0; + +import com.box.sdkgen.serialization.json.EnumWrapper; +import com.box.sdkgen.serialization.json.Valuable; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.util.Arrays; + +public enum AiSessionV2026R0TypeField implements Valuable { + AI_SESSION("ai_session"); + + private final String value; + + AiSessionV2026R0TypeField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + public static class AiSessionV2026R0TypeFieldDeserializer + extends JsonDeserializer> { + + public AiSessionV2026R0TypeFieldDeserializer() { + super(); + } + + @Override + public EnumWrapper deserialize( + JsonParser p, DeserializationContext ctxt) throws IOException { + String value = p.getValueAsString(); + return Arrays.stream(AiSessionV2026R0TypeField.values()) + .filter((v) -> v.getValue().equalsIgnoreCase(value)) + .findFirst() + .map(EnumWrapper::new) + .orElse(new EnumWrapper(value)); + } + } + + public static class AiSessionV2026R0TypeFieldSerializer + extends JsonSerializer> { + + public AiSessionV2026R0TypeFieldSerializer() { + super(); + } + + @Override + public void serialize( + EnumWrapper value, + JsonGenerator gen, + SerializerProvider serializers) + throws IOException { + gen.writeString(value.getStringValue()); + } + } +}