diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aaa4cc9..017bd77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' @@ -17,7 +19,7 @@ jobs: timeout-minutes: 15 name: lint runs-on: ${{ github.repository == 'stainless-sdks/arcade-engine-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 @@ -44,7 +46,7 @@ jobs: contents: read id-token: write runs-on: ${{ github.repository == 'stainless-sdks/arcade-engine-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 diff --git a/.gitignore b/.gitignore index b1346e6..90b85e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log .gradle .idea .kotlin diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e8285b7..4f9005e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.5" + ".": "0.1.0-alpha.6" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index f7c06a5..f413d4c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/arcade-ai%2Farcade-engine-6ff494eafa2c154892716407682bb2296cff4f18c45765c5fb16bdf36f452ae1.yml -openapi_spec_hash: 63dde2481a7d51042a241bfba232b0b0 -config_hash: bf64816643634a621cd0ffd93d9c4347 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/arcade-ai/arcade-engine-22ce2a59bb1f308059c59ed19600698c5562a62c75f15c85429d186e9d8bdde6.yml +openapi_spec_hash: 2923fbda6c2899ade719d00540c34ff6 +config_hash: 2d4163acdeacd75903f978cd79c35d14 diff --git a/CHANGELOG.md b/CHANGELOG.md index 30401cf..f14ce42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,59 @@ # Changelog +## 0.1.0-alpha.6 (2026-05-07) + +Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/ArcadeAI/arcade-java/compare/v0.1.0-alpha.5...v0.1.0-alpha.6) + +### Features + +* **api:** api update ([aa56504](https://github.com/ArcadeAI/arcade-java/commit/aa565048f02eb4a21657d4e51c4975376968b579)) +* **api:** api update ([f7f972b](https://github.com/ArcadeAI/arcade-java/commit/f7f972bc274de10da54ffe2004d9d50fa16bc5a3)) +* **api:** api update ([acfd5b0](https://github.com/ArcadeAI/arcade-java/commit/acfd5b0aedbb445e1269a6b879111ff19c8aeef5)) +* **api:** api update ([5871f8b](https://github.com/ArcadeAI/arcade-java/commit/5871f8b7d0a2a89a6cbb57561a292b32381c74b6)) +* **client:** improve logging ([891246c](https://github.com/ArcadeAI/arcade-java/commit/891246cd432befc39f95ecc5fc69c123ab19414a)) +* **client:** more robust error parsing ([1043b59](https://github.com/ArcadeAI/arcade-java/commit/1043b591c5cee640130803058086ab444bd07b58)) +* **client:** support proxy authentication ([93ca773](https://github.com/ArcadeAI/arcade-java/commit/93ca7737f605353b1709e92b80ba5a0dc4075c41)) +* support setting headers via env ([219088d](https://github.com/ArcadeAI/arcade-java/commit/219088d6cdc541d7ae57d36a438f2e6b8894f106)) + + +### Bug Fixes + +* **client:** allow updating header/query affecting fields in `toBuilder()` ([f86e1f2](https://github.com/ArcadeAI/arcade-java/commit/f86e1f2dff33a369dd6d52119ce670747dfd2392)) + + +### Performance Improvements + +* **client:** create one json mapper ([be74413](https://github.com/ArcadeAI/arcade-java/commit/be744132658d4afa95b3d42edc256a3d245a931a)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([d5942be](https://github.com/ArcadeAI/arcade-java/commit/d5942be3ea63057a3267602dc72046e71d9a5855)) +* **internal:** bump ktfmt ([f38504b](https://github.com/ArcadeAI/arcade-java/commit/f38504b554f72ac9f701716ff1ad40ec5f1a47b2)) +* **internal:** codegen related update ([317c328](https://github.com/ArcadeAI/arcade-java/commit/317c328ecaf054e2fbdea4b6dbfb3a1451bb5070)) +* **internal:** tweak CI branches ([5213191](https://github.com/ArcadeAI/arcade-java/commit/521319108a7b064979e96ecf2fff5e74681b56bf)) +* **internal:** update gitignore ([c9b3d8f](https://github.com/ArcadeAI/arcade-java/commit/c9b3d8f8b7825876526e6dca16859c9f12fcce37)) +* **internal:** update multipart form array serialization ([abeec96](https://github.com/ArcadeAI/arcade-java/commit/abeec961730398bb0c49f01ea13312468be4787c)) +* **internal:** update retry delay tests ([993657b](https://github.com/ArcadeAI/arcade-java/commit/993657b3ac45eafee6b85f76a578f2c6daaacfe2)) +* remove duplicated dokka setup ([8e3a087](https://github.com/ArcadeAI/arcade-java/commit/8e3a087be33daae54aa87f67cdc62a22f566d504)) +* **tests:** bump steady to v0.19.4 ([0d022df](https://github.com/ArcadeAI/arcade-java/commit/0d022dfe027631ea83e1794bcb9e79824ab28f0f)) +* **tests:** bump steady to v0.19.5 ([d186f97](https://github.com/ArcadeAI/arcade-java/commit/d186f9769310ebff3584418642cc0b31a13e1d1c)) +* **tests:** bump steady to v0.19.6 ([b5094e5](https://github.com/ArcadeAI/arcade-java/commit/b5094e5507917137cf7b30c90e1028c122bd1331)) +* **tests:** bump steady to v0.19.7 ([231a1a7](https://github.com/ArcadeAI/arcade-java/commit/231a1a764782bb5bdcd1118630b3bbd544333aa4)) +* **tests:** bump steady to v0.20.1 ([b936990](https://github.com/ArcadeAI/arcade-java/commit/b93699052685356a902c34f38d8e46a617e77454)) +* **tests:** bump steady to v0.20.2 ([7dfba2e](https://github.com/ArcadeAI/arcade-java/commit/7dfba2ef15e2c5f6412a64f23cde8138159c42ea)) +* **tests:** bump steady to v0.22.1 ([bca6f99](https://github.com/ArcadeAI/arcade-java/commit/bca6f993c4876c486640b25ca1d41ff45f299263)) + + +### Documentation + +* clarify forwards compat behavior ([0053367](https://github.com/ArcadeAI/arcade-java/commit/00533674a82a9ec0815ef3d6cb12390927aa9cd2)) + + +### Refactors + +* **tests:** switch from prism to steady ([ae8ff34](https://github.com/ArcadeAI/arcade-java/commit/ae8ff343537d6ff24a3346fac27516c2bc3e07d9)) + ## 0.1.0-alpha.5 (2026-03-16) Full Changelog: [v0.1.0-alpha.4...v0.1.0-alpha.5](https://github.com/ArcadeAI/arcade-java/compare/v0.1.0-alpha.4...v0.1.0-alpha.5) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f910db9..ed588bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ Most tests require you to [run a mock server](https://github.com/stoplightio/pri ./scripts/mock --daemon ``` -The mock serer will run in the background allowing you to run tests from the command line `./gradlew test` or from your IDE. +The mock server will run in the background allowing you to run tests from the command line `./gradlew test` or from your IDE. To stop the mock server run: ```shell @@ -62,3 +62,22 @@ To format and fix all issues automatically: ```sh $ ./scripts/format ``` + +## Release and pull request process + +As mentioned above, most of the code in this repository is generated. So the pull requests process may different from what you are expecting. Here are the steps: + +- Custom code changes should target the `next` branch in [`ArcadeAI/arcade-java`](https://github.com/arcadeai/arcade-java). +- Be selective on what you are changing, as this may cause [merge conflicts](https://www.stainless.com/docs/sdks/configure/custom-code) with the generated code. +- Create a new pull request against `next`, CI will build and test it. +- Once it is merged to `next`, and when there have been upstream changes to the OpenAPI spec, you will see a pull request titled "release: " (where `` is the next version to be released) +- Review it, most of the changes will have been generated, make sure the changes from your pull request are included. +- Approve the PR, and merge it. + - The `next` branch will be rebased to `main`, so you will need to rewrite the branch, something like: `git fetch origin next && git reset --hard origin/next` +- Once changes are merged to `main` a CI job will deploy the version to [Maven Central](https://central.sonatype.com/search?q=arcade-java). There may be a delay between the time it is published until the time it shows up in the Maven Central search results. + +## Troubleshooting tips + +If you are running into issues deploying to Maven Central, run the [`Release Doctor`](https://github.com/ArcadeAI/arcade-java/actions/workflows/release-doctor.yml) CI job, this will check that the required environment variables are set correctly. + +The [`CI` workflow](https://github.com/ArcadeAI/arcade-java/blob/main/.github/workflows/ci.yml), includes a couple of `if` statments that look like: `github.repository == 'stainless-sdks/arcade-engine-java'`. These are ONLY used for pre-release builds when the Stainless SDK code is generated. These are NOT used currently (in the future if there are multiple Java project repositories, this Maven repository could be used to test nightly builds). Otherwise, [build from source](#building-the-repository-from-source). diff --git a/README.md b/README.md index e1b0ef4..c4b849f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/dev.arcade/arcade-java)](https://central.sonatype.com/artifact/dev.arcade/arcade-java/0.1.0-alpha.5) -[![javadoc](https://javadoc.io/badge2/dev.arcade/arcade-java/0.1.0-alpha.5/javadoc.svg)](https://javadoc.io/doc/dev.arcade/arcade-java/0.1.0-alpha.5) +[![Maven Central](https://img.shields.io/maven-central/v/dev.arcade/arcade-java)](https://central.sonatype.com/artifact/dev.arcade/arcade-java/0.1.0-alpha.6) +[![javadoc](https://javadoc.io/badge2/dev.arcade/arcade-java/0.1.0-alpha.6/javadoc.svg)](https://javadoc.io/doc/dev.arcade/arcade-java/0.1.0-alpha.6) @@ -13,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [docs.arcade.dev](https://docs.arcade.dev). Javadocs are available on [javadoc.io](https://javadoc.io/doc/dev.arcade/arcade-java/0.1.0-alpha.5). +The REST API documentation can be found on [docs.arcade.dev](https://docs.arcade.dev). Javadocs are available on [javadoc.io](https://javadoc.io/doc/dev.arcade/arcade-java/0.1.0-alpha.6). @@ -24,7 +24,7 @@ The REST API documentation can be found on [docs.arcade.dev](https://docs.arcade ### Gradle ```kotlin -implementation("dev.arcade:arcade-java:0.1.0-alpha.5") +implementation("dev.arcade:arcade-java:0.1.0-alpha.6") ``` ### Maven @@ -33,7 +33,7 @@ implementation("dev.arcade:arcade-java:0.1.0-alpha.5") dev.arcade arcade-java - 0.1.0-alpha.5 + 0.1.0-alpha.6 ``` @@ -50,7 +50,6 @@ import dev.arcade.client.ArcadeClient; import dev.arcade.client.okhttp.ArcadeOkHttpClient; import dev.arcade.models.tools.ExecuteToolRequest; import dev.arcade.models.tools.ExecuteToolResponse; -import dev.arcade.models.tools.ToolExecuteParams; // Configures using the `arcade.apiKey` and `arcade.baseUrl` system properties // Or configures using the `ARCADE_API_KEY` and `ARCADE_BASE_URL` environment variables @@ -186,7 +185,6 @@ import dev.arcade.client.ArcadeClient; import dev.arcade.client.okhttp.ArcadeOkHttpClient; import dev.arcade.models.tools.ExecuteToolRequest; import dev.arcade.models.tools.ExecuteToolResponse; -import dev.arcade.models.tools.ToolExecuteParams; import java.util.concurrent.CompletableFuture; // Configures using the `arcade.apiKey` and `arcade.baseUrl` system properties @@ -206,7 +204,6 @@ import dev.arcade.client.ArcadeClientAsync; import dev.arcade.client.okhttp.ArcadeOkHttpClientAsync; import dev.arcade.models.tools.ExecuteToolRequest; import dev.arcade.models.tools.ExecuteToolResponse; -import dev.arcade.models.tools.ToolExecuteParams; import java.util.concurrent.CompletableFuture; // Configures using the `arcade.apiKey` and `arcade.baseUrl` system properties @@ -232,7 +229,6 @@ import dev.arcade.core.http.Headers; import dev.arcade.core.http.HttpResponseFor; import dev.arcade.models.chat.ChatRequest; import dev.arcade.models.chat.ChatResponse; -import dev.arcade.models.chat.completions.CompletionCreateParams; ChatRequest params = ChatRequest.builder().build(); HttpResponseFor chatResponse = client.chat().completions().withRawResponse().create(params); @@ -376,8 +372,6 @@ while (true) { ## Logging -The SDK uses the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor). - Enable logging by setting the `ARCADE_LOG` environment variable to `info`: ```sh @@ -390,6 +384,19 @@ Or to `debug` for more verbose logging: export ARCADE_LOG=debug ``` +Or configure the client manually using the `logLevel` method: + +```java +import dev.arcade.client.ArcadeClient; +import dev.arcade.client.okhttp.ArcadeOkHttpClient; +import dev.arcade.core.LogLevel; + +ArcadeClient client = ArcadeOkHttpClient.builder() + .fromEnv() + .logLevel(LogLevel.INFO) + .build(); +``` + ## ProGuard and R8 Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `arcade-java-core` is published with a [configuration file](arcade-java-core/src/main/resources/META-INF/proguard/arcade-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage). @@ -484,6 +491,21 @@ ArcadeClient client = ArcadeOkHttpClient.builder() .build(); ``` +If the proxy responds with `407 Proxy Authentication Required`, supply credentials by also configuring `proxyAuthenticator`: + +```java +import dev.arcade.client.ArcadeClient; +import dev.arcade.client.okhttp.ArcadeOkHttpClient; +import dev.arcade.core.http.ProxyAuthenticator; + +ArcadeClient client = ArcadeOkHttpClient.builder() + .fromEnv() + .proxy(...) + // Or a custom implementation of `ProxyAuthenticator`. + .proxyAuthenticator(ProxyAuthenticator.basic("username", "password")) + .build(); +``` + ### Connection pooling To customize the underlying OkHttp connection pool, configure the client using the `maxIdleConnections` and `keepAliveDuration` methods: @@ -710,7 +732,9 @@ In rare cases, the API may return a response that doesn't match the expected typ By default, the SDK will not throw an exception in this case. It will throw [`ArcadeInvalidDataException`](arcade-java-core/src/main/kotlin/dev/arcade/errors/ArcadeInvalidDataException.kt) only if you directly access the property. -If you would prefer to check that the response is completely well-typed upfront, then either call `validate()`: +Validating the response is _not_ forwards compatible with new types from the API for existing fields. + +If you would still prefer to check that the response is completely well-typed upfront, then either call `validate()`: ```java import dev.arcade.models.tools.ExecuteToolResponse; diff --git a/arcade-java-client-okhttp/build.gradle.kts b/arcade-java-client-okhttp/build.gradle.kts index 72ac6cf..694a868 100644 --- a/arcade-java-client-okhttp/build.gradle.kts +++ b/arcade-java-client-okhttp/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { api(project(":arcade-java-core")) implementation("com.squareup.okhttp3:okhttp:4.12.0") - implementation("com.squareup.okhttp3:logging-interceptor:4.12.0") testImplementation(kotlin("test")) testImplementation("org.assertj:assertj-core:3.27.7") diff --git a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClient.kt b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClient.kt index df8b6ec..f4b0a08 100644 --- a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClient.kt +++ b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClient.kt @@ -6,11 +6,13 @@ import com.fasterxml.jackson.databind.json.JsonMapper import dev.arcade.client.ArcadeClient import dev.arcade.client.ArcadeClientImpl import dev.arcade.core.ClientOptions +import dev.arcade.core.LogLevel import dev.arcade.core.Sleeper import dev.arcade.core.Timeout import dev.arcade.core.http.AsyncStreamResponse import dev.arcade.core.http.Headers import dev.arcade.core.http.HttpClient +import dev.arcade.core.http.ProxyAuthenticator import dev.arcade.core.http.QueryParams import dev.arcade.core.jsonMapper import java.net.Proxy @@ -49,6 +51,7 @@ class ArcadeOkHttpClient private constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var sslSocketFactory: SSLSocketFactory? = null @@ -79,6 +82,20 @@ class ArcadeOkHttpClient private constructor() { /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + /** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication + * Required`. + */ + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + + /** + * Alias for calling [Builder.proxyAuthenticator] with `proxyAuthenticator.orElse(null)`. + */ + fun proxyAuthenticator(proxyAuthenticator: Optional) = + proxyAuthenticator(proxyAuthenticator.getOrNull()) + /** * The maximum number of idle connections kept by the underlying OkHttp connection pool. * @@ -230,6 +247,9 @@ class ArcadeOkHttpClient private constructor() { /** * Whether to call `validate` on every response before returning it. * + * Setting this to `true` is _not_ forwards compatible with new types from the API for + * existing fields. + * * Defaults to false, which means the shape of the response will not be validated upfront. * Instead, validation will only occur for the parts of the response that are accessed. */ @@ -271,6 +291,15 @@ class ArcadeOkHttpClient private constructor() { */ fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } + /** + * The level at which to log request and response information. + * + * [fromEnv] will set the level from environment variables. See [LogLevel.fromEnv]. + * + * Defaults to [LogLevel.fromEnv]. + */ + fun logLevel(logLevel: LogLevel) = apply { clientOptions.logLevel(logLevel) } + /** API key used for authorization in header */ fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) } @@ -373,6 +402,7 @@ class ArcadeOkHttpClient private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .proxyAuthenticator(proxyAuthenticator) .maxIdleConnections(maxIdleConnections) .keepAliveDuration(keepAliveDuration) .dispatcherExecutorService(dispatcherExecutorService) diff --git a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClientAsync.kt b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClientAsync.kt index 5eee0ac..85fa44d 100644 --- a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClientAsync.kt +++ b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/ArcadeOkHttpClientAsync.kt @@ -6,11 +6,13 @@ import com.fasterxml.jackson.databind.json.JsonMapper import dev.arcade.client.ArcadeClientAsync import dev.arcade.client.ArcadeClientAsyncImpl import dev.arcade.core.ClientOptions +import dev.arcade.core.LogLevel import dev.arcade.core.Sleeper import dev.arcade.core.Timeout import dev.arcade.core.http.AsyncStreamResponse import dev.arcade.core.http.Headers import dev.arcade.core.http.HttpClient +import dev.arcade.core.http.ProxyAuthenticator import dev.arcade.core.http.QueryParams import dev.arcade.core.jsonMapper import java.net.Proxy @@ -49,6 +51,7 @@ class ArcadeOkHttpClientAsync private constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var sslSocketFactory: SSLSocketFactory? = null @@ -79,6 +82,20 @@ class ArcadeOkHttpClientAsync private constructor() { /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + /** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication + * Required`. + */ + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + + /** + * Alias for calling [Builder.proxyAuthenticator] with `proxyAuthenticator.orElse(null)`. + */ + fun proxyAuthenticator(proxyAuthenticator: Optional) = + proxyAuthenticator(proxyAuthenticator.getOrNull()) + /** * The maximum number of idle connections kept by the underlying OkHttp connection pool. * @@ -230,6 +247,9 @@ class ArcadeOkHttpClientAsync private constructor() { /** * Whether to call `validate` on every response before returning it. * + * Setting this to `true` is _not_ forwards compatible with new types from the API for + * existing fields. + * * Defaults to false, which means the shape of the response will not be validated upfront. * Instead, validation will only occur for the parts of the response that are accessed. */ @@ -271,6 +291,15 @@ class ArcadeOkHttpClientAsync private constructor() { */ fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } + /** + * The level at which to log request and response information. + * + * [fromEnv] will set the level from environment variables. See [LogLevel.fromEnv]. + * + * Defaults to [LogLevel.fromEnv]. + */ + fun logLevel(logLevel: LogLevel) = apply { clientOptions.logLevel(logLevel) } + /** API key used for authorization in header */ fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) } @@ -373,6 +402,7 @@ class ArcadeOkHttpClientAsync private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .proxyAuthenticator(proxyAuthenticator) .maxIdleConnections(maxIdleConnections) .keepAliveDuration(keepAliveDuration) .dispatcherExecutorService(dispatcherExecutorService) diff --git a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/OkHttpClient.kt b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/OkHttpClient.kt index decc575..da745ff 100644 --- a/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/OkHttpClient.kt +++ b/arcade-java-client-okhttp/src/main/kotlin/dev/arcade/client/okhttp/OkHttpClient.kt @@ -8,9 +8,11 @@ import dev.arcade.core.http.HttpMethod import dev.arcade.core.http.HttpRequest import dev.arcade.core.http.HttpRequestBody import dev.arcade.core.http.HttpResponse +import dev.arcade.core.http.ProxyAuthenticator import dev.arcade.errors.ArcadeIoException import java.io.IOException import java.io.InputStream +import java.io.OutputStream import java.net.Proxy import java.time.Duration import java.util.concurrent.CancellationException @@ -20,10 +22,12 @@ import java.util.concurrent.TimeUnit import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager +import kotlin.jvm.optionals.getOrNull import okhttp3.Call import okhttp3.Callback import okhttp3.ConnectionPool import okhttp3.Dispatcher +import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType @@ -31,8 +35,9 @@ import okhttp3.Request import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response -import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink +import okio.buffer +import okio.sink class OkHttpClient internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient { @@ -41,7 +46,7 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie val call = newCall(request, requestOptions) return try { - call.execute().toResponse() + call.execute().toHttpResponse() } catch (e: IOException) { throw ArcadeIoException("Request failed", e) } finally { @@ -59,7 +64,7 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie call.enqueue( object : Callback { override fun onResponse(call: Call, response: Response) { - future.complete(response.toResponse()) + future.complete(response.toHttpResponse()) } override fun onFailure(call: Call, e: IOException) { @@ -87,18 +92,6 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie private fun newCall(request: HttpRequest, requestOptions: RequestOptions): Call { val clientBuilder = okHttpClient.newBuilder() - val logLevel = - when (System.getenv("ARCADE_LOG")?.lowercase()) { - "info" -> HttpLoggingInterceptor.Level.BASIC - "debug" -> HttpLoggingInterceptor.Level.BODY - else -> null - } - if (logLevel != null) { - clientBuilder.addNetworkInterceptor( - HttpLoggingInterceptor().setLevel(logLevel).apply { redactHeader("Authorization") } - ) - } - requestOptions.timeout?.let { clientBuilder .connectTimeout(it.connect()) @@ -111,89 +104,6 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie return client.newCall(request.toRequest(client)) } - private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient): Request { - var body: RequestBody? = body?.toRequestBody() - if (body == null && requiresBody(method)) { - body = "".toRequestBody() - } - - val builder = Request.Builder().url(toUrl()).method(method.name, body) - headers.names().forEach { name -> - headers.values(name).forEach { builder.addHeader(name, it) } - } - - if ( - !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 - ) { - builder.addHeader( - "X-Stainless-Read-Timeout", - Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), - ) - } - if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { - builder.addHeader( - "X-Stainless-Timeout", - Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), - ) - } - - return builder.build() - } - - /** `OkHttpClient` always requires a request body for some methods. */ - private fun requiresBody(method: HttpMethod): Boolean = - when (method) { - HttpMethod.POST, - HttpMethod.PUT, - HttpMethod.PATCH -> true - else -> false - } - - private fun HttpRequest.toUrl(): String { - val builder = baseUrl.toHttpUrl().newBuilder() - pathSegments.forEach(builder::addPathSegment) - queryParams.keys().forEach { key -> - queryParams.values(key).forEach { builder.addQueryParameter(key, it) } - } - - return builder.toString() - } - - private fun HttpRequestBody.toRequestBody(): RequestBody { - val mediaType = contentType()?.toMediaType() - val length = contentLength() - - return object : RequestBody() { - override fun contentType(): MediaType? = mediaType - - override fun contentLength(): Long = length - - override fun isOneShot(): Boolean = !repeatable() - - override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream()) - } - } - - private fun Response.toResponse(): HttpResponse { - val headers = headers.toHeaders() - - return object : HttpResponse { - override fun statusCode(): Int = code - - override fun headers(): Headers = headers - - override fun body(): InputStream = body!!.byteStream() - - override fun close() = body!!.close() - } - } - - private fun okhttp3.Headers.toHeaders(): Headers { - val headersBuilder = Headers.builder() - forEach { (name, value) -> headersBuilder.put(name, value) } - return headersBuilder.build() - } - companion object { @JvmStatic fun builder() = Builder() } @@ -202,6 +112,7 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var dispatcherExecutorService: ExecutorService? = null @@ -215,6 +126,10 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + /** * Sets the maximum number of idle connections kept by the underlying [ConnectionPool]. * @@ -264,6 +179,19 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie .callTimeout(timeout.request()) .proxy(proxy) .apply { + proxyAuthenticator?.let { auth -> + proxyAuthenticator { route, response -> + auth + .authenticate( + route?.proxy ?: Proxy.NO_PROXY, + response.request.toHttpRequest(), + response.toHttpResponse(), + ) + .getOrNull() + ?.toRequest(client = null) + } + } + dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) } val maxIdleConnections = maxIdleConnections @@ -303,3 +231,126 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie ) } } + +private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient?): Request { + var body: RequestBody? = body?.toRequestBody() + if (body == null && requiresBody(method)) { + body = "".toRequestBody() + } + + val builder = Request.Builder().url(toUrl()).method(method.name, body) + headers.names().forEach { name -> headers.values(name).forEach { builder.addHeader(name, it) } } + + if (client != null) { + if ( + !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 + ) { + builder.addHeader( + "X-Stainless-Read-Timeout", + Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), + ) + } + if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { + builder.addHeader( + "X-Stainless-Timeout", + Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), + ) + } + } + + return builder.build() +} + +/** `OkHttpClient` always requires a request body for some methods. */ +private fun requiresBody(method: HttpMethod): Boolean = + when (method) { + HttpMethod.POST, + HttpMethod.PUT, + HttpMethod.PATCH -> true + else -> false + } + +private fun HttpRequest.toUrl(): String { + val builder = baseUrl.toHttpUrl().newBuilder() + pathSegments.forEach(builder::addPathSegment) + queryParams.keys().forEach { key -> + queryParams.values(key).forEach { builder.addQueryParameter(key, it) } + } + + return builder.toString() +} + +private fun HttpRequestBody.toRequestBody(): RequestBody { + val mediaType = contentType()?.toMediaType() + val length = contentLength() + + return object : RequestBody() { + override fun contentType(): MediaType? = mediaType + + override fun contentLength(): Long = length + + override fun isOneShot(): Boolean = !repeatable() + + override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream()) + } +} + +private fun Request.toHttpRequest(): HttpRequest { + val builder = HttpRequest.builder().method(HttpMethod.valueOf(method)).baseUrl(url.toBaseUrl()) + url.pathSegments.forEach(builder::addPathSegment) + url.queryParameterNames.forEach { name -> + url.queryParameterValues(name).filterNotNull().forEach { builder.putQueryParam(name, it) } + } + headers.forEach { (name, value) -> builder.putHeader(name, value) } + body?.let { builder.body(it.toHttpRequestBody()) } + return builder.build() +} + +private fun HttpUrl.toBaseUrl(): String = buildString { + append(scheme).append("://").append(host) + if (port != HttpUrl.defaultPort(scheme)) { + append(":").append(port) + } +} + +private fun RequestBody.toHttpRequestBody(): HttpRequestBody { + val mediaType = contentType()?.toString() + val length = contentLength() + val isOneShot = isOneShot() + val source = this + return object : HttpRequestBody { + override fun contentType(): String? = mediaType + + override fun contentLength(): Long = length + + override fun repeatable(): Boolean = !isOneShot + + override fun writeTo(outputStream: OutputStream) { + val sink = outputStream.sink().buffer() + source.writeTo(sink) + sink.flush() + } + + override fun close() {} + } +} + +private fun Response.toHttpResponse(): HttpResponse { + val headers = headers.toHeaders() + + return object : HttpResponse { + override fun statusCode(): Int = code + + override fun headers(): Headers = headers + + override fun body(): InputStream = body!!.byteStream() + + override fun close() = body!!.close() + } +} + +private fun okhttp3.Headers.toHeaders(): Headers { + val headersBuilder = Headers.builder() + forEach { (name, value) -> headersBuilder.put(name, value) } + return headersBuilder.build() +} diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/ClientOptions.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/ClientOptions.kt index 65f5de9..8698772 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/core/ClientOptions.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/ClientOptions.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper import dev.arcade.core.http.AsyncStreamResponse import dev.arcade.core.http.Headers import dev.arcade.core.http.HttpClient +import dev.arcade.core.http.LoggingHttpClient import dev.arcade.core.http.PhantomReachableClosingHttpClient import dev.arcade.core.http.QueryParams import dev.arcade.core.http.RetryingHttpClient @@ -80,6 +81,9 @@ private constructor( /** * Whether to call `validate` on every response before returning it. * + * Setting this to `true` is _not_ forwards compatible with new types from the API for existing + * fields. + * * Defaults to false, which means the shape of the response will not be validated upfront. * Instead, validation will only occur for the parts of the response that are accessed. */ @@ -107,6 +111,14 @@ private constructor( * Defaults to 2. */ @get:JvmName("maxRetries") val maxRetries: Int, + /** + * The level at which to log request and response information. + * + * [fromEnv] will set the level from environment variables. See [LogLevel.fromEnv]. + * + * Defaults to [LogLevel.fromEnv]. + */ + @get:JvmName("logLevel") val logLevel: LogLevel, /** API key used for authorization in header */ @get:JvmName("apiKey") val apiKey: String, ) { @@ -164,6 +176,7 @@ private constructor( private var responseValidation: Boolean = false private var timeout: Timeout = Timeout.default() private var maxRetries: Int = 2 + private var logLevel: LogLevel = LogLevel.fromEnv() private var apiKey: String? = null @JvmSynthetic @@ -180,6 +193,7 @@ private constructor( responseValidation = clientOptions.responseValidation timeout = clientOptions.timeout maxRetries = clientOptions.maxRetries + logLevel = clientOptions.logLevel apiKey = clientOptions.apiKey } @@ -260,6 +274,9 @@ private constructor( /** * Whether to call `validate` on every response before returning it. * + * Setting this to `true` is _not_ forwards compatible with new types from the API for + * existing fields. + * * Defaults to false, which means the shape of the response will not be validated upfront. * Instead, validation will only occur for the parts of the response that are accessed. */ @@ -301,6 +318,15 @@ private constructor( */ fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries } + /** + * The level at which to log request and response information. + * + * [fromEnv] will set the level from environment variables. See [LogLevel.fromEnv]. + * + * Defaults to [LogLevel.fromEnv]. + */ + fun logLevel(logLevel: LogLevel) = apply { this.logLevel = logLevel } + /** API key used for authorization in header */ fun apiKey(apiKey: String) = apply { this.apiKey = apiKey } @@ -399,12 +425,21 @@ private constructor( * System properties take precedence over environment variables. */ fun fromEnv() = apply { + logLevel(LogLevel.fromEnv()) (System.getProperty("arcade.baseUrl") ?: System.getenv("ARCADE_BASE_URL"))?.let { baseUrl(it) } (System.getProperty("arcade.apiKey") ?: System.getenv("ARCADE_API_KEY"))?.let { apiKey(it) } + System.getenv("ARCADE_CUSTOM_HEADERS")?.let { customHeadersEnv -> + for (line in customHeadersEnv.split("\n")) { + val colon = line.indexOf(':') + if (colon >= 0) { + putHeader(line.substring(0, colon).trim(), line.substring(colon + 1).trim()) + } + } + } } /** @@ -453,18 +488,25 @@ private constructor( headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) headers.put("X-Stainless-Kotlin-Version", KotlinVersion.CURRENT.toString()) + // We replace after all the default headers to allow end-users to overwrite them. + headers.replaceAll(this.headers.build()) + queryParams.replaceAll(this.queryParams.build()) apiKey.let { if (!it.isEmpty()) { - headers.put("Authorization", it) + headers.replace("Authorization", it) } } - headers.replaceAll(this.headers.build()) - queryParams.replaceAll(this.queryParams.build()) return ClientOptions( httpClient, RetryingHttpClient.builder() - .httpClient(httpClient) + .httpClient( + LoggingHttpClient.builder() + .httpClient(httpClient) + .clock(clock) + .level(logLevel) + .build() + ) .sleeper(sleeper) .clock(clock) .maxRetries(maxRetries) @@ -480,6 +522,7 @@ private constructor( responseValidation, timeout, maxRetries, + logLevel, apiKey, ) } diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/LogLevel.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/LogLevel.kt new file mode 100644 index 0000000..cfd4b89 --- /dev/null +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/LogLevel.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package dev.arcade.core + +/** The level at which to log request and response information. */ +enum class LogLevel { + /** No logging. */ + OFF, + /** Minimal request and response summary logs. No headers or bodies are logged. */ + INFO, + /** [INFO] logs plus details about request failures. */ + ERROR, + /** + * Full request and response logs. Sensitive headers are redacted, but sensitive data in request + * and response bodies may still be visible. + */ + DEBUG; + + /** Returns whether this level is at or higher than the given [level]. */ + fun shouldLog(level: LogLevel): Boolean = ordinal >= level.ordinal + + companion object { + + /** Returns a [LogLevel] based on the `ARCADE_LOG` environment variable. */ + fun fromEnv() = + when (System.getenv("ARCADE_LOG")?.lowercase()) { + "info" -> INFO + "error" -> ERROR + "debug" -> DEBUG + else -> OFF + } + } +} diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/ObjectMappers.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/ObjectMappers.kt index 9fb2ee7..6a815ab 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/core/ObjectMappers.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/ObjectMappers.kt @@ -29,7 +29,9 @@ import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.temporal.ChronoField -fun jsonMapper(): JsonMapper = +fun jsonMapper(): JsonMapper = JSON_MAPPER + +private val JSON_MAPPER: JsonMapper = JsonMapper.builder() .addModule(kotlinModule()) .addModule(Jdk8Module()) diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/RequestOptions.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/RequestOptions.kt index 59a7d7f..f1f8154 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/core/RequestOptions.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/RequestOptions.kt @@ -33,6 +33,15 @@ class RequestOptions private constructor(val responseValidation: Boolean?, val t private var responseValidation: Boolean? = null private var timeout: Timeout? = null + /** + * Whether to call `validate` on the response before returning it. + * + * Setting this to `true` is _not_ forwards compatible with new types from the API for + * existing fields. + * + * Defaults to false, which means the shape of the response will not be validated upfront. + * Instead, validation will only occur for the parts of the response that are accessed. + */ fun responseValidation(responseValidation: Boolean) = apply { this.responseValidation = responseValidation } diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/Utils.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/Utils.kt index 8c7aa5f..647ca6b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/core/Utils.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/Utils.kt @@ -5,6 +5,7 @@ package dev.arcade.core import dev.arcade.errors.ArcadeInvalidDataException import java.util.Collections import java.util.SortedMap +import java.util.SortedSet import java.util.concurrent.CompletableFuture import java.util.concurrent.locks.Lock @@ -16,6 +17,11 @@ internal fun T?.getOrThrow(name: String): T = internal fun List.toImmutable(): List = if (isEmpty()) Collections.emptyList() else Collections.unmodifiableList(toList()) +@JvmSynthetic +internal fun > SortedSet.toImmutable(): SortedSet = + if (isEmpty()) Collections.emptySortedSet() + else Collections.unmodifiableSortedSet(toSortedSet(comparator() ?: Comparator.naturalOrder())) + @JvmSynthetic internal fun Map.toImmutable(): Map = if (isEmpty()) immutableEmptyMap() else Collections.unmodifiableMap(toMap()) diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/http/LoggingHttpClient.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/http/LoggingHttpClient.kt new file mode 100644 index 0000000..be13b36 --- /dev/null +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/http/LoggingHttpClient.kt @@ -0,0 +1,627 @@ +// File generated from our OpenAPI spec by Stainless. + +package dev.arcade.core.http + +import dev.arcade.core.LogLevel +import dev.arcade.core.RequestOptions +import dev.arcade.core.checkRequired +import dev.arcade.core.toImmutable +import java.io.ByteArrayOutputStream +import java.io.InputStream +import java.io.OutputStream +import java.nio.ByteBuffer +import java.nio.charset.CharacterCodingException +import java.nio.charset.Charset +import java.nio.charset.CharsetDecoder +import java.nio.charset.CodingErrorAction +import java.nio.charset.StandardCharsets +import java.time.Clock +import java.time.Duration +import java.time.OffsetDateTime +import java.util.SortedSet +import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletionException +import kotlin.time.toKotlinDuration + +/** A wrapper [HttpClient] around [httpClient] that logs request and response information. */ +class LoggingHttpClient +private constructor( + /** The underlying [HttpClient] for making requests. */ + @get:JvmName("httpClient") val httpClient: HttpClient, + /** + * Sensitive headers to redact from logs. + * + * Defaults to `Set.of("Authorization")`. + */ + @get:JvmName("redactedHeaders") val redactedHeaders: SortedSet, + /** + * The clock to use for measuring request and response durations. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ + @get:JvmName("clock") val clock: Clock, + /** + * The log level to use. + * + * Pass [LogLevel.fromEnv] to read from environment variables. + */ + @get:JvmName("level") val level: LogLevel, +) : HttpClient { + + override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { + val loggingRequest = logRequest(request) + + val before = OffsetDateTime.now(clock) + val response = + try { + httpClient.execute(loggingRequest, requestOptions) + } catch (e: Throwable) { + logFailure(e, Duration.between(before, OffsetDateTime.now(clock))) + throw e + } + + val took = Duration.between(before, OffsetDateTime.now(clock)) + return logResponse(response, took) + } + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture { + val loggingRequest = logRequest(request) + + val before = OffsetDateTime.now(clock) + val future = + try { + httpClient.executeAsync(loggingRequest, requestOptions) + } catch (e: Throwable) { + logFailure(e, Duration.between(before, OffsetDateTime.now(clock))) + throw e + } + return future.handle { response, error -> + val took = Duration.between(before, OffsetDateTime.now(clock)) + if (error != null) { + logFailure(unwrapCompletionException(error), took) + throw error + } + logResponse(response, took) + } + } + + private fun logRequest(request: HttpRequest): HttpRequest { + if (!level.shouldLog(LogLevel.INFO)) { + return request + } + + System.err.println( + buildString { + append("--> ${request.method} ${request.url()}") + request.body?.let { + val length = it.contentLength() + append(if (length >= 0) " ($length-byte body)" else " (unknown-length body)") + } + } + ) + + if (!level.shouldLog(LogLevel.DEBUG)) { + return request + } + + logHeaders(request.headers) + + if (request.body == null) { + System.err.println("--> END ${request.method}") + System.err.println() + return request + } + + return request + .toBuilder() + .body(LoggingHttpRequestBody(request.method, request.body)) + .build() + } + + private fun logResponse(response: HttpResponse, took: Duration): HttpResponse { + if (!level.shouldLog(LogLevel.INFO)) { + return response + } + + val contentLength = response.headers().values("Content-Length").firstOrNull()?.toIntOrNull() + System.err.println( + "<-- ${response.statusCode()} (${ + buildString { + append(took.format()) + contentLength?.let { append(", $contentLength-byte body") } + } + })" + ) + + if (!level.shouldLog(LogLevel.DEBUG)) { + return response + } + + logHeaders(response.headers()) + return LoggingHttpResponse(response) + } + + private fun logFailure(error: Throwable, took: Duration) { + if (!level.shouldLog(LogLevel.ERROR)) { + return + } + + System.err.println( + buildString { + append("<-- !! ${error.javaClass.simpleName}") + error.message?.let { append(": $it") } + append(" (${took.format()})") + } + ) + } + + private fun unwrapCompletionException(error: Throwable): Throwable = + if (error is CompletionException && error.cause != null) error.cause!! else error + + private fun logHeaders(headers: Headers) = + headers.names().forEach { name -> + headers.values(name).forEach { value -> + System.err.println("$name: ${if (redactedHeaders.contains(name)) "██" else value}") + } + } + + override fun close() = httpClient.close() + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [LoggingHttpClient]. + * + * The following fields are required: + * ```java + * .httpClient() + * .level() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [LoggingHttpClient]. */ + class Builder internal constructor() { + + private var httpClient: HttpClient? = null + private var redactedHeaders: Set = setOf("Authorization") + private var clock: Clock = Clock.systemUTC() + private var level: LogLevel? = null + + @JvmSynthetic + internal fun from(loggingHttpClient: LoggingHttpClient) = apply { + httpClient = loggingHttpClient.httpClient + redactedHeaders = loggingHttpClient.redactedHeaders + clock = loggingHttpClient.clock + level = loggingHttpClient.level + } + + /** The underlying [HttpClient] for making requests. */ + fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } + + /** + * Sensitive headers to redact from logs. + * + * Defaults to `Set.of("Authorization")`. + */ + fun redactedHeaders(redactedHeaders: Set) = apply { + this.redactedHeaders = redactedHeaders + } + + /** + * The clock to use for measuring request and response durations. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ + fun clock(clock: Clock) = apply { this.clock = clock } + + /** + * The log level to use. + * + * Pass [LogLevel.fromEnv] to read from environment variables. + */ + fun level(level: LogLevel) = apply { this.level = level } + + /** + * Returns an immutable instance of [LoggingHttpClient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .httpClient() + * .level() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): LoggingHttpClient = + LoggingHttpClient( + checkRequired("httpClient", httpClient), + redactedHeaders.toSortedSet(String.CASE_INSENSITIVE_ORDER).toImmutable(), + clock, + checkRequired("level", level), + ) + } +} + +/** + * An [HttpRequestBody] wrapper that delegates to [body] while also logging line by line as it's + * written. + * + * The logging occurs in a streaming manner with minimal buffering. + */ +private class LoggingHttpRequestBody( + private val method: HttpMethod, + private val body: HttpRequestBody, +) : HttpRequestBody { + + private val charset by lazy { parseCharset(body.contentType()) } + + override fun writeTo(outputStream: OutputStream) { + val loggingOutputStream = LoggingOutputStream(outputStream, charset) + body.writeTo(loggingOutputStream) + + loggingOutputStream.flush() + System.err.println("--> END $method (${loggingOutputStream.writeCount()}-byte body)") + System.err.println() + } + + override fun contentType(): String? = body.contentType() + + override fun contentLength(): Long = body.contentLength() + + override fun repeatable(): Boolean = body.repeatable() + + override fun close() = body.close() +} + +/** + * An [OutputStream] wrapper that delegates to [outputStream] while also logging bytes line by line + * as it's written to. + * + * The written content is assumed to be in the given [charset] and the logging occurs in a streaming + * manner with minimal buffering. + */ +private class LoggingOutputStream(private val outputStream: OutputStream, charset: Charset?) : + OutputStream() { + + private val buffer = LoggingBuffer(charset) + + fun writeCount() = buffer.writeCount() + + override fun write(b: Int) { + outputStream.write(b) + buffer.write(b) + } + + override fun write(b: ByteArray, off: Int, len: Int) { + outputStream.write(b, off, len) + for (i in off until off + len) { + buffer.write(b[i].toInt() and 0xFF) + } + } + + /** Prints any currently buffered content. */ + override fun flush() { + buffer.flush() + outputStream.flush() + } + + override fun close() = outputStream.close() +} + +/** + * An [HttpResponse] wrapper that delegates to [response] while also logging line-by-line as it's + * read. + * + * The logging occurs in a streaming manner with minimal buffering. + */ +private class LoggingHttpResponse(private val response: HttpResponse) : HttpResponse { + + private val loggingBody: Lazy = lazy { + LoggingInputStream( + response.body(), + parseCharset(response.headers().values("Content-Type").firstOrNull()), + ) + } + + override fun statusCode(): Int = response.statusCode() + + override fun headers(): Headers = response.headers() + + override fun body(): InputStream = loggingBody.value + + override fun close() { + if (loggingBody.isInitialized()) { + loggingBody.value.close() + } + response.close() + } +} + +/** + * An [InputStream] wrapper that delegates to [inputStream] while also logging bytes line by line as + * it's read. + * + * The contents of [inputStream] are assumed to be in the given [charset] and the logging occurs in + * a streaming manner with minimal buffering. + */ +private class LoggingInputStream(private val inputStream: InputStream, charset: Charset?) : + InputStream() { + + private var isDone = false + private val buffer = LoggingBuffer(charset) + + override fun read(): Int { + if (isDone) { + return -1 + } + + val b = inputStream.read() + + if (b == -1) { + markDone() + return b + } + + buffer.write(b) + return b + } + + override fun read(b: ByteArray, off: Int, len: Int): Int { + if (isDone) { + return -1 + } + + val bytesRead = inputStream.read(b, off, len) + + if (bytesRead == -1) { + markDone() + return bytesRead + } + + for (i in off until off + bytesRead) { + buffer.write(b[i].toInt() and 0xFF) + } + return bytesRead + } + + override fun close() { + if (!isDone) { + markDone(closedEarly = true) + } + inputStream.close() + } + + private fun markDone(closedEarly: Boolean = false) { + isDone = true + buffer.flush() + val suffix = if (closedEarly) ", closed early" else "" + System.err.println("<-- END HTTP (${buffer.writeCount()}-byte body$suffix)") + System.err.println() + } +} + +/** + * A byte buffer that prints line by line, using the given [charset], as bytes are written to it. + * + * When [charset] is `null`, the buffer performs an upfront check to detect binary content. If + * non-whitespace ISO control characters are found in the first [PROBABLY_UTF8_CODE_POINT_LIMIT] + * code points, body logging is suppressed entirely. + */ +private class LoggingBuffer(charset: Charset?) { + + private val charset = charset ?: StandardCharsets.UTF_8 + + private val decoder: CharsetDecoder = + this.charset + .newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT) + private var writeCount = 0 + private val buffer = ByteArrayOutputStream(128) + + /** + * Whether logging has been suppressed because the content doesn't appear to be readable text. + * + * This is only set when [charset] is `null` and the content fails the [isProbablyUtf8] check. + */ + private var suppressed = false + + /** + * Bytes accumulated for the [isProbablyUtf8] check before any lines are printed. + * + * Once the check passes (or [charset] is non-null), this is set to `null` and bytes flow + * directly to [buffer]. + */ + private var prefetchBuffer: ByteArrayOutputStream? = + if (charset != null) null else ByteArrayOutputStream(128) + + fun writeCount() = writeCount + + fun write(b: Int) { + if (writeCount == 0) { + // Print a newline before we start printing anything to separate the printed content + // from previous content. + System.err.println() + } + + writeCount++ + + if (suppressed) { + return + } + + val prefetch = prefetchBuffer + if (prefetch != null) { + prefetch.write(b) + // Continue accumulating until we have enough bytes to decide. + if (prefetch.size() < PROBABLY_UTF8_BYTE_LIMIT && b != '\n'.code) { + return + } + // We have enough bytes. Check if the content is probably UTF-8. + prefetchBuffer = null + val bytes = prefetch.toByteArray() + if (!isProbablyUtf8(bytes)) { + suppressed = true + System.err.println("(binary body omitted)") + return + } + // Content looks like UTF-8. Feed the accumulated bytes into the normal buffer. + for (byte in bytes) { + writeToBuffer(byte.toInt() and 0xFF) + } + return + } + + writeToBuffer(b) + } + + private fun writeToBuffer(b: Int) { + if (b == '\n'.code) { + flush() + return + } + + buffer.write(b) + } + + /** Prints any currently buffered content. */ + fun flush() { + if (suppressed) { + return + } + + // If we still have a prefetch buffer when flush is called (body was shorter than the + // limit), run the check now. + val prefetch = prefetchBuffer + if (prefetch != null) { + prefetchBuffer = null + val bytes = prefetch.toByteArray() + if (bytes.isEmpty()) { + return + } + if (!isProbablyUtf8(bytes)) { + suppressed = true + System.err.println("(binary body omitted)") + return + } + for (byte in bytes) { + writeToBuffer(byte.toInt() and 0xFF) + } + } + + if (buffer.size() == 0) { + return + } + + val line = + try { + decoder.decode(ByteBuffer.wrap(buffer.toByteArray())) + } catch (e: CharacterCodingException) { + "(omitted line is not valid $charset)" + } + buffer.reset() + System.err.println(line) + } +} + +/** The maximum number of code points to sample when checking if content is probably UTF-8. */ +private const val PROBABLY_UTF8_CODE_POINT_LIMIT = 64 + +/** + * The maximum number of bytes to accumulate before running the [isProbablyUtf8] check. UTF-8 code + * points are at most 4 bytes, so this accommodates [PROBABLY_UTF8_CODE_POINT_LIMIT] code points. + */ +private const val PROBABLY_UTF8_BYTE_LIMIT = PROBABLY_UTF8_CODE_POINT_LIMIT * 4 + +/** + * Returns `true` if the given [bytes] probably contain human-readable UTF-8 text. + * + * Decodes up to [PROBABLY_UTF8_CODE_POINT_LIMIT] code points and returns `false` if any + * non-whitespace ISO control characters are found, or if the bytes are not valid UTF-8. + */ +private fun isProbablyUtf8(bytes: ByteArray): Boolean { + try { + val decoder = + StandardCharsets.UTF_8.newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT) + val charBuffer = decoder.decode(ByteBuffer.wrap(bytes)) + var codePointCount = 0 + var i = 0 + while (i < charBuffer.length && codePointCount < PROBABLY_UTF8_CODE_POINT_LIMIT) { + val codePoint = Character.codePointAt(charBuffer, i) + if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { + return false + } + i += Character.charCount(codePoint) + codePointCount++ + } + return true + } catch (e: CharacterCodingException) { + return false + } +} + +/** Returns the [Charset] in the given [contentType] string, or `null` if unspecified. */ +private fun parseCharset(contentType: String?): Charset? = + contentType + ?.split(";") + ?.drop(1) + ?.map { it.trim() } + ?.firstOrNull { it.startsWith("charset=", ignoreCase = true) } + ?.substringAfter("=") + ?.trim() + ?.removeSurrounding("\"") + ?.let { runCatching { charset(it) }.getOrNull() } + +/** Formats the [Duration] into a string like "1m 40s 467ms". */ +private fun Duration.format(): String = + toKotlinDuration().toComponents { days, hours, minutes, seconds, nanoseconds -> + buildString { + val milliseconds = nanoseconds / 1_000_000 + if (days > 0) { + append("${days}d") + } + if (hours > 0) { + if (isNotEmpty()) { + append(" ") + } + append("${hours}h") + } + if (minutes > 0) { + if (isNotEmpty()) { + append(" ") + } + append("${minutes}m") + } + if (seconds > 0) { + if (isNotEmpty()) { + append(" ") + } + append("${seconds}s") + } + if (milliseconds > 0) { + if (isNotEmpty()) { + append(" ") + } + append("${milliseconds}ms") + } + + if (isEmpty()) { + append("0s") + } + } + } diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/core/http/ProxyAuthenticator.kt b/arcade-java-core/src/main/kotlin/dev/arcade/core/http/ProxyAuthenticator.kt new file mode 100644 index 0000000..3339ed2 --- /dev/null +++ b/arcade-java-core/src/main/kotlin/dev/arcade/core/http/ProxyAuthenticator.kt @@ -0,0 +1,59 @@ +package dev.arcade.core.http + +import java.net.Proxy +import java.nio.charset.Charset +import java.nio.charset.StandardCharsets +import java.util.Base64 +import java.util.Optional + +/** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication Required`. + * + * Implementations inspect the 407 [response] (typically its `Proxy-Authenticate` header) and return + * the request to retry with a `Proxy-Authorization` header set, or [Optional.empty] to abandon + * authentication and surface the 407 to the caller. + * + * Implementations must be thread-safe; they may be invoked concurrently from multiple HTTP calls. + */ +fun interface ProxyAuthenticator { + + /** + * @param proxy the proxy that produced the challenge, or [Proxy.NO_PROXY] if the route is not + * yet established + * @param request the request that produced [response] + * @param response the 407 challenge response + * @return the retry request to send (typically [request] with a `Proxy-Authorization` header + * added), or [Optional.empty] to abandon authentication + */ + fun authenticate( + proxy: Proxy, + request: HttpRequest, + response: HttpResponse, + ): Optional + + companion object { + + /** + * A [ProxyAuthenticator] that uses RFC 7617 Basic authentication with the ISO-8859-1 + * charset. + */ + @JvmStatic + fun basic(username: String, password: String): ProxyAuthenticator = + basic(username, password, StandardCharsets.ISO_8859_1) + + /** + * A [ProxyAuthenticator] that uses RFC 7617 Basic authentication with the given [charset]. + */ + @JvmStatic + fun basic(username: String, password: String, charset: Charset): ProxyAuthenticator { + val token = + Base64.getEncoder().encodeToString("$username:$password".toByteArray(charset)) + val headerValue = "Basic $token" + return ProxyAuthenticator { _, request, _ -> + Optional.of( + request.toBuilder().putHeader("Proxy-Authorization", headerValue).build() + ) + } + } + } +} diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/BadRequestException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/BadRequestException.kt index b5cd72d..9c90f64 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/BadRequestException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/BadRequestException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class BadRequestException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("400: $body", cause) { + ArcadeServiceException( + "400: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 400 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/InternalServerException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/InternalServerException.kt index faa5ede..b3e6868 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/InternalServerException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/InternalServerException.kt @@ -5,6 +5,7 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -14,7 +15,11 @@ private constructor( private val headers: Headers, private val body: JsonValue, cause: Throwable?, -) : ArcadeServiceException("$statusCode: $body", cause) { +) : + ArcadeServiceException( + "$statusCode: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = statusCode diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/NotFoundException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/NotFoundException.kt index b156be1..9971517 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/NotFoundException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/NotFoundException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class NotFoundException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("404: $body", cause) { + ArcadeServiceException( + "404: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 404 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/PermissionDeniedException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/PermissionDeniedException.kt index 5c77c7a..9cbb855 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/PermissionDeniedException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/PermissionDeniedException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class PermissionDeniedException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("403: $body", cause) { + ArcadeServiceException( + "403: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 403 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/RateLimitException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/RateLimitException.kt index 290070c..f96f7ef 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/RateLimitException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/RateLimitException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class RateLimitException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("429: $body", cause) { + ArcadeServiceException( + "429: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 429 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnauthorizedException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnauthorizedException.kt index 258076a..094b13f 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnauthorizedException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnauthorizedException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class UnauthorizedException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("401: $body", cause) { + ArcadeServiceException( + "401: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 401 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnexpectedStatusCodeException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnexpectedStatusCodeException.kt index a7a0400..3813475 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnexpectedStatusCodeException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnexpectedStatusCodeException.kt @@ -5,6 +5,7 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -14,7 +15,11 @@ private constructor( private val headers: Headers, private val body: JsonValue, cause: Throwable?, -) : ArcadeServiceException("$statusCode: $body", cause) { +) : + ArcadeServiceException( + "$statusCode: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = statusCode diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnprocessableEntityException.kt b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnprocessableEntityException.kt index b94b126..115d3b4 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnprocessableEntityException.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/errors/UnprocessableEntityException.kt @@ -5,12 +5,16 @@ package dev.arcade.errors import dev.arcade.core.JsonValue import dev.arcade.core.checkRequired import dev.arcade.core.http.Headers +import dev.arcade.core.jsonMapper import java.util.Optional import kotlin.jvm.optionals.getOrNull class UnprocessableEntityException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : - ArcadeServiceException("422: $body", cause) { + ArcadeServiceException( + "422: ${if (body.isMissing()) "Unknown" else jsonMapper().writeValueAsString(body)}", + cause, + ) { override fun statusCode(): Int = 422 diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationContext.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationContext.kt index 6adbac1..0336aaf 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationContext.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationContext.kt @@ -140,6 +140,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizationContext = apply { if (validated) { return@apply @@ -226,6 +234,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserInfo = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationResponse.kt index 0eddad8..4aa970f 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/AuthorizationResponse.kt @@ -308,6 +308,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizationResponse = apply { if (validated) { return@apply @@ -445,6 +453,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Status = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/Error.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/Error.kt index 40800cb..2c37ff7 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/Error.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/Error.kt @@ -136,6 +136,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Error = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderCreateRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderCreateRequest.kt index dbff3f9..abe0c9a 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderCreateRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderCreateRequest.kt @@ -311,6 +311,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthProviderCreateRequest = apply { if (validated) { return@apply @@ -768,6 +776,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -1190,6 +1207,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizeRequest = apply { if (validated) { return@apply @@ -1292,6 +1319,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -1433,6 +1470,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -1569,6 +1616,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -1668,6 +1725,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -1887,6 +1954,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Pkce = apply { if (validated) { return@apply @@ -2316,6 +2393,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): RefreshRequest = apply { if (validated) { return@apply @@ -2418,6 +2505,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -2559,6 +2656,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -2695,6 +2802,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -2794,6 +2911,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -2969,6 +3096,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ScopeDelimiter = apply { if (validated) { return@apply @@ -3426,6 +3563,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): TokenIntrospectionRequest = apply { if (validated) { return@apply @@ -3613,6 +3760,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Triggers = apply { if (validated) { return@apply @@ -3724,6 +3881,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -3865,6 +4032,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -4001,6 +4178,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -4100,6 +4287,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -4562,6 +4759,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): TokenRequest = apply { if (validated) { return@apply @@ -4664,6 +4871,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -4805,6 +5022,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -4941,6 +5168,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -5040,6 +5277,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -5538,6 +5785,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserInfoRequest = apply { if (validated) { return@apply @@ -5725,6 +5982,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Triggers = apply { if (validated) { return@apply @@ -5836,6 +6103,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -5977,6 +6254,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -6113,6 +6400,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -6212,6 +6509,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderListResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderListResponse.kt index d6bc9c0..4c94a07 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderListResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderListResponse.kt @@ -245,6 +245,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthProviderListResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderResponse.kt index c00cfb8..5117fd4 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderResponse.kt @@ -359,6 +359,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthProviderResponse = apply { if (validated) { return@apply @@ -524,6 +532,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -653,6 +670,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply @@ -1153,6 +1180,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -1600,6 +1636,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizeRequest = apply { if (validated) { return@apply @@ -1704,6 +1750,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -1808,6 +1864,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -2087,6 +2153,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ClientSecret = apply { if (validated) { return@apply @@ -2225,6 +2301,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -2424,6 +2510,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Pkce = apply { if (validated) { return@apply @@ -2876,6 +2972,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): RefreshRequest = apply { if (validated) { return@apply @@ -2980,6 +3086,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -3084,6 +3200,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -3640,6 +3766,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): TokenIntrospectionRequest = apply { if (validated) { return@apply @@ -3748,6 +3884,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -3852,6 +3998,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -4040,6 +4196,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Triggers = apply { if (validated) { return@apply @@ -4535,6 +4701,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): TokenRequest = apply { if (validated) { return@apply @@ -4639,6 +4815,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -4743,6 +4929,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -5263,6 +5459,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserInfoRequest = apply { if (validated) { return@apply @@ -5369,6 +5575,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -5473,6 +5689,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -5661,6 +5887,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Triggers = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequest.kt index 159520d..9057d6c 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequest.kt @@ -264,6 +264,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthProviderUpdateRequest = apply { if (validated) { return@apply @@ -309,6 +317,7 @@ private constructor( private val pkce: JsonField, private val refreshRequest: JsonField, private val scopeDelimiter: JsonField, + private val tokenIntrospectionRequest: JsonField, private val tokenRequest: JsonField, private val userInfoRequest: JsonField, private val additionalProperties: MutableMap, @@ -332,6 +341,9 @@ private constructor( @JsonProperty("scope_delimiter") @ExcludeMissing scopeDelimiter: JsonField = JsonMissing.of(), + @JsonProperty("token_introspection_request") + @ExcludeMissing + tokenIntrospectionRequest: JsonField = JsonMissing.of(), @JsonProperty("token_request") @ExcludeMissing tokenRequest: JsonField = JsonMissing.of(), @@ -345,6 +357,7 @@ private constructor( pkce, refreshRequest, scopeDelimiter, + tokenIntrospectionRequest, tokenRequest, userInfoRequest, mutableMapOf(), @@ -389,6 +402,13 @@ private constructor( fun scopeDelimiter(): Optional = scopeDelimiter.getOptional("scope_delimiter") + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tokenIntrospectionRequest(): Optional = + tokenIntrospectionRequest.getOptional("token_introspection_request") + /** * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -456,6 +476,17 @@ private constructor( @ExcludeMissing fun _scopeDelimiter(): JsonField = scopeDelimiter + /** + * Returns the raw JSON value of [tokenIntrospectionRequest]. + * + * Unlike [tokenIntrospectionRequest], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("token_introspection_request") + @ExcludeMissing + fun _tokenIntrospectionRequest(): JsonField = + tokenIntrospectionRequest + /** * Returns the raw JSON value of [tokenRequest]. * @@ -503,6 +534,8 @@ private constructor( private var pkce: JsonField = JsonMissing.of() private var refreshRequest: JsonField = JsonMissing.of() private var scopeDelimiter: JsonField = JsonMissing.of() + private var tokenIntrospectionRequest: JsonField = + JsonMissing.of() private var tokenRequest: JsonField = JsonMissing.of() private var userInfoRequest: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -515,6 +548,7 @@ private constructor( pkce = oauth2.pkce refreshRequest = oauth2.refreshRequest scopeDelimiter = oauth2.scopeDelimiter + tokenIntrospectionRequest = oauth2.tokenIntrospectionRequest tokenRequest = oauth2.tokenRequest userInfoRequest = oauth2.userInfoRequest additionalProperties = oauth2.additionalProperties.toMutableMap() @@ -597,6 +631,20 @@ private constructor( this.scopeDelimiter = scopeDelimiter } + fun tokenIntrospectionRequest(tokenIntrospectionRequest: TokenIntrospectionRequest) = + tokenIntrospectionRequest(JsonField.of(tokenIntrospectionRequest)) + + /** + * Sets [Builder.tokenIntrospectionRequest] to an arbitrary JSON value. + * + * You should usually call [Builder.tokenIntrospectionRequest] with a well-typed + * [TokenIntrospectionRequest] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tokenIntrospectionRequest( + tokenIntrospectionRequest: JsonField + ) = apply { this.tokenIntrospectionRequest = tokenIntrospectionRequest } + fun tokenRequest(tokenRequest: TokenRequest) = tokenRequest(JsonField.of(tokenRequest)) /** @@ -656,6 +704,7 @@ private constructor( pkce, refreshRequest, scopeDelimiter, + tokenIntrospectionRequest, tokenRequest, userInfoRequest, additionalProperties.toMutableMap(), @@ -664,6 +713,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -675,6 +733,7 @@ private constructor( pkce().ifPresent { it.validate() } refreshRequest().ifPresent { it.validate() } scopeDelimiter().ifPresent { it.validate() } + tokenIntrospectionRequest().ifPresent { it.validate() } tokenRequest().ifPresent { it.validate() } userInfoRequest().ifPresent { it.validate() } validated = true @@ -702,6 +761,7 @@ private constructor( (pkce.asKnown().getOrNull()?.validity() ?: 0) + (refreshRequest.asKnown().getOrNull()?.validity() ?: 0) + (scopeDelimiter.asKnown().getOrNull()?.validity() ?: 0) + + (tokenIntrospectionRequest.asKnown().getOrNull()?.validity() ?: 0) + (tokenRequest.asKnown().getOrNull()?.validity() ?: 0) + (userInfoRequest.asKnown().getOrNull()?.validity() ?: 0) @@ -1069,6 +1129,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizeRequest = apply { if (validated) { return@apply @@ -1171,6 +1241,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -1312,6 +1392,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -1448,6 +1538,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -1547,6 +1647,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -1766,6 +1876,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Pkce = apply { if (validated) { return@apply @@ -2180,6 +2300,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): RefreshRequest = apply { if (validated) { return@apply @@ -2282,6 +2412,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -2423,6 +2563,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -2559,6 +2709,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -2658,6 +2818,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -2833,6 +3003,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ScopeDelimiter = apply { if (validated) { return@apply @@ -2871,7 +3051,7 @@ private constructor( override fun toString() = value.toString() } - class TokenRequest + class TokenIntrospectionRequest @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val authHeaderValueFormat: JsonField, @@ -2882,6 +3062,7 @@ private constructor( private val requestContentType: JsonField, private val responseContentType: JsonField, private val responseMap: JsonField, + private val triggers: JsonField, private val additionalProperties: MutableMap, ) { @@ -2911,6 +3092,9 @@ private constructor( @JsonProperty("response_map") @ExcludeMissing responseMap: JsonField = JsonMissing.of(), + @JsonProperty("triggers") + @ExcludeMissing + triggers: JsonField = JsonMissing.of(), ) : this( authHeaderValueFormat, authMethod, @@ -2920,6 +3104,7 @@ private constructor( requestContentType, responseContentType, responseMap, + triggers, mutableMapOf(), ) @@ -2974,6 +3159,12 @@ private constructor( */ fun responseMap(): Optional = responseMap.getOptional("response_map") + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun triggers(): Optional = triggers.getOptional("triggers") + /** * Returns the raw JSON value of [authHeaderValueFormat]. * @@ -3046,6 +3237,16 @@ private constructor( @ExcludeMissing fun _responseMap(): JsonField = responseMap + /** + * Returns the raw JSON value of [triggers]. + * + * Unlike [triggers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("triggers") + @ExcludeMissing + fun _triggers(): JsonField = triggers + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3060,11 +3261,14 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [TokenRequest]. */ + /** + * Returns a mutable builder for constructing an instance of + * [TokenIntrospectionRequest]. + */ @JvmStatic fun builder() = Builder() } - /** A builder for [TokenRequest]. */ + /** A builder for [TokenIntrospectionRequest]. */ class Builder internal constructor() { private var authHeaderValueFormat: JsonField = JsonMissing.of() @@ -3075,19 +3279,22 @@ private constructor( private var requestContentType: JsonField = JsonMissing.of() private var responseContentType: JsonField = JsonMissing.of() private var responseMap: JsonField = JsonMissing.of() + private var triggers: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(tokenRequest: TokenRequest) = apply { - authHeaderValueFormat = tokenRequest.authHeaderValueFormat - authMethod = tokenRequest.authMethod - endpoint = tokenRequest.endpoint - method = tokenRequest.method - params = tokenRequest.params - requestContentType = tokenRequest.requestContentType - responseContentType = tokenRequest.responseContentType - responseMap = tokenRequest.responseMap - additionalProperties = tokenRequest.additionalProperties.toMutableMap() + internal fun from(tokenIntrospectionRequest: TokenIntrospectionRequest) = apply { + authHeaderValueFormat = tokenIntrospectionRequest.authHeaderValueFormat + authMethod = tokenIntrospectionRequest.authMethod + endpoint = tokenIntrospectionRequest.endpoint + method = tokenIntrospectionRequest.method + params = tokenIntrospectionRequest.params + requestContentType = tokenIntrospectionRequest.requestContentType + responseContentType = tokenIntrospectionRequest.responseContentType + responseMap = tokenIntrospectionRequest.responseMap + triggers = tokenIntrospectionRequest.triggers + additionalProperties = + tokenIntrospectionRequest.additionalProperties.toMutableMap() } fun authHeaderValueFormat(authHeaderValueFormat: String) = @@ -3192,6 +3399,17 @@ private constructor( this.responseMap = responseMap } + fun triggers(triggers: Triggers) = triggers(JsonField.of(triggers)) + + /** + * Sets [Builder.triggers] to an arbitrary JSON value. + * + * You should usually call [Builder.triggers] with a well-typed [Triggers] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun triggers(triggers: JsonField) = apply { this.triggers = triggers } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3215,12 +3433,12 @@ private constructor( } /** - * Returns an immutable instance of [TokenRequest]. + * Returns an immutable instance of [TokenIntrospectionRequest]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): TokenRequest = - TokenRequest( + fun build(): TokenIntrospectionRequest = + TokenIntrospectionRequest( authHeaderValueFormat, authMethod, endpoint, @@ -3229,13 +3447,24 @@ private constructor( requestContentType, responseContentType, responseMap, + triggers, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): TokenRequest = apply { + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): TokenIntrospectionRequest = apply { if (validated) { return@apply } @@ -3248,6 +3477,7 @@ private constructor( requestContentType().ifPresent { it.validate() } responseContentType().ifPresent { it.validate() } responseMap().ifPresent { it.validate() } + triggers().ifPresent { it.validate() } validated = true } @@ -3274,7 +3504,8 @@ private constructor( (params.asKnown().getOrNull()?.validity() ?: 0) + (requestContentType.asKnown().getOrNull()?.validity() ?: 0) + (responseContentType.asKnown().getOrNull()?.validity() ?: 0) + - (responseMap.asKnown().getOrNull()?.validity() ?: 0) + (responseMap.asKnown().getOrNull()?.validity() ?: 0) + + (triggers.asKnown().getOrNull()?.validity() ?: 0) class Params @JsonCreator @@ -3337,6 +3568,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -3478,6 +3719,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -3614,6 +3865,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -3713,6 +3974,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -3757,66 +4028,1245 @@ private constructor( override fun toString() = "ResponseMap{additionalProperties=$additionalProperties}" } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is TokenRequest && - authHeaderValueFormat == other.authHeaderValueFormat && - authMethod == other.authMethod && - endpoint == other.endpoint && - method == other.method && - params == other.params && - requestContentType == other.requestContentType && - responseContentType == other.responseContentType && - responseMap == other.responseMap && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - authHeaderValueFormat, - authMethod, - endpoint, - method, - params, - requestContentType, - responseContentType, - responseMap, - additionalProperties, - ) - } + class Triggers + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val onTokenGrant: JsonField, + private val onTokenRefresh: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun hashCode(): Int = hashCode + @JsonCreator + private constructor( + @JsonProperty("on_token_grant") + @ExcludeMissing + onTokenGrant: JsonField = JsonMissing.of(), + @JsonProperty("on_token_refresh") + @ExcludeMissing + onTokenRefresh: JsonField = JsonMissing.of(), + ) : this(onTokenGrant, onTokenRefresh, mutableMapOf()) - override fun toString() = - "TokenRequest{authHeaderValueFormat=$authHeaderValueFormat, authMethod=$authMethod, endpoint=$endpoint, method=$method, params=$params, requestContentType=$requestContentType, responseContentType=$responseContentType, responseMap=$responseMap, additionalProperties=$additionalProperties}" - } + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun onTokenGrant(): Optional = onTokenGrant.getOptional("on_token_grant") - class UserInfoRequest - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val authHeaderValueFormat: JsonField, - private val authMethod: JsonField, - private val endpoint: JsonField, - private val method: JsonField, - private val params: JsonField, - private val requestContentType: JsonField, - private val responseContentType: JsonField, - private val responseMap: JsonField, - private val triggers: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun onTokenRefresh(): Optional = + onTokenRefresh.getOptional("on_token_refresh") - @JsonCreator - private constructor( - @JsonProperty("auth_header_value_format") - @ExcludeMissing - authHeaderValueFormat: JsonField = JsonMissing.of(), - @JsonProperty("auth_method") + /** + * Returns the raw JSON value of [onTokenGrant]. + * + * Unlike [onTokenGrant], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("on_token_grant") @ExcludeMissing - authMethod: JsonField = JsonMissing.of(), + fun _onTokenGrant(): JsonField = onTokenGrant + + /** + * Returns the raw JSON value of [onTokenRefresh]. + * + * Unlike [onTokenRefresh], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("on_token_refresh") + @ExcludeMissing + fun _onTokenRefresh(): JsonField = onTokenRefresh + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Triggers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Triggers]. */ + class Builder internal constructor() { + + private var onTokenGrant: JsonField = JsonMissing.of() + private var onTokenRefresh: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(triggers: Triggers) = apply { + onTokenGrant = triggers.onTokenGrant + onTokenRefresh = triggers.onTokenRefresh + additionalProperties = triggers.additionalProperties.toMutableMap() + } + + fun onTokenGrant(onTokenGrant: Boolean) = + onTokenGrant(JsonField.of(onTokenGrant)) + + /** + * Sets [Builder.onTokenGrant] to an arbitrary JSON value. + * + * You should usually call [Builder.onTokenGrant] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun onTokenGrant(onTokenGrant: JsonField) = apply { + this.onTokenGrant = onTokenGrant + } + + fun onTokenRefresh(onTokenRefresh: Boolean) = + onTokenRefresh(JsonField.of(onTokenRefresh)) + + /** + * Sets [Builder.onTokenRefresh] to an arbitrary JSON value. + * + * You should usually call [Builder.onTokenRefresh] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun onTokenRefresh(onTokenRefresh: JsonField) = apply { + this.onTokenRefresh = onTokenRefresh + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Triggers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Triggers = + Triggers(onTokenGrant, onTokenRefresh, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Triggers = apply { + if (validated) { + return@apply + } + + onTokenGrant() + onTokenRefresh() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (onTokenGrant.asKnown().isPresent) 1 else 0) + + (if (onTokenRefresh.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Triggers && + onTokenGrant == other.onTokenGrant && + onTokenRefresh == other.onTokenRefresh && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(onTokenGrant, onTokenRefresh, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Triggers{onTokenGrant=$onTokenGrant, onTokenRefresh=$onTokenRefresh, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TokenIntrospectionRequest && + authHeaderValueFormat == other.authHeaderValueFormat && + authMethod == other.authMethod && + endpoint == other.endpoint && + method == other.method && + params == other.params && + requestContentType == other.requestContentType && + responseContentType == other.responseContentType && + responseMap == other.responseMap && + triggers == other.triggers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + authHeaderValueFormat, + authMethod, + endpoint, + method, + params, + requestContentType, + responseContentType, + responseMap, + triggers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TokenIntrospectionRequest{authHeaderValueFormat=$authHeaderValueFormat, authMethod=$authMethod, endpoint=$endpoint, method=$method, params=$params, requestContentType=$requestContentType, responseContentType=$responseContentType, responseMap=$responseMap, triggers=$triggers, additionalProperties=$additionalProperties}" + } + + class TokenRequest + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val authHeaderValueFormat: JsonField, + private val authMethod: JsonField, + private val endpoint: JsonField, + private val method: JsonField, + private val params: JsonField, + private val requestContentType: JsonField, + private val responseContentType: JsonField, + private val responseMap: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth_header_value_format") + @ExcludeMissing + authHeaderValueFormat: JsonField = JsonMissing.of(), + @JsonProperty("auth_method") + @ExcludeMissing + authMethod: JsonField = JsonMissing.of(), + @JsonProperty("endpoint") + @ExcludeMissing + endpoint: JsonField = JsonMissing.of(), + @JsonProperty("method") + @ExcludeMissing + method: JsonField = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("request_content_type") + @ExcludeMissing + requestContentType: JsonField = JsonMissing.of(), + @JsonProperty("response_content_type") + @ExcludeMissing + responseContentType: JsonField = JsonMissing.of(), + @JsonProperty("response_map") + @ExcludeMissing + responseMap: JsonField = JsonMissing.of(), + ) : this( + authHeaderValueFormat, + authMethod, + endpoint, + method, + params, + requestContentType, + responseContentType, + responseMap, + mutableMapOf(), + ) + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun authHeaderValueFormat(): Optional = + authHeaderValueFormat.getOptional("auth_header_value_format") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun authMethod(): Optional = authMethod.getOptional("auth_method") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun endpoint(): Optional = endpoint.getOptional("endpoint") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun method(): Optional = method.getOptional("method") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun params(): Optional = params.getOptional("params") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun requestContentType(): Optional = + requestContentType.getOptional("request_content_type") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun responseContentType(): Optional = + responseContentType.getOptional("response_content_type") + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun responseMap(): Optional = responseMap.getOptional("response_map") + + /** + * Returns the raw JSON value of [authHeaderValueFormat]. + * + * Unlike [authHeaderValueFormat], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("auth_header_value_format") + @ExcludeMissing + fun _authHeaderValueFormat(): JsonField = authHeaderValueFormat + + /** + * Returns the raw JSON value of [authMethod]. + * + * Unlike [authMethod], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth_method") + @ExcludeMissing + fun _authMethod(): JsonField = authMethod + + /** + * Returns the raw JSON value of [endpoint]. + * + * Unlike [endpoint], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("endpoint") @ExcludeMissing fun _endpoint(): JsonField = endpoint + + /** + * Returns the raw JSON value of [method]. + * + * Unlike [method], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("method") @ExcludeMissing fun _method(): JsonField = method + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("params") @ExcludeMissing fun _params(): JsonField = params + + /** + * Returns the raw JSON value of [requestContentType]. + * + * Unlike [requestContentType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("request_content_type") + @ExcludeMissing + fun _requestContentType(): JsonField = requestContentType + + /** + * Returns the raw JSON value of [responseContentType]. + * + * Unlike [responseContentType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("response_content_type") + @ExcludeMissing + fun _responseContentType(): JsonField = responseContentType + + /** + * Returns the raw JSON value of [responseMap]. + * + * Unlike [responseMap], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("response_map") + @ExcludeMissing + fun _responseMap(): JsonField = responseMap + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [TokenRequest]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TokenRequest]. */ + class Builder internal constructor() { + + private var authHeaderValueFormat: JsonField = JsonMissing.of() + private var authMethod: JsonField = JsonMissing.of() + private var endpoint: JsonField = JsonMissing.of() + private var method: JsonField = JsonMissing.of() + private var params: JsonField = JsonMissing.of() + private var requestContentType: JsonField = JsonMissing.of() + private var responseContentType: JsonField = JsonMissing.of() + private var responseMap: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tokenRequest: TokenRequest) = apply { + authHeaderValueFormat = tokenRequest.authHeaderValueFormat + authMethod = tokenRequest.authMethod + endpoint = tokenRequest.endpoint + method = tokenRequest.method + params = tokenRequest.params + requestContentType = tokenRequest.requestContentType + responseContentType = tokenRequest.responseContentType + responseMap = tokenRequest.responseMap + additionalProperties = tokenRequest.additionalProperties.toMutableMap() + } + + fun authHeaderValueFormat(authHeaderValueFormat: String) = + authHeaderValueFormat(JsonField.of(authHeaderValueFormat)) + + /** + * Sets [Builder.authHeaderValueFormat] to an arbitrary JSON value. + * + * You should usually call [Builder.authHeaderValueFormat] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun authHeaderValueFormat(authHeaderValueFormat: JsonField) = apply { + this.authHeaderValueFormat = authHeaderValueFormat + } + + fun authMethod(authMethod: String) = authMethod(JsonField.of(authMethod)) + + /** + * Sets [Builder.authMethod] to an arbitrary JSON value. + * + * You should usually call [Builder.authMethod] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun authMethod(authMethod: JsonField) = apply { + this.authMethod = authMethod + } + + fun endpoint(endpoint: String) = endpoint(JsonField.of(endpoint)) + + /** + * Sets [Builder.endpoint] to an arbitrary JSON value. + * + * You should usually call [Builder.endpoint] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun endpoint(endpoint: JsonField) = apply { this.endpoint = endpoint } + + fun method(method: String) = method(JsonField.of(method)) + + /** + * Sets [Builder.method] to an arbitrary JSON value. + * + * You should usually call [Builder.method] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun method(method: JsonField) = apply { this.method = method } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed [Params] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun params(params: JsonField) = apply { this.params = params } + + fun requestContentType(requestContentType: RequestContentType) = + requestContentType(JsonField.of(requestContentType)) + + /** + * Sets [Builder.requestContentType] to an arbitrary JSON value. + * + * You should usually call [Builder.requestContentType] with a well-typed + * [RequestContentType] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun requestContentType(requestContentType: JsonField) = apply { + this.requestContentType = requestContentType + } + + fun responseContentType(responseContentType: ResponseContentType) = + responseContentType(JsonField.of(responseContentType)) + + /** + * Sets [Builder.responseContentType] to an arbitrary JSON value. + * + * You should usually call [Builder.responseContentType] with a well-typed + * [ResponseContentType] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun responseContentType(responseContentType: JsonField) = + apply { + this.responseContentType = responseContentType + } + + fun responseMap(responseMap: ResponseMap) = responseMap(JsonField.of(responseMap)) + + /** + * Sets [Builder.responseMap] to an arbitrary JSON value. + * + * You should usually call [Builder.responseMap] with a well-typed [ResponseMap] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun responseMap(responseMap: JsonField) = apply { + this.responseMap = responseMap + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TokenRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TokenRequest = + TokenRequest( + authHeaderValueFormat, + authMethod, + endpoint, + method, + params, + requestContentType, + responseContentType, + responseMap, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): TokenRequest = apply { + if (validated) { + return@apply + } + + authHeaderValueFormat() + authMethod() + endpoint() + method() + params().ifPresent { it.validate() } + requestContentType().ifPresent { it.validate() } + responseContentType().ifPresent { it.validate() } + responseMap().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (authHeaderValueFormat.asKnown().isPresent) 1 else 0) + + (if (authMethod.asKnown().isPresent) 1 else 0) + + (if (endpoint.asKnown().isPresent) 1 else 0) + + (if (method.asKnown().isPresent) 1 else 0) + + (params.asKnown().getOrNull()?.validity() ?: 0) + + (requestContentType.asKnown().getOrNull()?.validity() ?: 0) + + (responseContentType.asKnown().getOrNull()?.validity() ?: 0) + + (responseMap.asKnown().getOrNull()?.validity() ?: 0) + + class Params + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Params]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + additionalProperties = params.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Params]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Params = Params(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Params{additionalProperties=$additionalProperties}" + } + + class RequestContentType + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField + val APPLICATION_X_WWW_FORM_URLENCODED = of("application/x-www-form-urlencoded") + + @JvmField val APPLICATION_JSON = of("application/json") + + @JvmStatic fun of(value: String) = RequestContentType(JsonField.of(value)) + } + + /** An enum containing [RequestContentType]'s known values. */ + enum class Known { + APPLICATION_X_WWW_FORM_URLENCODED, + APPLICATION_JSON, + } + + /** + * An enum containing [RequestContentType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RequestContentType] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + APPLICATION_X_WWW_FORM_URLENCODED, + APPLICATION_JSON, + /** + * An enum member indicating that [RequestContentType] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + APPLICATION_X_WWW_FORM_URLENCODED -> Value.APPLICATION_X_WWW_FORM_URLENCODED + APPLICATION_JSON -> Value.APPLICATION_JSON + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws ArcadeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + APPLICATION_X_WWW_FORM_URLENCODED -> Known.APPLICATION_X_WWW_FORM_URLENCODED + APPLICATION_JSON -> Known.APPLICATION_JSON + else -> + throw ArcadeInvalidDataException("Unknown RequestContentType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws ArcadeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + ArcadeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): RequestContentType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RequestContentType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ResponseContentType + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField + val APPLICATION_X_WWW_FORM_URLENCODED = of("application/x-www-form-urlencoded") + + @JvmField val APPLICATION_JSON = of("application/json") + + @JvmStatic fun of(value: String) = ResponseContentType(JsonField.of(value)) + } + + /** An enum containing [ResponseContentType]'s known values. */ + enum class Known { + APPLICATION_X_WWW_FORM_URLENCODED, + APPLICATION_JSON, + } + + /** + * An enum containing [ResponseContentType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ResponseContentType] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + APPLICATION_X_WWW_FORM_URLENCODED, + APPLICATION_JSON, + /** + * An enum member indicating that [ResponseContentType] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + APPLICATION_X_WWW_FORM_URLENCODED -> Value.APPLICATION_X_WWW_FORM_URLENCODED + APPLICATION_JSON -> Value.APPLICATION_JSON + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws ArcadeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + APPLICATION_X_WWW_FORM_URLENCODED -> Known.APPLICATION_X_WWW_FORM_URLENCODED + APPLICATION_JSON -> Known.APPLICATION_JSON + else -> + throw ArcadeInvalidDataException("Unknown ResponseContentType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws ArcadeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + ArcadeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResponseContentType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseContentType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ResponseMap + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [ResponseMap]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ResponseMap]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(responseMap: ResponseMap) = apply { + additionalProperties = responseMap.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ResponseMap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ResponseMap = ResponseMap(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResponseMap = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: ArcadeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseMap && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "ResponseMap{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TokenRequest && + authHeaderValueFormat == other.authHeaderValueFormat && + authMethod == other.authMethod && + endpoint == other.endpoint && + method == other.method && + params == other.params && + requestContentType == other.requestContentType && + responseContentType == other.responseContentType && + responseMap == other.responseMap && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + authHeaderValueFormat, + authMethod, + endpoint, + method, + params, + requestContentType, + responseContentType, + responseMap, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TokenRequest{authHeaderValueFormat=$authHeaderValueFormat, authMethod=$authMethod, endpoint=$endpoint, method=$method, params=$params, requestContentType=$requestContentType, responseContentType=$responseContentType, responseMap=$responseMap, additionalProperties=$additionalProperties}" + } + + class UserInfoRequest + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val authHeaderValueFormat: JsonField, + private val authMethod: JsonField, + private val endpoint: JsonField, + private val method: JsonField, + private val params: JsonField, + private val requestContentType: JsonField, + private val responseContentType: JsonField, + private val responseMap: JsonField, + private val triggers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth_header_value_format") + @ExcludeMissing + authHeaderValueFormat: JsonField = JsonMissing.of(), + @JsonProperty("auth_method") + @ExcludeMissing + authMethod: JsonField = JsonMissing.of(), @JsonProperty("endpoint") @ExcludeMissing endpoint: JsonField = JsonMissing.of(), @@ -4193,6 +5643,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserInfoRequest = apply { if (validated) { return@apply @@ -4297,6 +5757,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Params = apply { if (validated) { return@apply @@ -4438,6 +5908,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): RequestContentType = apply { if (validated) { return@apply @@ -4574,6 +6054,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseContentType = apply { if (validated) { return@apply @@ -4673,6 +6163,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ResponseMap = apply { if (validated) { return@apply @@ -4861,6 +6361,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Triggers = apply { if (validated) { return@apply @@ -4962,6 +6472,7 @@ private constructor( pkce == other.pkce && refreshRequest == other.refreshRequest && scopeDelimiter == other.scopeDelimiter && + tokenIntrospectionRequest == other.tokenIntrospectionRequest && tokenRequest == other.tokenRequest && userInfoRequest == other.userInfoRequest && additionalProperties == other.additionalProperties @@ -4975,6 +6486,7 @@ private constructor( pkce, refreshRequest, scopeDelimiter, + tokenIntrospectionRequest, tokenRequest, userInfoRequest, additionalProperties, @@ -4984,7 +6496,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Oauth2{authorizeRequest=$authorizeRequest, clientId=$clientId, clientSecret=$clientSecret, pkce=$pkce, refreshRequest=$refreshRequest, scopeDelimiter=$scopeDelimiter, tokenRequest=$tokenRequest, userInfoRequest=$userInfoRequest, additionalProperties=$additionalProperties}" + "Oauth2{authorizeRequest=$authorizeRequest, clientId=$clientId, clientSecret=$clientSecret, pkce=$pkce, refreshRequest=$refreshRequest, scopeDelimiter=$scopeDelimiter, tokenIntrospectionRequest=$tokenIntrospectionRequest, tokenRequest=$tokenRequest, userInfoRequest=$userInfoRequest, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretCreateParams.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretCreateParams.kt index a52b828..d180e72 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretCreateParams.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretCreateParams.kt @@ -430,6 +430,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Body = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretListResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretListResponse.kt index 9459f39..3f5778d 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretListResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretListResponse.kt @@ -243,6 +243,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): SecretListResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretResponse.kt index 4146152..5cf6ffe 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/secrets/SecretResponse.kt @@ -295,6 +295,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): SecretResponse = apply { if (validated) { return@apply @@ -456,6 +464,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -585,6 +602,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionListPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionListPageResponse.kt index 3d40096..8b8c721 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionListPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionListPageResponse.kt @@ -249,6 +249,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserConnectionListPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionResponse.kt index e1ea340..7a71e2a 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/admin/userconnections/UserConnectionResponse.kt @@ -395,6 +395,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UserConnectionResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/AuthRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/AuthRequest.kt index 6c761a5..fee209b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/AuthRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/AuthRequest.kt @@ -200,6 +200,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthRequest = apply { if (validated) { return@apply @@ -433,6 +441,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthRequirement = apply { if (validated) { return@apply @@ -584,6 +601,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserRequest.kt index dcf9388..8cb22e2 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserRequest.kt @@ -157,6 +157,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ConfirmUserRequest = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserResponse.kt index c76f5ba..cda22df 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/auth/ConfirmUserResponse.kt @@ -156,6 +156,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ConfirmUserResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatMessage.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatMessage.kt index d65d93a..6f6b40d 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatMessage.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatMessage.kt @@ -283,6 +283,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ChatMessage = apply { if (validated) { return@apply @@ -471,6 +479,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ToolCall = apply { if (validated) { return@apply @@ -634,6 +651,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Function = apply { if (validated) { return@apply @@ -767,6 +794,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatRequest.kt index 39bceff..1d7add6 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatRequest.kt @@ -768,6 +768,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ChatRequest = apply { if (validated) { return@apply @@ -891,6 +899,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): LogitBias = apply { if (validated) { return@apply @@ -1027,6 +1044,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ResponseFormat = apply { if (validated) { return@apply @@ -1141,6 +1167,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply @@ -1312,6 +1348,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): StreamOptions = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatResponse.kt index 20f907b..5530254 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/ChatResponse.kt @@ -310,6 +310,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ChatResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Choice.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Choice.kt index e652d4e..661cd0e 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Choice.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Choice.kt @@ -301,6 +301,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Choice = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Usage.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Usage.kt index 2166b90..1805d25 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Usage.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/chat/Usage.kt @@ -181,6 +181,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Usage = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/health/HealthSchema.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/health/HealthSchema.kt index 27720dd..7d4d392 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/health/HealthSchema.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/health/HealthSchema.kt @@ -140,6 +140,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): HealthSchema = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/AuthorizeToolRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/AuthorizeToolRequest.kt index 4842ecd..826d1f3 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/AuthorizeToolRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/AuthorizeToolRequest.kt @@ -226,6 +226,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): AuthorizeToolRequest = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolRequest.kt index 487040d..1e922e5 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolRequest.kt @@ -308,6 +308,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ExecuteToolRequest = apply { if (validated) { return@apply @@ -408,6 +416,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Input = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolResponse.kt index eb5c67b..de75202 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ExecuteToolResponse.kt @@ -380,6 +380,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ExecuteToolResponse = apply { if (validated) { return@apply @@ -687,6 +695,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Output = apply { if (validated) { return@apply @@ -1128,6 +1145,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Error = apply { if (validated) { return@apply @@ -1231,6 +1258,17 @@ private constructor( @JvmField val UPSTREAM_RUNTIME_UNMAPPED = of("UPSTREAM_RUNTIME_UNMAPPED") + @JvmField + val NETWORK_TRANSPORT_RUNTIME_TIMEOUT = of("NETWORK_TRANSPORT_RUNTIME_TIMEOUT") + + @JvmField + val NETWORK_TRANSPORT_RUNTIME_UNREACHABLE = + of("NETWORK_TRANSPORT_RUNTIME_UNREACHABLE") + + @JvmField + val NETWORK_TRANSPORT_RUNTIME_UNMAPPED = + of("NETWORK_TRANSPORT_RUNTIME_UNMAPPED") + @JvmField val UNKNOWN = of("UNKNOWN") @JvmStatic fun of(value: String) = Kind(JsonField.of(value)) @@ -1257,6 +1295,9 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT, UPSTREAM_RUNTIME_SERVER_ERROR, UPSTREAM_RUNTIME_UNMAPPED, + NETWORK_TRANSPORT_RUNTIME_TIMEOUT, + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE, + NETWORK_TRANSPORT_RUNTIME_UNMAPPED, UNKNOWN, } @@ -1289,6 +1330,9 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT, UPSTREAM_RUNTIME_SERVER_ERROR, UPSTREAM_RUNTIME_UNMAPPED, + NETWORK_TRANSPORT_RUNTIME_TIMEOUT, + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE, + NETWORK_TRANSPORT_RUNTIME_UNMAPPED, UNKNOWN, /** * An enum member indicating that [Kind] was instantiated with an unknown value. @@ -1324,6 +1368,11 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT -> Value.UPSTREAM_RUNTIME_RATE_LIMIT UPSTREAM_RUNTIME_SERVER_ERROR -> Value.UPSTREAM_RUNTIME_SERVER_ERROR UPSTREAM_RUNTIME_UNMAPPED -> Value.UPSTREAM_RUNTIME_UNMAPPED + NETWORK_TRANSPORT_RUNTIME_TIMEOUT -> Value.NETWORK_TRANSPORT_RUNTIME_TIMEOUT + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE -> + Value.NETWORK_TRANSPORT_RUNTIME_UNREACHABLE + NETWORK_TRANSPORT_RUNTIME_UNMAPPED -> + Value.NETWORK_TRANSPORT_RUNTIME_UNMAPPED UNKNOWN -> Value.UNKNOWN else -> Value._UNKNOWN } @@ -1358,6 +1407,11 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT -> Known.UPSTREAM_RUNTIME_RATE_LIMIT UPSTREAM_RUNTIME_SERVER_ERROR -> Known.UPSTREAM_RUNTIME_SERVER_ERROR UPSTREAM_RUNTIME_UNMAPPED -> Known.UPSTREAM_RUNTIME_UNMAPPED + NETWORK_TRANSPORT_RUNTIME_TIMEOUT -> Known.NETWORK_TRANSPORT_RUNTIME_TIMEOUT + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE -> + Known.NETWORK_TRANSPORT_RUNTIME_UNREACHABLE + NETWORK_TRANSPORT_RUNTIME_UNMAPPED -> + Known.NETWORK_TRANSPORT_RUNTIME_UNMAPPED UNKNOWN -> Known.UNKNOWN else -> throw ArcadeInvalidDataException("Unknown Kind: $value") } @@ -1378,6 +1432,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Kind = apply { if (validated) { return@apply @@ -1477,6 +1541,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Extra = apply { if (validated) { return@apply @@ -1741,6 +1815,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Log = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolDefinition.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolDefinition.kt index 7be442a..ab6b906 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolDefinition.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolDefinition.kt @@ -440,6 +440,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ToolDefinition = apply { if (validated) { return@apply @@ -601,6 +609,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Input = apply { if (validated) { return@apply @@ -888,6 +905,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Parameter = apply { if (validated) { return@apply @@ -1149,6 +1176,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Toolkit = apply { if (validated) { return@apply @@ -1260,6 +1296,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): FormattedSchema = apply { if (validated) { return@apply @@ -1464,6 +1509,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Metadata = apply { if (validated) { return@apply @@ -1756,6 +1810,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Behavior = apply { if (validated) { return@apply @@ -1945,6 +2009,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Classification = apply { if (validated) { return@apply @@ -2050,6 +2124,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Extras = apply { if (validated) { return@apply @@ -2302,6 +2386,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Output = apply { if (validated) { return@apply @@ -2536,6 +2629,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Requirements = apply { if (validated) { return@apply @@ -2884,6 +2986,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Authorization = apply { if (validated) { return@apply @@ -3044,6 +3156,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -3181,6 +3303,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Status = apply { if (validated) { return@apply @@ -3325,6 +3457,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): TokenStatus = apply { if (validated) { return@apply @@ -3580,6 +3722,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Secret = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecution.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecution.kt index f03513d..b110338 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecution.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecution.kt @@ -468,6 +468,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ToolExecution = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecutionAttempt.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecutionAttempt.kt index fd3dbb5..dbf0d89 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecutionAttempt.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolExecutionAttempt.kt @@ -273,6 +273,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ToolExecutionAttempt = apply { if (validated) { return@apply @@ -502,6 +510,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Output = apply { if (validated) { return@apply @@ -943,6 +960,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Error = apply { if (validated) { return@apply @@ -1046,6 +1073,17 @@ private constructor( @JvmField val UPSTREAM_RUNTIME_UNMAPPED = of("UPSTREAM_RUNTIME_UNMAPPED") + @JvmField + val NETWORK_TRANSPORT_RUNTIME_TIMEOUT = of("NETWORK_TRANSPORT_RUNTIME_TIMEOUT") + + @JvmField + val NETWORK_TRANSPORT_RUNTIME_UNREACHABLE = + of("NETWORK_TRANSPORT_RUNTIME_UNREACHABLE") + + @JvmField + val NETWORK_TRANSPORT_RUNTIME_UNMAPPED = + of("NETWORK_TRANSPORT_RUNTIME_UNMAPPED") + @JvmField val UNKNOWN = of("UNKNOWN") @JvmStatic fun of(value: String) = Kind(JsonField.of(value)) @@ -1072,6 +1110,9 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT, UPSTREAM_RUNTIME_SERVER_ERROR, UPSTREAM_RUNTIME_UNMAPPED, + NETWORK_TRANSPORT_RUNTIME_TIMEOUT, + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE, + NETWORK_TRANSPORT_RUNTIME_UNMAPPED, UNKNOWN, } @@ -1104,6 +1145,9 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT, UPSTREAM_RUNTIME_SERVER_ERROR, UPSTREAM_RUNTIME_UNMAPPED, + NETWORK_TRANSPORT_RUNTIME_TIMEOUT, + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE, + NETWORK_TRANSPORT_RUNTIME_UNMAPPED, UNKNOWN, /** * An enum member indicating that [Kind] was instantiated with an unknown value. @@ -1139,6 +1183,11 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT -> Value.UPSTREAM_RUNTIME_RATE_LIMIT UPSTREAM_RUNTIME_SERVER_ERROR -> Value.UPSTREAM_RUNTIME_SERVER_ERROR UPSTREAM_RUNTIME_UNMAPPED -> Value.UPSTREAM_RUNTIME_UNMAPPED + NETWORK_TRANSPORT_RUNTIME_TIMEOUT -> Value.NETWORK_TRANSPORT_RUNTIME_TIMEOUT + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE -> + Value.NETWORK_TRANSPORT_RUNTIME_UNREACHABLE + NETWORK_TRANSPORT_RUNTIME_UNMAPPED -> + Value.NETWORK_TRANSPORT_RUNTIME_UNMAPPED UNKNOWN -> Value.UNKNOWN else -> Value._UNKNOWN } @@ -1173,6 +1222,11 @@ private constructor( UPSTREAM_RUNTIME_RATE_LIMIT -> Known.UPSTREAM_RUNTIME_RATE_LIMIT UPSTREAM_RUNTIME_SERVER_ERROR -> Known.UPSTREAM_RUNTIME_SERVER_ERROR UPSTREAM_RUNTIME_UNMAPPED -> Known.UPSTREAM_RUNTIME_UNMAPPED + NETWORK_TRANSPORT_RUNTIME_TIMEOUT -> Known.NETWORK_TRANSPORT_RUNTIME_TIMEOUT + NETWORK_TRANSPORT_RUNTIME_UNREACHABLE -> + Known.NETWORK_TRANSPORT_RUNTIME_UNREACHABLE + NETWORK_TRANSPORT_RUNTIME_UNMAPPED -> + Known.NETWORK_TRANSPORT_RUNTIME_UNMAPPED UNKNOWN -> Known.UNKNOWN else -> throw ArcadeInvalidDataException("Unknown Kind: $value") } @@ -1193,6 +1247,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Kind = apply { if (validated) { return@apply @@ -1292,6 +1356,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Extra = apply { if (validated) { return@apply @@ -1556,6 +1630,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Log = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolGetParams.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolGetParams.kt index f851a95..301be76 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolGetParams.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolGetParams.kt @@ -323,6 +323,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): IncludeFormat = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListPageResponse.kt index 4910d9b..f961478 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListPageResponse.kt @@ -243,6 +243,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ToolListPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListParams.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListParams.kt index f5c8025..0b27170 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListParams.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ToolListParams.kt @@ -14,9 +14,13 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -/** Returns a page of tools from the engine configuration, optionally filtered by toolkit */ +/** + * Returns a page of tools from the engine configuration, optionally filtered by toolkit and/or + * metadata + */ class ToolListParams private constructor( + private val filter: String?, private val includeAllVersions: Boolean?, private val includeFormat: List?, private val limit: Long?, @@ -27,6 +31,13 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { + /** + * JSON metadata filter. Array fields (service_domains, operations): shorthand array or object + * with any_of/all_of/none_of operators (case-insensitive). Boolean fields: read_only, + * destructive, idempotent, open_world. Extras: case-sensitive key-value subset match. + */ + fun filter(): Optional = Optional.ofNullable(filter) + /** Include all versions of each tool */ fun includeAllVersions(): Optional = Optional.ofNullable(includeAllVersions) @@ -64,6 +75,7 @@ private constructor( /** A builder for [ToolListParams]. */ class Builder internal constructor() { + private var filter: String? = null private var includeAllVersions: Boolean? = null private var includeFormat: MutableList? = null private var limit: Long? = null @@ -75,6 +87,7 @@ private constructor( @JvmSynthetic internal fun from(toolListParams: ToolListParams) = apply { + filter = toolListParams.filter includeAllVersions = toolListParams.includeAllVersions includeFormat = toolListParams.includeFormat?.toMutableList() limit = toolListParams.limit @@ -85,6 +98,17 @@ private constructor( additionalQueryParams = toolListParams.additionalQueryParams.toBuilder() } + /** + * JSON metadata filter. Array fields (service_domains, operations): shorthand array or + * object with any_of/all_of/none_of operators (case-insensitive). Boolean fields: + * read_only, destructive, idempotent, open_world. Extras: case-sensitive key-value subset + * match. + */ + fun filter(filter: String?) = apply { this.filter = filter } + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + /** Include all versions of each tool */ fun includeAllVersions(includeAllVersions: Boolean?) = apply { this.includeAllVersions = includeAllVersions @@ -266,6 +290,7 @@ private constructor( */ fun build(): ToolListParams = ToolListParams( + filter, includeAllVersions, includeFormat?.toImmutable(), limit, @@ -282,6 +307,7 @@ private constructor( override fun _queryParams(): QueryParams = QueryParams.builder() .apply { + filter?.let { put("filter", it) } includeAllVersions?.let { put("include_all_versions", it.toString()) } includeFormat?.let { put("include_format", it.joinToString(",") { it.toString() }) } limit?.let { put("limit", it.toString()) } @@ -389,6 +415,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): IncludeFormat = apply { if (validated) { return@apply @@ -433,6 +468,7 @@ private constructor( } return other is ToolListParams && + filter == other.filter && includeAllVersions == other.includeAllVersions && includeFormat == other.includeFormat && limit == other.limit && @@ -445,6 +481,7 @@ private constructor( override fun hashCode(): Int = Objects.hash( + filter, includeAllVersions, includeFormat, limit, @@ -456,5 +493,5 @@ private constructor( ) override fun toString() = - "ToolListParams{includeAllVersions=$includeAllVersions, includeFormat=$includeFormat, limit=$limit, offset=$offset, toolkit=$toolkit, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "ToolListParams{filter=$filter, includeAllVersions=$includeAllVersions, includeFormat=$includeFormat, limit=$limit, offset=$offset, toolkit=$toolkit, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ValueSchema.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ValueSchema.kt index 06139a7..0e5223b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ValueSchema.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/ValueSchema.kt @@ -209,6 +209,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ValueSchema = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedGetResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedGetResponse.kt index 3ebb65e..c0c1d55 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedGetResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedGetResponse.kt @@ -68,6 +68,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): FormattedGetResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListPageResponse.kt index 0d6c9cb..7494c4b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListPageResponse.kt @@ -247,6 +247,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): FormattedListPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListParams.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListParams.kt index 3112f34..4231263 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListParams.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListParams.kt @@ -15,6 +15,7 @@ import kotlin.jvm.optionals.getOrNull */ class FormattedListParams private constructor( + private val filter: String?, private val format: String?, private val includeAllVersions: Boolean?, private val limit: Long?, @@ -25,6 +26,13 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { + /** + * JSON metadata filter. Array fields (service_domains, operations): shorthand array or object + * with any_of/all_of/none_of operators (case-insensitive). Boolean fields: read_only, + * destructive, idempotent, open_world. Extras: case-sensitive key-value subset match. + */ + fun filter(): Optional = Optional.ofNullable(filter) + /** Provider format */ fun format(): Optional = Optional.ofNullable(format) @@ -62,6 +70,7 @@ private constructor( /** A builder for [FormattedListParams]. */ class Builder internal constructor() { + private var filter: String? = null private var format: String? = null private var includeAllVersions: Boolean? = null private var limit: Long? = null @@ -73,6 +82,7 @@ private constructor( @JvmSynthetic internal fun from(formattedListParams: FormattedListParams) = apply { + filter = formattedListParams.filter format = formattedListParams.format includeAllVersions = formattedListParams.includeAllVersions limit = formattedListParams.limit @@ -83,6 +93,17 @@ private constructor( additionalQueryParams = formattedListParams.additionalQueryParams.toBuilder() } + /** + * JSON metadata filter. Array fields (service_domains, operations): shorthand array or + * object with any_of/all_of/none_of operators (case-insensitive). Boolean fields: + * read_only, destructive, idempotent, open_world. Extras: case-sensitive key-value subset + * match. + */ + fun filter(filter: String?) = apply { this.filter = filter } + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + /** Provider format */ fun format(format: String?) = apply { this.format = format } @@ -251,6 +272,7 @@ private constructor( */ fun build(): FormattedListParams = FormattedListParams( + filter, format, includeAllVersions, limit, @@ -267,6 +289,7 @@ private constructor( override fun _queryParams(): QueryParams = QueryParams.builder() .apply { + filter?.let { put("filter", it) } format?.let { put("format", it) } includeAllVersions?.let { put("include_all_versions", it.toString()) } limit?.let { put("limit", it.toString()) } @@ -283,6 +306,7 @@ private constructor( } return other is FormattedListParams && + filter == other.filter && format == other.format && includeAllVersions == other.includeAllVersions && limit == other.limit && @@ -295,6 +319,7 @@ private constructor( override fun hashCode(): Int = Objects.hash( + filter, format, includeAllVersions, limit, @@ -306,5 +331,5 @@ private constructor( ) override fun toString() = - "FormattedListParams{format=$format, includeAllVersions=$includeAllVersions, limit=$limit, offset=$offset, toolkit=$toolkit, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "FormattedListParams{filter=$filter, format=$format, includeAllVersions=$includeAllVersions, limit=$limit, offset=$offset, toolkit=$toolkit, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListResponse.kt index c2c3672..2ee357b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/formatted/FormattedListResponse.kt @@ -69,6 +69,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): FormattedListResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledGetResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledGetResponse.kt index b8b575d..c4c95d1 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledGetResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledGetResponse.kt @@ -549,6 +549,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ScheduledGetResponse = apply { if (validated) { return@apply @@ -659,6 +667,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Input = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledListPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledListPageResponse.kt index 98f1c94..c637e90 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledListPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/tools/scheduled/ScheduledListPageResponse.kt @@ -246,6 +246,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): ScheduledListPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/CreateWorkerRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/CreateWorkerRequest.kt index ed1a052..747f590 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/CreateWorkerRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/CreateWorkerRequest.kt @@ -242,6 +242,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): CreateWorkerRequest = apply { if (validated) { return@apply @@ -482,6 +490,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Http = apply { if (validated) { return@apply @@ -800,6 +817,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Mcp = apply { if (validated) { return@apply @@ -898,6 +924,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Headers = apply { if (validated) { return@apply @@ -1154,6 +1190,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -1277,6 +1323,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Secrets = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/UpdateWorkerRequest.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/UpdateWorkerRequest.kt index 039958e..31bda7a 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/UpdateWorkerRequest.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/UpdateWorkerRequest.kt @@ -166,6 +166,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): UpdateWorkerRequest = apply { if (validated) { return@apply @@ -376,6 +384,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Http = apply { if (validated) { return@apply @@ -676,6 +693,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Mcp = apply { if (validated) { return@apply @@ -774,6 +800,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Headers = apply { if (validated) { return@apply @@ -994,6 +1030,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -1108,6 +1154,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Secrets = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerHealthResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerHealthResponse.kt index 8a54a8c..f9dae32 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerHealthResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerHealthResponse.kt @@ -191,6 +191,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): WorkerHealthResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerListPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerListPageResponse.kt index 8609944..d9aea4b 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerListPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerListPageResponse.kt @@ -243,6 +243,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): WorkerListPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerResponse.kt index 51843b5..444c77e 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerResponse.kt @@ -320,6 +320,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): WorkerResponse = apply { if (validated) { return@apply @@ -483,6 +491,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -612,6 +629,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply @@ -849,6 +876,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Http = apply { if (validated) { return@apply @@ -1072,6 +1108,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Secret = apply { if (validated) { return@apply @@ -1210,6 +1256,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -1297,8 +1353,10 @@ private constructor( class Mcp @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val externalId: JsonField, private val headers: JsonField, private val oauth2: JsonField, + private val redirectUri: JsonField, private val retry: JsonField, private val secrets: JsonField, private val timeout: JsonField, @@ -1308,13 +1366,35 @@ private constructor( @JsonCreator private constructor( + @JsonProperty("external_id") + @ExcludeMissing + externalId: JsonField = JsonMissing.of(), @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), @JsonProperty("oauth2") @ExcludeMissing oauth2: JsonField = JsonMissing.of(), + @JsonProperty("redirect_uri") + @ExcludeMissing + redirectUri: JsonField = JsonMissing.of(), @JsonProperty("retry") @ExcludeMissing retry: JsonField = JsonMissing.of(), @JsonProperty("secrets") @ExcludeMissing secrets: JsonField = JsonMissing.of(), @JsonProperty("timeout") @ExcludeMissing timeout: JsonField = JsonMissing.of(), @JsonProperty("uri") @ExcludeMissing uri: JsonField = JsonMissing.of(), - ) : this(headers, oauth2, retry, secrets, timeout, uri, mutableMapOf()) + ) : this( + externalId, + headers, + oauth2, + redirectUri, + retry, + secrets, + timeout, + uri, + mutableMapOf(), + ) + + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalId(): Optional = externalId.getOptional("external_id") /** * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -1328,6 +1408,12 @@ private constructor( */ fun oauth2(): Optional = oauth2.getOptional("oauth2") + /** + * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun redirectUri(): Optional = redirectUri.getOptional("redirect_uri") + /** * @throws ArcadeInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1352,6 +1438,15 @@ private constructor( */ fun uri(): Optional = uri.getOptional("uri") + /** + * Returns the raw JSON value of [externalId]. + * + * Unlike [externalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("external_id") + @ExcludeMissing + fun _externalId(): JsonField = externalId + /** * Returns the raw JSON value of [headers]. * @@ -1366,6 +1461,15 @@ private constructor( */ @JsonProperty("oauth2") @ExcludeMissing fun _oauth2(): JsonField = oauth2 + /** + * Returns the raw JSON value of [redirectUri]. + * + * Unlike [redirectUri], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("redirect_uri") + @ExcludeMissing + fun _redirectUri(): JsonField = redirectUri + /** * Returns the raw JSON value of [retry]. * @@ -1415,8 +1519,10 @@ private constructor( /** A builder for [Mcp]. */ class Builder internal constructor() { + private var externalId: JsonField = JsonMissing.of() private var headers: JsonField = JsonMissing.of() private var oauth2: JsonField = JsonMissing.of() + private var redirectUri: JsonField = JsonMissing.of() private var retry: JsonField = JsonMissing.of() private var secrets: JsonField = JsonMissing.of() private var timeout: JsonField = JsonMissing.of() @@ -1425,8 +1531,10 @@ private constructor( @JvmSynthetic internal fun from(mcp: Mcp) = apply { + externalId = mcp.externalId headers = mcp.headers oauth2 = mcp.oauth2 + redirectUri = mcp.redirectUri retry = mcp.retry secrets = mcp.secrets timeout = mcp.timeout @@ -1434,6 +1542,17 @@ private constructor( additionalProperties = mcp.additionalProperties.toMutableMap() } + fun externalId(externalId: String) = externalId(JsonField.of(externalId)) + + /** + * Sets [Builder.externalId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalId(externalId: JsonField) = apply { this.externalId = externalId } + fun headers(headers: Headers) = headers(JsonField.of(headers)) /** @@ -1456,6 +1575,19 @@ private constructor( */ fun oauth2(oauth2: JsonField) = apply { this.oauth2 = oauth2 } + fun redirectUri(redirectUri: String) = redirectUri(JsonField.of(redirectUri)) + + /** + * Sets [Builder.redirectUri] to an arbitrary JSON value. + * + * You should usually call [Builder.redirectUri] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun redirectUri(redirectUri: JsonField) = apply { + this.redirectUri = redirectUri + } + fun retry(retry: Long) = retry(JsonField.of(retry)) /** @@ -1526,8 +1658,10 @@ private constructor( */ fun build(): Mcp = Mcp( + externalId, headers, oauth2, + redirectUri, retry, secrets, timeout, @@ -1538,13 +1672,24 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Mcp = apply { if (validated) { return@apply } + externalId() headers().ifPresent { it.validate() } oauth2().ifPresent { it.validate() } + redirectUri() retry() secrets().ifPresent { it.validate() } timeout() @@ -1568,8 +1713,10 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (externalId.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + (oauth2.asKnown().getOrNull()?.validity() ?: 0) + + (if (redirectUri.asKnown().isPresent) 1 else 0) + (if (retry.asKnown().isPresent) 1 else 0) + (secrets.asKnown().getOrNull()?.validity() ?: 0) + (if (timeout.asKnown().isPresent) 1 else 0) + @@ -1636,6 +1783,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Headers = apply { if (validated) { return@apply @@ -1987,6 +2144,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -2229,6 +2396,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): ClientSecret = apply { if (validated) { return@apply @@ -2369,6 +2546,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ fun validate(): Binding = apply { if (validated) { return@apply @@ -2525,6 +2712,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Secrets = apply { if (validated) { return@apply @@ -2572,8 +2769,10 @@ private constructor( } return other is Mcp && + externalId == other.externalId && headers == other.headers && oauth2 == other.oauth2 && + redirectUri == other.redirectUri && retry == other.retry && secrets == other.secrets && timeout == other.timeout && @@ -2582,13 +2781,23 @@ private constructor( } private val hashCode: Int by lazy { - Objects.hash(headers, oauth2, retry, secrets, timeout, uri, additionalProperties) + Objects.hash( + externalId, + headers, + oauth2, + redirectUri, + retry, + secrets, + timeout, + uri, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "Mcp{headers=$headers, oauth2=$oauth2, retry=$retry, secrets=$secrets, timeout=$timeout, uri=$uri, additionalProperties=$additionalProperties}" + "Mcp{externalId=$externalId, headers=$headers, oauth2=$oauth2, redirectUri=$redirectUri, retry=$retry, secrets=$secrets, timeout=$timeout, uri=$uri, additionalProperties=$additionalProperties}" } class Requirements @@ -2723,6 +2932,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Requirements = apply { if (validated) { return@apply @@ -2879,6 +3097,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Authorization = apply { if (validated) { return@apply @@ -3006,6 +3234,16 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ fun validate(): Oauth2 = apply { if (validated) { return@apply @@ -3180,6 +3418,15 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): Type = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerToolsPageResponse.kt b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerToolsPageResponse.kt index b585877..d4f4d91 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerToolsPageResponse.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/models/workers/WorkerToolsPageResponse.kt @@ -244,6 +244,14 @@ private constructor( private var validated: Boolean = false + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws ArcadeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ fun validate(): WorkerToolsPageResponse = apply { if (validated) { return@apply diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/services/async/ToolServiceAsync.kt b/arcade-java-core/src/main/kotlin/dev/arcade/services/async/ToolServiceAsync.kt index 4a773b7..c59e0f6 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/services/async/ToolServiceAsync.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/services/async/ToolServiceAsync.kt @@ -38,7 +38,10 @@ interface ToolServiceAsync { fun formatted(): FormattedServiceAsync - /** Returns a page of tools from the engine configuration, optionally filtered by toolkit */ + /** + * Returns a page of tools from the engine configuration, optionally filtered by toolkit and/or + * metadata + */ fun list(): CompletableFuture = list(ToolListParams.none()) /** @see list */ diff --git a/arcade-java-core/src/main/kotlin/dev/arcade/services/blocking/ToolService.kt b/arcade-java-core/src/main/kotlin/dev/arcade/services/blocking/ToolService.kt index 22a6d53..c10f1fa 100644 --- a/arcade-java-core/src/main/kotlin/dev/arcade/services/blocking/ToolService.kt +++ b/arcade-java-core/src/main/kotlin/dev/arcade/services/blocking/ToolService.kt @@ -38,7 +38,10 @@ interface ToolService { fun formatted(): FormattedService - /** Returns a page of tools from the engine configuration, optionally filtered by toolkit */ + /** + * Returns a page of tools from the engine configuration, optionally filtered by toolkit and/or + * metadata + */ fun list(): ToolListPage = list(ToolListParams.none()) /** @see list */ diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/core/ClientOptionsTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/core/ClientOptionsTest.kt index 8a79f69..10e787e 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/core/ClientOptionsTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/core/ClientOptionsTest.kt @@ -16,6 +16,29 @@ internal class ClientOptionsTest { private val httpClient = mock() + @Test + fun putHeader_canOverwriteDefaultHeader() { + val clientOptions = + ClientOptions.builder() + .httpClient(httpClient) + .putHeader("User-Agent", "My User Agent") + .apiKey("My API Key") + .build() + + assertThat(clientOptions.headers.values("User-Agent")).containsExactly("My User Agent") + } + + @Test + fun toBuilder_bearerCanBeUpdated() { + var clientOptions = + ClientOptions.builder().httpClient(httpClient).apiKey("My API Key").build() + + clientOptions = clientOptions.toBuilder().apiKey("another My API Key").build() + + assertThat(clientOptions.headers.values("Authorization")) + .containsExactly("another My API Key") + } + @Test fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient() { var clientOptions = diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/core/http/LoggingHttpClientTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/core/http/LoggingHttpClientTest.kt new file mode 100644 index 0000000..cec3a67 --- /dev/null +++ b/arcade-java-core/src/test/kotlin/dev/arcade/core/http/LoggingHttpClientTest.kt @@ -0,0 +1,999 @@ +// File generated from our OpenAPI spec by Stainless. + +package dev.arcade.core.http + +import dev.arcade.core.LogLevel +import dev.arcade.core.RequestOptions +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream +import java.io.PrintStream +import java.nio.charset.StandardCharsets +import java.time.Clock +import java.time.Instant +import java.time.ZoneOffset +import java.util.concurrent.CompletableFuture +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatThrownBy +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.ResourceLock +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource + +@ResourceLock("stderr") +internal class LoggingHttpClientTest { + + private lateinit var originalErr: PrintStream + private lateinit var errContent: ByteArrayOutputStream + + @BeforeEach + fun beforeEach() { + originalErr = System.err + errContent = ByteArrayOutputStream() + System.setErr(PrintStream(errContent)) + } + + @AfterEach + fun afterEach() { + System.setErr(originalErr) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun offLevel_noOutput(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.OFF) + + val response = client.execute(simpleGetRequest(), async).apply { body().readBytes() } + + assertThat(response.statusCode()).isEqualTo(200) + assertThat(stderrOutput()).isEmpty() + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_logsGetRequest(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.INFO) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- 200 (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_logsPostRequestWithBodySize(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.INFO) + + client.execute(postRequestWithBody("""{"key":"value"}"""), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> POST https://api.example.com/v1/resources (15-byte body) + |<-- 200 (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_logsRequestWithUnknownLengthBody(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.INFO) + + client + .execute(postRequestWithBody("""{"key":"value"}""", contentLength = -1L), async) + .body() + .readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> POST https://api.example.com/v1/resources (unknown-length body) + |<-- 200 (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_logsResponseStatusAndDuration(async: Boolean) { + val clock = + clockFrom( + Instant.parse("1998-04-21T00:00:00Z"), + Instant.parse("1998-04-21T00:00:01.234Z"), + ) + val client = loggingClient(fakeHttpClient(statusCode = 201), LogLevel.INFO, clock) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- 201 (1s 234ms) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_logsResponseContentLength(async: Boolean) { + val headers = + Headers.builder().put("Content-Length", "42").put("Content-Type", "text/plain").build() + val client = loggingClient(fakeHttpClient(responseHeaders = headers), LogLevel.INFO) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- 200 (0s, 42-byte body) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_doesNotLogHeaders(async: Boolean) { + val headers = Headers.builder().put("X-Custom", "visible").build() + val client = loggingClient(fakeHttpClient(responseHeaders = headers), LogLevel.INFO) + + client + .execute( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("v1") + .putHeader("X-Request-Custom", "req-value") + .build(), + async, + ) + .body() + .readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1 + |<-- 200 (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsGetWithEndMarker(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.DEBUG) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsRequestAndResponseHeaders(async: Boolean) { + val responseHeaders = + Headers.builder() + .put("X-Response-Id", "abc-123") + .put("Content-Type", "text/plain") + .build() + val client = + loggingClient(fakeHttpClient(responseHeaders = responseHeaders), LogLevel.DEBUG) + + client + .execute( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("test") + .putHeader("X-Custom", "my-value") + .build(), + async, + ) + .body() + .readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/test + |X-Custom: my-value + |--> END GET + | + |<-- 200 (0s) + |Content-Type: text/plain + |X-Response-Id: abc-123 + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_redactsSensitiveHeaders(async: Boolean) { + val client = + loggingClient( + fakeHttpClient(), + LogLevel.DEBUG, + redactedHeaders = setOf("Authorization", "X-Secret"), + ) + + client + .execute( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("test") + .putHeader("Authorization", "Bearer token-123") + .putHeader("X-Secret", "secret-value") + .putHeader("X-Public", "public-value") + .build(), + async, + ) + .body() + .readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/test + |Authorization: ██ + |X-Public: public-value + |X-Secret: ██ + |--> END GET + | + |<-- 200 (0s) + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_redactsHeadersCaseInsensitively(async: Boolean) { + val client = + loggingClient( + fakeHttpClient(), + LogLevel.DEBUG, + redactedHeaders = setOf("Authorization"), + ) + + client + .execute( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("test") + .putHeader("authorization", "Bearer secret") + .build(), + async, + ) + .body() + .readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/test + |authorization: ██ + |--> END GET + | + |<-- 200 (0s) + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsRequestBody(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.DEBUG) + val body = """{"name":"test","value":42}""" + + client.execute(postRequestWithBody(body), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> POST https://api.example.com/v1/resources (26-byte body) + | + |{"name":"test","value":42} + |--> END POST (26-byte body) + | + |<-- 200 (0s) + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsResponseBody(async: Boolean) { + val responseBody = """{"id":1,"status":"ok"}""" + val headers = Headers.builder().put("Content-Type", "application/json").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + val response = client.execute(simpleGetRequest(), async) + val body = response.body().readBytes().toString(StandardCharsets.UTF_8) + + assertThat(body).isEqualTo(responseBody) + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: application/json + | + |{"id":1,"status":"ok"} + |<-- END HTTP (22-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsBinaryResponseBodyAsOmitted(async: Boolean) { + val binaryBody = ByteArray(256) { it.toByte() } + val client = loggingClient(fakeHttpClient(responseBody = binaryBody), LogLevel.DEBUG) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + | + |(binary body omitted) + |<-- END HTTP (256-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsMultilineResponseBody(async: Boolean) { + val multilineBody = "line1\nline2\nline3" + val headers = Headers.builder().put("Content-Type", "text/plain; charset=utf-8").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = multilineBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: text/plain; charset=utf-8 + | + |line1 + |line2 + |line3 + |<-- END HTTP (17-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsResponseBodyWithExplicitCharset(async: Boolean) { + val responseBody = "héllo wörld" + val headers = Headers.builder().put("Content-Type", "text/plain; charset=utf-8").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: text/plain; charset=utf-8 + | + |héllo wörld + |<-- END HTTP (13-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsResponseBodyWithNoContentType(async: Boolean) { + val responseBody = "plain text body" + val client = + loggingClient( + fakeHttpClient(responseBody = responseBody.toByteArray(StandardCharsets.UTF_8)), + LogLevel.DEBUG, + ) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + | + |plain text body + |<-- END HTTP (15-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsEmptyResponseBody(async: Boolean) { + val client = loggingClient(fakeHttpClient(), LogLevel.DEBUG) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |<-- END HTTP (0-byte body) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsEndHttpMarkerOnEarlyClose(async: Boolean) { + val responseBody = """{"id":1,"status":"ok"}""" + val headers = Headers.builder().put("Content-Type", "application/json").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + val body = client.execute(simpleGetRequest(), async).body() + body.read(ByteArray(5)) + body.close() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: application/json + | + |{"id" + |<-- END HTTP (5-byte body, closed early) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsEndHttpMarkerOnCloseWithoutReading(async: Boolean) { + val responseBody = """{"id":1,"status":"ok"}""" + val headers = Headers.builder().put("Content-Type", "application/json").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + client.execute(simpleGetRequest(), async).body().close() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: application/json + |<-- END HTTP (0-byte body, closed early) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsEndHttpMarkerWhenResponseClosedAfterPartialRead(async: Boolean) { + val responseBody = """{"id":1,"status":"ok"}""" + val headers = Headers.builder().put("Content-Type", "application/json").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + val response = client.execute(simpleGetRequest(), async) + response.body().read(ByteArray(5)) + response.close() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: application/json + | + |{"id" + |<-- END HTTP (5-byte body, closed early) + | + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_doesNotLogEndHttpMarkerWhenResponseClosedWithoutBodyAccess(async: Boolean) { + val responseBody = """{"id":1,"status":"ok"}""" + val headers = Headers.builder().put("Content-Type", "application/json").build() + val client = + loggingClient( + fakeHttpClient( + responseHeaders = headers, + responseBody = responseBody.toByteArray(StandardCharsets.UTF_8), + ), + LogLevel.DEBUG, + ) + + client.execute(simpleGetRequest(), async).close() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- 200 (0s) + |Content-Type: application/json + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun errorLevel_logsRequestFailure(async: Boolean) { + val clock = + clockFrom( + Instant.parse("1998-04-21T00:00:00Z"), + Instant.parse("1998-04-21T00:00:01.234Z"), + ) + val client = + loggingClient( + failingHttpClient(IOException("Connection refused")), + LogLevel.ERROR, + clock, + ) + + assertThatThrownBy { client.execute(simpleGetRequest(), async) } + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- !! IOException: Connection refused (1s 234ms) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun infoLevel_doesNotLogRequestFailure(async: Boolean) { + val client = + loggingClient(failingHttpClient(IOException("Connection refused")), LogLevel.INFO) + + assertThatThrownBy { client.execute(simpleGetRequest(), async) } + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun debugLevel_logsRequestFailureAfterHeaders(async: Boolean) { + val client = + loggingClient(failingHttpClient(IOException("Connection refused")), LogLevel.DEBUG) + + assertThatThrownBy { client.execute(simpleGetRequest(), async) } + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |--> END GET + | + |<-- !! IOException: Connection refused (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun errorLevel_logsRequestFailureWithoutMessage(async: Boolean) { + val client = loggingClient(failingHttpClient(IOException()), LogLevel.ERROR) + + assertThatThrownBy { client.execute(simpleGetRequest(), async) } + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- !! IOException (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun offLevel_doesNotLogRequestFailure(async: Boolean) { + val client = + loggingClient(failingHttpClient(IOException("Connection refused")), LogLevel.OFF) + + assertThatThrownBy { client.execute(simpleGetRequest(), async) } + + assertThat(stderrOutput()).isEmpty() + } + + @Test + fun errorLevel_logsExecuteAsyncSynchronousThrow() { + val error = IOException("Connection refused") + val client = + loggingClient( + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse = throw UnsupportedOperationException() + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture = throw error + + override fun close() {} + }, + LogLevel.ERROR, + ) + + assertThatThrownBy { client.execute(simpleGetRequest(), async = true) }.isSameAs(error) + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- !! IOException: Connection refused (0s) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun durationFormat_seconds(async: Boolean) { + val clock = + clockFrom( + Instant.parse("1998-04-21T00:00:00Z"), + Instant.parse("1998-04-21T00:00:02.500Z"), + ) + val client = loggingClient(fakeHttpClient(), LogLevel.INFO, clock) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- 200 (2s 500ms) + |""" + .trimMargin() + ) + } + + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun durationFormat_minutesAndSeconds(async: Boolean) { + val clock = + clockFrom( + Instant.parse("1998-04-21T00:00:00Z"), + Instant.parse("1998-04-21T00:01:40.467Z"), + ) + val client = loggingClient(fakeHttpClient(), LogLevel.INFO, clock) + + client.execute(simpleGetRequest(), async).body().readBytes() + + assertThat(stderrOutput()) + .isEqualTo( + """ + |--> GET https://api.example.com/v1/resources + |<-- 200 (1m 40s 467ms) + |""" + .trimMargin() + ) + } + + @Test + fun builder_toBuilder_roundtrips() { + val delegate = fakeHttpClient() + val clock = Clock.fixed(Instant.parse("1998-04-21T00:00:00Z"), ZoneOffset.UTC) + val client = + LoggingHttpClient.builder() + .httpClient(delegate) + .level(LogLevel.DEBUG) + .redactedHeaders(setOf("X-Secret")) + .clock(clock) + .build() + + val rebuilt = client.toBuilder().build() + + assertThat(rebuilt.httpClient).isSameAs(delegate) + assertThat(rebuilt.level).isEqualTo(LogLevel.DEBUG) + assertThat(rebuilt.redactedHeaders).containsExactly("X-Secret") + assertThat(rebuilt.clock).isEqualTo(clock) + } + + @Test + fun close_delegatesToUnderlyingClient() { + var closed = false + val delegate = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse = throw UnsupportedOperationException() + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture = throw UnsupportedOperationException() + + override fun close() { + closed = true + } + } + val client = loggingClient(delegate, LogLevel.OFF) + + client.close() + + assertThat(closed).isTrue() + } + + private fun stderrOutput(): String = errContent.toString("UTF-8") + + private fun loggingClient( + httpClient: HttpClient, + level: LogLevel, + clock: Clock = clockFrom(Instant.parse("1998-04-21T00:00:00Z")), + redactedHeaders: Set = setOf("Authorization"), + ): LoggingHttpClient = + LoggingHttpClient.builder() + .httpClient(httpClient) + .level(level) + .clock(clock) + .redactedHeaders(redactedHeaders) + .build() + + private fun simpleGetRequest(): HttpRequest = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("v1") + .addPathSegment("resources") + .build() + + private fun postRequestWithBody( + body: String, + contentType: String = "application/json", + contentLength: Long? = null, + ): HttpRequest = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl("https://api.example.com") + .addPathSegment("v1") + .addPathSegment("resources") + .body( + object : HttpRequestBody { + private val bytes = body.toByteArray(StandardCharsets.UTF_8) + + override fun writeTo(outputStream: OutputStream) { + outputStream.write(bytes) + } + + override fun contentType(): String = contentType + + override fun contentLength(): Long = contentLength ?: bytes.size.toLong() + + override fun repeatable(): Boolean = true + + override fun close() {} + } + ) + .build() + + private fun fakeHttpClient( + statusCode: Int = 200, + responseHeaders: Headers = Headers.builder().build(), + responseBody: ByteArray = ByteArray(0), + ): HttpClient = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse { + // Consume the request body if present to trigger logging. + request.body?.let { + val out = ByteArrayOutputStream() + it.writeTo(out) + } + return fakeResponse(statusCode, responseHeaders, responseBody) + } + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture = + CompletableFuture.completedFuture(execute(request, requestOptions)) + + override fun close() {} + } + + private fun failingHttpClient(error: Throwable): HttpClient = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse { + request.body?.let { + val out = ByteArrayOutputStream() + it.writeTo(out) + } + throw error + } + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture { + val future = CompletableFuture() + future.completeExceptionally(error) + return future + } + + override fun close() {} + } + + private fun fakeResponse(statusCode: Int, headers: Headers, body: ByteArray): HttpResponse = + object : HttpResponse { + override fun statusCode(): Int = statusCode + + override fun headers(): Headers = headers + + override fun body(): InputStream = ByteArrayInputStream(body) + + override fun close() {} + } + + private fun clockFrom(vararg instants: Instant): Clock = + object : Clock() { + private var index = 0 + + override fun getZone() = ZoneOffset.UTC + + override fun withZone(zone: java.time.ZoneId?) = this + + override fun instant(): Instant { + val instant = instants[index % instants.size] + index++ + return instant + } + } + + private fun HttpClient.execute(request: HttpRequest, async: Boolean): HttpResponse = + if (async) executeAsync(request).get() else execute(request) +} diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/core/http/RetryingHttpClientTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/core/http/RetryingHttpClientTest.kt index 1e64d8e..b7a4609 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/core/http/RetryingHttpClientTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/core/http/RetryingHttpClientTest.kt @@ -400,9 +400,9 @@ internal class RetryingHttpClientTest { assertThat(sleeper.durations).hasSize(3) // retries=1: 0.5s * [0.75, 1.0] assertThat(sleeper.durations[0]).isBetween(Duration.ofMillis(375), Duration.ofMillis(500)) - // retries=2: 1.0s * [0.75, 1.0] + // retries=2: 1s * [0.75, 1.0] assertThat(sleeper.durations[1]).isBetween(Duration.ofMillis(750), Duration.ofMillis(1000)) - // retries=3: 2.0s * [0.75, 1.0] + // retries=3: 2s * [0.75, 1.0] assertThat(sleeper.durations[2]).isBetween(Duration.ofMillis(1500), Duration.ofMillis(2000)) assertNoResponseLeaks() } @@ -427,9 +427,9 @@ internal class RetryingHttpClientTest { assertThat(response.statusCode()).isEqualTo(503) verify(7, postRequestedFor(urlPathEqualTo("/something"))) assertThat(sleeper.durations).hasSize(6) - // retries=5: min(0.5 * 2^4, 8) = 8.0s * [0.75, 1.0] + // retries=5: backoff hits the 8s cap * [0.75, 1.0] assertThat(sleeper.durations[4]).isBetween(Duration.ofMillis(6000), Duration.ofMillis(8000)) - // retries=6: min(0.5 * 2^5, 8) = min(16, 8) = 8.0s * [0.75, 1.0] (capped) + // retries=6: still capped at 8s * [0.75, 1.0] assertThat(sleeper.durations[5]).isBetween(Duration.ofMillis(6000), Duration.ofMillis(8000)) assertNoResponseLeaks() } diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderPatchParamsTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderPatchParamsTest.kt index 6e659de..b0d2dab 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderPatchParamsTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderPatchParamsTest.kt @@ -90,6 +90,46 @@ internal class AuthProviderPatchParamsTest { .scopeDelimiter( AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2 ) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") @@ -276,6 +316,58 @@ internal class AuthProviderPatchParamsTest { .scopeDelimiter( AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2 ) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") @@ -448,6 +540,46 @@ internal class AuthProviderPatchParamsTest { .scopeDelimiter( AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2 ) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequestTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequestTest.kt index c551713..b07bc1d 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequestTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/admin/authproviders/AuthProviderUpdateRequestTest.kt @@ -86,6 +86,46 @@ internal class AuthProviderUpdateRequestTest { .build() ) .scopeDelimiter(AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") @@ -227,6 +267,44 @@ internal class AuthProviderUpdateRequestTest { .build() ) .scopeDelimiter(AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.Params + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") @@ -370,6 +448,46 @@ internal class AuthProviderUpdateRequestTest { .build() ) .scopeDelimiter(AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest.builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/ToolListParamsTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/ToolListParamsTest.kt index 2c07652..9f3f267 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/ToolListParamsTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/ToolListParamsTest.kt @@ -11,6 +11,7 @@ internal class ToolListParamsTest { @Test fun create() { ToolListParams.builder() + .filter("filter") .includeAllVersions(true) .addIncludeFormat(ToolListParams.IncludeFormat.ARCADE) .limit(0L) @@ -24,6 +25,7 @@ internal class ToolListParamsTest { fun queryParams() { val params = ToolListParams.builder() + .filter("filter") .includeAllVersions(true) .addIncludeFormat(ToolListParams.IncludeFormat.ARCADE) .limit(0L) @@ -37,6 +39,7 @@ internal class ToolListParamsTest { assertThat(queryParams) .isEqualTo( QueryParams.builder() + .put("filter", "filter") .put("include_all_versions", "true") .put("include_format", listOf("arcade").joinToString(",")) .put("limit", "0") diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/formatted/FormattedListParamsTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/formatted/FormattedListParamsTest.kt index 48d2dad..06a3344 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/formatted/FormattedListParamsTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/tools/formatted/FormattedListParamsTest.kt @@ -11,6 +11,7 @@ internal class FormattedListParamsTest { @Test fun create() { FormattedListParams.builder() + .filter("filter") .format("format") .includeAllVersions(true) .limit(0L) @@ -24,6 +25,7 @@ internal class FormattedListParamsTest { fun queryParams() { val params = FormattedListParams.builder() + .filter("filter") .format("format") .includeAllVersions(true) .limit(0L) @@ -37,6 +39,7 @@ internal class FormattedListParamsTest { assertThat(queryParams) .isEqualTo( QueryParams.builder() + .put("filter", "filter") .put("format", "format") .put("include_all_versions", "true") .put("limit", "0") diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerListPageResponseTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerListPageResponseTest.kt index bfe4dee..36db9bd 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerListPageResponseTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerListPageResponseTest.kt @@ -43,6 +43,7 @@ internal class WorkerListPageResponseTest { .managed(true) .mcp( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -68,6 +69,7 @@ internal class WorkerListPageResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() @@ -142,6 +144,7 @@ internal class WorkerListPageResponseTest { .managed(true) .mcp( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -167,6 +170,7 @@ internal class WorkerListPageResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() @@ -244,6 +248,7 @@ internal class WorkerListPageResponseTest { .managed(true) .mcp( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -269,6 +274,7 @@ internal class WorkerListPageResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerResponseTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerResponseTest.kt index c280d01..bf49033 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerResponseTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/models/workers/WorkerResponseTest.kt @@ -40,6 +40,7 @@ internal class WorkerResponseTest { .managed(true) .mcp( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -64,6 +65,7 @@ internal class WorkerResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() @@ -131,6 +133,7 @@ internal class WorkerResponseTest { assertThat(workerResponse.mcp()) .contains( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -153,6 +156,7 @@ internal class WorkerResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() @@ -223,6 +227,7 @@ internal class WorkerResponseTest { .managed(true) .mcp( WorkerResponse.Mcp.builder() + .externalId("external_id") .headers( WorkerResponse.Mcp.Headers.builder() .putAdditionalProperty("foo", JsonValue.from("string")) @@ -247,6 +252,7 @@ internal class WorkerResponseTest { .addSupportedScope("string") .build() ) + .redirectUri("redirect_uri") .retry(0L) .secrets( WorkerResponse.Mcp.Secrets.builder() diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/services/async/admin/AuthProviderServiceAsyncTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/services/async/admin/AuthProviderServiceAsyncTest.kt index 04a3bb6..6c53381 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/services/async/admin/AuthProviderServiceAsyncTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/services/async/admin/AuthProviderServiceAsyncTest.kt @@ -373,6 +373,58 @@ internal class AuthProviderServiceAsyncTest { .scopeDelimiter( AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2 ) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") diff --git a/arcade-java-core/src/test/kotlin/dev/arcade/services/blocking/admin/AuthProviderServiceTest.kt b/arcade-java-core/src/test/kotlin/dev/arcade/services/blocking/admin/AuthProviderServiceTest.kt index dcfea65..aa06f1e 100644 --- a/arcade-java-core/src/test/kotlin/dev/arcade/services/blocking/admin/AuthProviderServiceTest.kt +++ b/arcade-java-core/src/test/kotlin/dev/arcade/services/blocking/admin/AuthProviderServiceTest.kt @@ -369,6 +369,58 @@ internal class AuthProviderServiceTest { .scopeDelimiter( AuthProviderUpdateRequest.Oauth2.ScopeDelimiter.Unknown2 ) + .tokenIntrospectionRequest( + AuthProviderUpdateRequest.Oauth2.TokenIntrospectionRequest + .builder() + .authHeaderValueFormat("auth_header_value_format") + .authMethod("auth_method") + .endpoint("endpoint") + .method("method") + .params( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Params + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .requestContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .RequestContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseContentType( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseContentType + .APPLICATION_X_WWW_FORM_URLENCODED + ) + .responseMap( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .ResponseMap + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .triggers( + AuthProviderUpdateRequest.Oauth2 + .TokenIntrospectionRequest + .Triggers + .builder() + .onTokenGrant(true) + .onTokenRefresh(true) + .build() + ) + .build() + ) .tokenRequest( AuthProviderUpdateRequest.Oauth2.TokenRequest.builder() .authHeaderValueFormat("auth_header_value_format") diff --git a/build.gradle.kts b/build.gradle.kts index 2348249..aec4e08 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ repositories { allprojects { group = "dev.arcade" - version = "0.1.0-alpha.5" // x-release-please-version + version = "0.1.0-alpha.6" // x-release-please-version } subprojects { @@ -22,7 +22,6 @@ subprojects { group = "Verification" description = "Verifies all source files are formatted." } - apply(plugin = "org.jetbrains.dokka") } subprojects { diff --git a/buildSrc/src/main/kotlin/arcade.kotlin.gradle.kts b/buildSrc/src/main/kotlin/arcade.kotlin.gradle.kts index 08c21f3..1fa9c32 100644 --- a/buildSrc/src/main/kotlin/arcade.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/arcade.kotlin.gradle.kts @@ -40,7 +40,7 @@ tasks.withType().configureEach { val ktfmt by configurations.creating dependencies { - ktfmt("com.facebook:ktfmt:0.56") + ktfmt("com.facebook:ktfmt:0.61") } fun registerKtfmt( diff --git a/scripts/fast-format b/scripts/fast-format index 1b3bc47..35a1dee 100755 --- a/scripts/fast-format +++ b/scripts/fast-format @@ -24,8 +24,8 @@ if [ ! -f "$FILE_LIST" ]; then exit 1 fi -if ! command -v ktfmt-fast-format &> /dev/null; then - echo "Error: ktfmt-fast-format not found" +if ! command -v ktfmt &> /dev/null; then + echo "Error: ktfmt not found" exit 1 fi @@ -36,7 +36,7 @@ echo "==> Done looking for Kotlin files" if [[ -n "$kt_files" ]]; then echo "==> will format Kotlin files" - echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt-fast-format --kotlinlang-style "$@" + echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt --kotlinlang-style "$@" else echo "No Kotlin files to format -- expected outcome during incremental formatting" fi diff --git a/scripts/mock b/scripts/mock index bcf3b39..feebe5e 100755 --- a/scripts/mock +++ b/scripts/mock @@ -19,34 +19,34 @@ fi echo "==> Starting mock server with URL ${URL}" -# Run prism mock on the given spec +# Run steady mock on the given spec if [ "$1" == "--daemon" ]; then # Pre-install the package so the download doesn't eat into the startup timeout - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version + npm exec --package=@stdy/cli@0.22.1 -- steady --version - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & - # Wait for server to come online (max 30s) + # Wait for server to come online via health endpoint (max 30s) echo -n "Waiting for server" attempts=0 - while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do + while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do + if ! kill -0 $! 2>/dev/null; then + echo + cat .stdy.log + exit 1 + fi attempts=$((attempts + 1)) if [ "$attempts" -ge 300 ]; then echo - echo "Timed out waiting for Prism server to start" - cat .prism.log + echo "Timed out waiting for Steady server to start" + cat .stdy.log exit 1 fi echo -n "." sleep 0.1 done - if grep -q "✖ fatal" ".prism.log"; then - cat .prism.log - exit 1 - fi - echo else - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" + npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" fi diff --git a/scripts/test b/scripts/test index 047bc1d..7d7f08e 100755 --- a/scripts/test +++ b/scripts/test @@ -9,8 +9,8 @@ GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' # No Color -function prism_is_running() { - curl --silent "http://localhost:4010" >/dev/null 2>&1 +function steady_is_running() { + curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1 } kill_server_on_port() { @@ -25,7 +25,7 @@ function is_overriding_api_base_url() { [ -n "$TEST_API_BASE_URL" ] } -if ! is_overriding_api_base_url && ! prism_is_running ; then +if ! is_overriding_api_base_url && ! steady_is_running ; then # When we exit this script, make sure to kill the background mock server process trap 'kill_server_on_port 4010' EXIT @@ -36,19 +36,19 @@ fi if is_overriding_api_base_url ; then echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}" echo -elif ! prism_is_running ; then - echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server" +elif ! steady_is_running ; then + echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server" echo -e "running against your OpenAPI spec." echo echo -e "To run the server, pass in the path or url of your OpenAPI" - echo -e "spec to the prism command:" + echo -e "spec to the steady command:" echo - echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}" + echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}" echo exit 1 else - echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}" + echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}" echo fi