sdkloom 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
// <Name>Client: builder, one method per operation, a raw() view and one <Operation>Params class per operation with non-path parameters.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { pagedItems, } from "@sdkloom/ir";
|
|
5
|
+
import { javaName } from "@sdkloom/transpile";
|
|
6
|
+
import { deprecatedTags, exceptionName, fileStart, MODEL_IMPORTS } from "./emit-models.ts";
|
|
7
|
+
import { camel, decoder, encoder, javadoc, javaType, pascal, str } from "./names.ts";
|
|
8
|
+
|
|
9
|
+
export function clientName(ir ) {
|
|
10
|
+
return `${ir.name}Client`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const BUILDER_OPTIONS = ["server", "baseUrl", "transport", "timeoutMs", "middleware", "onEvent", "clock", "proxy", "sslContext", "build"];
|
|
14
|
+
|
|
15
|
+
export function configFields(ir ) {
|
|
16
|
+
const fields = new Map ();
|
|
17
|
+
for (const middleware of ir.middlewares) {
|
|
18
|
+
for (const item of middleware.config) {
|
|
19
|
+
if (BUILDER_OPTIONS.includes(camel(item.name))) throw new Error(`config field ${item.name} of middleware ${middleware.name} collides with a client option`);
|
|
20
|
+
if (!fields.has(item.name)) fields.set(item.name, item);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return [...fields.values()];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function kind(node ) {
|
|
29
|
+
if (node === undefined) return undefined;
|
|
30
|
+
return node.kind === "primitive" && (node.name === "bytes" || node.name === "stream" || node.name === "multipart") ? node.name : "json";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function resultType(operation ) {
|
|
34
|
+
if (operation.events !== undefined) return `EventStream<${javaType(operation.events, `operations.${operation.name}.events`)}>`;
|
|
35
|
+
return operation.returns === undefined ? "Void" : javaType(operation.returns, `operations.${operation.name}.returns`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** An event stream whose data stays text: no decoder, the data is a String. */
|
|
39
|
+
function textEvents(node ) {
|
|
40
|
+
return node.kind === "primitive" && node.name === "string";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function namedParams(operation ) {
|
|
44
|
+
return operation.params.filter((param) => param.in !== "path");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function paramsClass(operation ) {
|
|
48
|
+
return `${pascal(operation.name)}Params`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function specName(operation ) {
|
|
52
|
+
return camel(operation.name).replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/_$/, "").toUpperCase();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/** Client methods besides the operations; an operation with one of these names would not compile. */
|
|
61
|
+
const CLIENT_METHODS = ["raw", "builder", "equals", "hashCode", "toString", "getClass", "wait", "notify", "notifyAll"];
|
|
62
|
+
|
|
63
|
+
/** Fails generation for operation and parameter names that would not compile. */
|
|
64
|
+
export function checkOperationNames(ir ) {
|
|
65
|
+
for (const operation of ir.operations) {
|
|
66
|
+
const name = camel(operation.name);
|
|
67
|
+
if (CLIENT_METHODS.includes(name)) throw new Error(`operation ${name} collides with ${clientName(ir)}.${name}(); rename the operation`);
|
|
68
|
+
for (const param of operation.params.filter((candidate) => candidate.in === "path")) {
|
|
69
|
+
const java = camel(param.name);
|
|
70
|
+
if (java === "body" || java === "params") throw new Error(`operations.${operation.name}: path parameter ${param.name} collides with the ${java} argument; rename it`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Path parameters, then the body, then the optional Params object. */
|
|
76
|
+
function signature(operation , withParams ) {
|
|
77
|
+
const path = operation.params.filter((param) => param.in === "path");
|
|
78
|
+
const params = [
|
|
79
|
+
...path.map((param) => `${javaType(param.type, `operations.${operation.name}.params.${param.name}`)} ${camel(param.name)}`),
|
|
80
|
+
...(operation.body === undefined ? [] : [`${javaType(operation.body, `operations.${operation.name}.body`)} body`]),
|
|
81
|
+
...(withParams ? [`${paramsClass(operation)} params`] : []),
|
|
82
|
+
];
|
|
83
|
+
const args = [...path.map((param) => camel(param.name)), ...(operation.body === undefined ? [] : ["body"])];
|
|
84
|
+
return { params: params.join(", "), args: args.join(", ") };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function hasRequiredNamed(operation ) {
|
|
88
|
+
return namedParams(operation).some((param) => !param.optional);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function emitSpec(writer , ir , operation ) {
|
|
92
|
+
const result = operation.events === undefined ? kind(operation.returns) : "events";
|
|
93
|
+
const chain = [
|
|
94
|
+
`OperationSpec.builder(${str(operation.name)}, ${str(operation.method)}, ${str(operation.path)})`,
|
|
95
|
+
...operation.params.map((param) => `.param(${str(param.name)}, ${str(param.in)})`),
|
|
96
|
+
...(operation.body === undefined ? [] : [`.body(${str(kind(operation.body) ?? "json")})`]),
|
|
97
|
+
...(result === undefined ? [] : [`.result(${str(result)})`]),
|
|
98
|
+
...(result === "json" && operation.returns !== undefined ? [`.decode(${decoder(ir, operation.returns, `operations.${operation.name}.returns`)})`] : []),
|
|
99
|
+
...(operation.events !== undefined && !textEvents(operation.events) ? [`.decode(${decoder(ir, operation.events, `operations.${operation.name}.events`)})`] : []),
|
|
100
|
+
...operation.errors.map((error) => `.error(${error.status}, ${exceptionName(error.name)}::new)`),
|
|
101
|
+
...operation.use.map((name) => `.use(${str(name)})`),
|
|
102
|
+
...(operation.since === undefined ? [] : [`.since(${str(operation.since)})`]),
|
|
103
|
+
".build();",
|
|
104
|
+
];
|
|
105
|
+
writer.line(`private static final OperationSpec ${specName(operation)} = ${chain[0] ?? ""}`).indent((body) => chain.slice(1).forEach((part) => body.line(part)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function operationDoc(operation ) {
|
|
109
|
+
return [
|
|
110
|
+
operation.doc ?? operation.name,
|
|
111
|
+
"",
|
|
112
|
+
`HTTP: ${operation.method} ${operation.path}`,
|
|
113
|
+
...(operation.since === undefined ? [] : [`Since API version ${operation.since}.`]),
|
|
114
|
+
...(operation.events === undefined ? [] : ["Server-sent events, read as they arrive: for (ServerSentEvent<...> event : client.op(...)). The request is sent when iteration starts; close the stream to stop early."]),
|
|
115
|
+
...(operation.stability === "stable" ? [] : [`Stability: ${operation.stability}`]),
|
|
116
|
+
...operation.errors.map((error) => `Throws ${exceptionName(error.name)} for HTTP ${error.status}.`),
|
|
117
|
+
"Throws ApiException for any other non-2xx response and TransportException when no response arrives.",
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function emitRawMethods(body , ir , operation ) {
|
|
122
|
+
const result = `RawResult<${resultType(operation)}>`;
|
|
123
|
+
const named = namedParams(operation);
|
|
124
|
+
const tags = deprecatedTags(operation.deprecated);
|
|
125
|
+
const annotate = () => {
|
|
126
|
+
if (tags.length > 0) body.line("@Deprecated");
|
|
127
|
+
};
|
|
128
|
+
if (named.length > 0 && !hasRequiredNamed(operation)) {
|
|
129
|
+
const short = signature(operation, false);
|
|
130
|
+
body.line();
|
|
131
|
+
javadoc(body, [`${operation.name} with the HTTP response.`], tags);
|
|
132
|
+
annotate();
|
|
133
|
+
body.line(`public ${result} ${camel(operation.name)}(${short.params}) {`).indent((fn) =>
|
|
134
|
+
fn.line(`return ${camel(operation.name)}(${[short.args, `${paramsClass(operation)}.builder().build()`].filter((part) => part !== "").join(", ")});`),
|
|
135
|
+
).line("}");
|
|
136
|
+
}
|
|
137
|
+
const full = signature(operation, named.length > 0);
|
|
138
|
+
body.line();
|
|
139
|
+
javadoc(body, [`${operation.name} with the HTTP response.`], tags);
|
|
140
|
+
annotate();
|
|
141
|
+
const link = operation.paginate?.kind === "link";
|
|
142
|
+
if (link) {
|
|
143
|
+
// The iterator calls the operation again at the URL the Link header named.
|
|
144
|
+
body.line(`public ${result} ${camel(operation.name)}(${full.params}) {`).indent((fn) => fn.line(`return ${camel(operation.name)}At(${[full.args, named.length > 0 ? "params" : "", "null"].filter((part) => part !== "").join(", ")});`)).line("}");
|
|
145
|
+
body.line();
|
|
146
|
+
javadoc(body, [`${operation.name} at url instead of the URL its path and query make (the next page a Link header named), with the HTTP response.`], tags);
|
|
147
|
+
annotate();
|
|
148
|
+
}
|
|
149
|
+
const atParams = link ? [full.params, "String url"].filter((part) => part !== "").join(", ") : full.params;
|
|
150
|
+
body.line(`public ${result} ${camel(operation.name)}${link ? "At" : ""}(${atParams}) {`).indent((fn) => {
|
|
151
|
+
fn.line("Map<String, Object> args$ = new HashMap<>();");
|
|
152
|
+
operation.params.filter((param) => param.in === "path").forEach((param) => fn.line(`args$.put(${str(param.name)}, ${camel(param.name)});`));
|
|
153
|
+
named.forEach((param) => fn.line(`args$.put(${str(param.name)}, params.${camel(param.name)}());`));
|
|
154
|
+
if (operation.body !== undefined) {
|
|
155
|
+
const encoded = kind(operation.body) === "json" ? encoder(ir, operation.body, "body") : "body";
|
|
156
|
+
fn.line(`args$.put("body", body == null ? null : ${encoded});`);
|
|
157
|
+
}
|
|
158
|
+
fn.line(`return ${clientName(ir)}.this.runtime.call(${specName(operation)}, args$${link ? ", url" : ""});`);
|
|
159
|
+
});
|
|
160
|
+
body.line("}");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function emitMethods(body , operation ) {
|
|
164
|
+
const type = resultType(operation);
|
|
165
|
+
const returns = type === "Void" ? "void" : type;
|
|
166
|
+
const named = namedParams(operation);
|
|
167
|
+
const tags = deprecatedTags(operation.deprecated);
|
|
168
|
+
const variants = named.length > 0 && !hasRequiredNamed(operation) ? [false, true] : [named.length > 0];
|
|
169
|
+
for (const withParams of variants) {
|
|
170
|
+
const sig = signature(operation, withParams);
|
|
171
|
+
const call = `raw.${camel(operation.name)}(${[sig.args, withParams ? "params" : ""].filter((part) => part !== "").join(", ")})`;
|
|
172
|
+
body.line();
|
|
173
|
+
javadoc(body, operationDoc(operation), tags);
|
|
174
|
+
if (tags.length > 0) body.line("@Deprecated");
|
|
175
|
+
const read = operation.events !== undefined ? `return EventStream.lazy(() -> ${call}.data());` : returns === "void" ? `${call};` : `return ${call}.data();`;
|
|
176
|
+
body.line(`public ${returns} ${camel(operation.name)}(${sig.params}) {`).indent((fn) => fn.line(read)).line("}");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** <name>AndWait: starts the work, then polls until it is done (kit block lro.wait). */
|
|
181
|
+
function emitWait(body , operation , wait ) {
|
|
182
|
+
const type = resultType(operation);
|
|
183
|
+
const named = namedParams(operation);
|
|
184
|
+
const variants = named.length > 0 && !hasRequiredNamed(operation) ? [false, true] : [named.length > 0];
|
|
185
|
+
for (const withParams of variants) {
|
|
186
|
+
const sig = signature(operation, withParams);
|
|
187
|
+
const args = [sig.args, withParams ? "params" : ""].filter((part) => part !== "").join(", ");
|
|
188
|
+
body.line();
|
|
189
|
+
javadoc(body, [`${operation.name}, then ${wait.poll} every ${wait.intervalMs} ms until ${wait.field} is ${wait.done.join(" or ")}; the finished result.`], [`@throws Waits.WaitTimeoutException when the work is not done within ${wait.timeoutMs} ms`]);
|
|
190
|
+
body.line(`public ${type} ${camel(operation.name)}AndWait(${sig.params}) {`).indent((fn) => {
|
|
191
|
+
fn.line(`${type} first = ${camel(operation.name)}(${args});`);
|
|
192
|
+
fn.line(`return Waits.until(first, (${type} current) -> ${camel(wait.poll)}(current.${camel(wait.from)}()), (${type} current) -> java.util.Arrays.asList(${wait.done.map(str).join(", ")}).contains(current.${camel(wait.field)}()), runtime.clock(), ${wait.intervalMs}L, ${wait.timeoutMs}L);`);
|
|
193
|
+
});
|
|
194
|
+
body.line("}");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** <name>All: every item of every page, fetched as the caller iterates (kit block pagination.iterate). */
|
|
199
|
+
function emitIterator(body , ir , operation , paginate ) {
|
|
200
|
+
const { item: itemNode, field: itemsField } = pagedItems(ir, operation);
|
|
201
|
+
const returns = operation.returns;
|
|
202
|
+
const page = returns?.kind === "ref" ? ir.types.find((named) => named.name === returns.name) : undefined;
|
|
203
|
+
const fields = page?.type.kind === "object" ? page.type.fields : [];
|
|
204
|
+
const item = javaType(itemNode, `operations.${operation.name}.paginate`);
|
|
205
|
+
const pageType = returns === undefined ? "Void" : javaType(returns, `operations.${operation.name}.returns`);
|
|
206
|
+
const params = paramsClass(operation);
|
|
207
|
+
const name = `${camel(operation.name)}All`;
|
|
208
|
+
const full = signature(operation, namedParams(operation).length > 0);
|
|
209
|
+
const call = (args ) => `${camel(operation.name)}(${[full.args, args].filter((part) => part !== "").join(", ")})`;
|
|
210
|
+
const next = () => {
|
|
211
|
+
if (paginate.kind === "link") return "";
|
|
212
|
+
if (paginate.kind === "cursor") {
|
|
213
|
+
const nextField = fields.find((entry) => entry.name === paginate.next);
|
|
214
|
+
const read = nextField?.optional === true ? `page.${camel(paginate.next)}().orElse(null)` : `page.${camel(paginate.next)}()`;
|
|
215
|
+
return `(${params} current, ${pageType} page, List<${item}> items) -> {\n String cursor = ${read};\n return cursor == null || cursor.isEmpty() ? null : current.toBuilder().${camel(paginate.param)}(cursor).build();\n}`;
|
|
216
|
+
}
|
|
217
|
+
const limit = paginate.limit === undefined ? "" : ` || (current.${camel(paginate.limit)}() != null && items.size() < current.${camel(paginate.limit)}())`;
|
|
218
|
+
const offset = `current.${camel(paginate.param)}()`;
|
|
219
|
+
return `(${params} current, ${pageType} page, List<${item}> items) -> items.isEmpty()${limit} ? null : current.toBuilder().${camel(paginate.param)}((${offset} == null ? 0L : ${offset}) + items.size()).build()`;
|
|
220
|
+
};
|
|
221
|
+
const doc = [`Every item of every ${operation.name} page, fetched as you iterate: for (${item} item : client.${name}(...)) { ... }.`];
|
|
222
|
+
if (namedParams(operation).length > 0 && !hasRequiredNamed(operation)) {
|
|
223
|
+
const short = signature(operation, false);
|
|
224
|
+
body.line();
|
|
225
|
+
javadoc(body, doc);
|
|
226
|
+
body.line(`public Iterable<${item}> ${name}(${short.params}) {`).indent((fn) => fn.line(`return ${name}(${[short.args, `${params}.builder().build()`].filter((part) => part !== "").join(", ")});`)).line("}");
|
|
227
|
+
}
|
|
228
|
+
body.line();
|
|
229
|
+
javadoc(body, doc);
|
|
230
|
+
body.line(`public Iterable<${item}> ${name}(${full.params}) {`).indent((fn) => {
|
|
231
|
+
if (paginate.kind === "link") {
|
|
232
|
+
// The Link header names the next page: the same operation is called at that URL.
|
|
233
|
+
const raw = `RawResult<${pageType}>`;
|
|
234
|
+
const at = (url ) => `raw.${camel(operation.name)}At(${[full.args, namedParams(operation).length > 0 ? "params" : "", url].filter((part) => part !== "").join(", ")})`;
|
|
235
|
+
fn.line("return Pages.iterate(").indent((args) => {
|
|
236
|
+
args.line("java.util.Optional.<String>empty(),");
|
|
237
|
+
args.line(`(java.util.Optional<String> url) -> ${at("url.orElse(null)")},`);
|
|
238
|
+
args.line(`(${raw} page) -> page.data()${itemsField === undefined ? "" : `.${camel(itemsField)}()`},`);
|
|
239
|
+
args.line(`(java.util.Optional<String> url, ${raw} page, List<${item}> items) -> {`).indent((inner) => {
|
|
240
|
+
inner.line('String next = Links.next(page.response().header("link"));');
|
|
241
|
+
inner.line("return next == null ? null : java.util.Optional.of(next);");
|
|
242
|
+
});
|
|
243
|
+
args.line("});");
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
fn.line("return Pages.iterate(").indent((args) => {
|
|
248
|
+
args.line("params,");
|
|
249
|
+
args.line(`(${params} current) -> ${call("current")},`);
|
|
250
|
+
args.line(`(${pageType} page) -> page.${camel(itemsField ?? "")}(),`);
|
|
251
|
+
next()
|
|
252
|
+
.split("\n")
|
|
253
|
+
.forEach((line, index, all) => args.line(index === all.length - 1 ? `${line});` : line));
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
body.line("}");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function configType(item ) {
|
|
260
|
+
return javaType(item.type, `config.${item.name}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function entryFor(ir , name , native ) {
|
|
264
|
+
const middleware = ir.middlewares.find((candidate) => candidate.name === name);
|
|
265
|
+
if (middleware === undefined) throw new Error(`unknown middleware ${name}`);
|
|
266
|
+
const pairs = middleware.config.flatMap((item) => [str(item.name), `builder.${camel(item.name)}`]);
|
|
267
|
+
return `MiddlewareEntry.of(${str(name)}, ${native.has(name) ? "Middlewares" : "TranspiledMiddlewares"}::${javaName(name)}, config$(${pairs.join(", ")}))`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function emitBuilder(writer , ir , client ) {
|
|
271
|
+
const config = configFields(ir);
|
|
272
|
+
javadoc(writer, [`Configures a ${client}.`]);
|
|
273
|
+
writer.line("public static final class Builder {").indent((body) => {
|
|
274
|
+
config.forEach((item) => body.line(`private ${configType(item)} ${camel(item.name)};`));
|
|
275
|
+
body.line("private String server = DEFAULT_SERVER;");
|
|
276
|
+
body.line("private String baseUrl;").line("private Transport transport;").line("private Long timeoutMs = DEFAULT_TIMEOUT_MS;");
|
|
277
|
+
body.line("private final List<MiddlewareEntry> middleware = new ArrayList<>();").line("private final List<EventListener> listeners = new ArrayList<>();");
|
|
278
|
+
body.line("private Clock clock;").line("private ProxySelector proxy;").line("private SSLContext sslContext;");
|
|
279
|
+
const versions = ir.apiVersions;
|
|
280
|
+
if (versions !== undefined) {
|
|
281
|
+
if (config.some((item) => camel(item.name) === "apiVersion")) throw new Error("a middleware config field apiVersion collides with the apiVersion client option of apiVersions");
|
|
282
|
+
body.line(`private String apiVersion = ${str(versions.values.at(-1) ?? "")};`);
|
|
283
|
+
}
|
|
284
|
+
body.line();
|
|
285
|
+
body.line("private Builder() {").line("}");
|
|
286
|
+
const setter = (name , type , doc , assign ) => {
|
|
287
|
+
body.line();
|
|
288
|
+
javadoc(body, [doc]);
|
|
289
|
+
body.line(`public Builder ${name}(${type} value) {`).indent((fn) => fn.line(assign).line("return this;")).line("}");
|
|
290
|
+
};
|
|
291
|
+
config.forEach((item) => setter(camel(item.name), configType(item), `${item.doc ?? item.name}${item.optional ? " Optional." : " Required."}`, `this.${camel(item.name)} = value;`));
|
|
292
|
+
setter("server", "String", `A named server: ${ir.servers.map((server) => server.name).join(", ")}. Defaults to ${ir.defaultServer}.`, "this.server = value;");
|
|
293
|
+
setter("baseUrl", "String", "A base URL that replaces the server, e.g. for a proxy or a local mock.", "this.baseUrl = value;");
|
|
294
|
+
setter("transport", "Transport", "Sends the requests; defaults to java.net.http.", "this.transport = value;");
|
|
295
|
+
setter("timeoutMs", "Long", "Timeout of each request in milliseconds; null for none. Defaults to 60000.", "this.timeoutMs = value;");
|
|
296
|
+
setter("middleware", "MiddlewareEntry", "Adds your own middleware; it runs after the SDK's own middleware.", "this.middleware.add(value);");
|
|
297
|
+
setter("onEvent", "EventListener", "Adds a listener for events such as retries; a listener that throws never breaks a call.", "this.listeners.add(value);");
|
|
298
|
+
setter("clock", "Clock", "The clock middleware uses to measure and wait; defaults to the system clock.", "this.clock = value;");
|
|
299
|
+
setter("proxy", "ProxySelector", "Routes requests through a proxy (default transport only).", "this.proxy = value;");
|
|
300
|
+
setter("sslContext", "SSLContext", "The TLS context, e.g. for a private CA (default transport only).", "this.sslContext = value;");
|
|
301
|
+
if (versions !== undefined) setter("apiVersion", "String", `The API version to use, sent as ${versions.header}: ${versions.values.join(", ")}. Defaults to ${versions.values.at(-1) ?? ""}, the newest.`, "this.apiVersion = value;");
|
|
302
|
+
body.line();
|
|
303
|
+
javadoc(body, [`Creates the client; throws IllegalStateException when required configuration is missing.`]);
|
|
304
|
+
body.line(`public ${client} build() {`).indent((fn) => {
|
|
305
|
+
config
|
|
306
|
+
.filter((item) => !item.optional)
|
|
307
|
+
.forEach((item) => fn.line(`if (${camel(item.name)} == null) {`).indent((b) => b.line(`throw new IllegalStateException(${str(`${item.name} is required`)});`)).line("}"));
|
|
308
|
+
fn.line("if (baseUrl == null && !SERVERS.containsKey(server)) {").indent((b) =>
|
|
309
|
+
b.line(`throw new IllegalStateException("unknown server " + server + "; use one of " + SERVERS.keySet());`),
|
|
310
|
+
).line("}");
|
|
311
|
+
fn.line(`return new ${client}(this);`);
|
|
312
|
+
});
|
|
313
|
+
body.line("}");
|
|
314
|
+
});
|
|
315
|
+
writer.line("}");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** transport: the runtime class used when the builder gets none (JdkTransport, or UrlConnectionTransport for Java 8). */
|
|
319
|
+
export function emitClient(ir , header , pkg , native , sdk , transport ) {
|
|
320
|
+
checkOperationNames(ir);
|
|
321
|
+
const client = clientName(ir);
|
|
322
|
+
const registry = [...new Set(ir.operations.flatMap((operation) => operation.use))].sort();
|
|
323
|
+
const writer = fileStart(header, pkg, [
|
|
324
|
+
...MODEL_IMPORTS,
|
|
325
|
+
"java.io.InputStream",
|
|
326
|
+
"java.net.ProxySelector",
|
|
327
|
+
"java.util.HashMap",
|
|
328
|
+
"javax.net.ssl.SSLContext",
|
|
329
|
+
"java.util.Arrays",
|
|
330
|
+
...["Clock", "EventListener", transport, "MiddlewareEntry", "OperationSpec", "Pages", "Links", "Waits", "MultipartForm", "RawResult", "EventStream", "SdkInfo", "Transport", "ClientRuntime", "Decode"].map((name) => `${pkg}.runtime.${name}`),
|
|
331
|
+
]);
|
|
332
|
+
javadoc(writer, [ir.doc ?? ir.name, "", "Thread-safe: build one client and share it.", `Create one with ${client}.builder()...build().`]);
|
|
333
|
+
writer.line(`public final class ${client} {`).indent((body) => {
|
|
334
|
+
javadoc(body, ["Server names and their base URLs."]);
|
|
335
|
+
body.line("public static final Map<String, String> SERVERS = servers$();");
|
|
336
|
+
javadoc(body, ["The server used when none is chosen."]);
|
|
337
|
+
body.line(`public static final String DEFAULT_SERVER = ${str(ir.defaultServer)};`);
|
|
338
|
+
body.line("private static final long DEFAULT_TIMEOUT_MS = 60000L;").line();
|
|
339
|
+
ir.operations.forEach((operation) => emitSpec(body, ir, operation));
|
|
340
|
+
body.line().line("private final ClientRuntime runtime;").line("private final Raw raw = new Raw();").line();
|
|
341
|
+
|
|
342
|
+
body.line(`private ${client}(Builder builder) {`).indent((fn) => {
|
|
343
|
+
fn.line("Clock clock = builder.clock == null ? Clock.system() : builder.clock;");
|
|
344
|
+
fn.line(`Transport transport = builder.transport == null ? new ${transport}(builder.proxy, builder.sslContext) : builder.transport;`);
|
|
345
|
+
fn.line(`List<MiddlewareEntry> sdk = Arrays.asList(${ir.use.map((name) => entryFor(ir, name, native)).join(", ")});`);
|
|
346
|
+
fn.line("Map<String, MiddlewareEntry> registry = new HashMap<>();");
|
|
347
|
+
registry.forEach((name) => fn.line(`registry.put(${str(name)}, ${entryFor(ir, name, native)});`));
|
|
348
|
+
fn.line("String baseUrl = builder.baseUrl == null ? SERVERS.get(builder.server) : builder.baseUrl;");
|
|
349
|
+
const versions = ir.apiVersions;
|
|
350
|
+
const version = versions === undefined ? "" : `, new ClientRuntime.ApiVersion(${str(versions.header)}, builder.apiVersion, Arrays.asList(${versions.values.map(str).join(", ")}))`;
|
|
351
|
+
fn.line(`this.runtime = new ClientRuntime(baseUrl, transport, clock, sdk, registry, builder.middleware, builder.listeners, builder.timeoutMs, new SdkInfo(${str(sdk.name)}, ${str(sdk.version)}, "java")${version});`);
|
|
352
|
+
});
|
|
353
|
+
body.line("}");
|
|
354
|
+
body.line();
|
|
355
|
+
javadoc(body, [`A new builder for ${client}.`]);
|
|
356
|
+
body.line("public static Builder builder() {").indent((fn) => fn.line("return new Builder();")).line("}");
|
|
357
|
+
body.line();
|
|
358
|
+
javadoc(body, ["The same operations, returning RawResult so the HTTP status and headers are available."]);
|
|
359
|
+
body.line("public Raw raw() {").indent((fn) => fn.line("return raw;")).line("}");
|
|
360
|
+
ir.operations.forEach((operation) => {
|
|
361
|
+
emitMethods(body, operation);
|
|
362
|
+
if (operation.paginate !== undefined) emitIterator(body, ir, operation, operation.paginate);
|
|
363
|
+
if (operation.wait !== undefined) emitWait(body, operation, operation.wait);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
body.line();
|
|
367
|
+
body.line("private static Map<String, String> servers$() {").indent((fn) => {
|
|
368
|
+
fn.line("Map<String, String> servers = new LinkedHashMap<>();");
|
|
369
|
+
ir.servers.forEach((server) => fn.line(`servers.put(${str(server.name)}, ${str(server.url)});`));
|
|
370
|
+
fn.line("return Collections.unmodifiableMap(servers);");
|
|
371
|
+
});
|
|
372
|
+
body.line("}");
|
|
373
|
+
body.line().line("private static Map<String, Object> config$(Object... pairs) {").indent((fn) => {
|
|
374
|
+
fn.line("Map<String, Object> config = new LinkedHashMap<>();");
|
|
375
|
+
fn.line("for (int i = 0; i < pairs.length; i += 2) {").indent((loop) => loop.line("config.put((String) pairs[i], pairs[i + 1]);")).line("}");
|
|
376
|
+
fn.line("return config;");
|
|
377
|
+
});
|
|
378
|
+
body.line("}");
|
|
379
|
+
|
|
380
|
+
body.line();
|
|
381
|
+
javadoc(body, ["Operations that return the decoded result together with the HTTP response."]);
|
|
382
|
+
body.line("public final class Raw {").indent((rawBody) => {
|
|
383
|
+
rawBody.line("private Raw() {").line("}");
|
|
384
|
+
ir.operations.forEach((operation) => emitRawMethods(rawBody, ir, operation));
|
|
385
|
+
});
|
|
386
|
+
body.line("}");
|
|
387
|
+
body.line();
|
|
388
|
+
emitBuilder(body, ir, client);
|
|
389
|
+
});
|
|
390
|
+
return writer.line("}").toString();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** <Operation>Params: the query and header parameters of one operation. */
|
|
394
|
+
export function emitParams(operation , header , pkg ) {
|
|
395
|
+
const name = paramsClass(operation);
|
|
396
|
+
const params = namedParams(operation);
|
|
397
|
+
const writer = fileStart(header, pkg, MODEL_IMPORTS);
|
|
398
|
+
javadoc(writer, [`Query and header parameters of ${operation.name}.`]);
|
|
399
|
+
writer.line(`public final class ${name} {`).indent((body) => {
|
|
400
|
+
params.forEach((param) => body.line(`private final ${javaType(param.type, `operations.${operation.name}.params.${param.name}`)} ${camel(param.name)};`));
|
|
401
|
+
body.line().line(`private ${name}(Builder builder) {`).indent((fn) => {
|
|
402
|
+
params
|
|
403
|
+
.filter((param) => !param.optional)
|
|
404
|
+
.forEach((param) => fn.line(`if (builder.${camel(param.name)} == null) {`).indent((b) => b.line(`throw new IllegalStateException(${str(`${param.name} is required`)});`)).line("}"));
|
|
405
|
+
params.forEach((param) => fn.line(`this.${camel(param.name)} = builder.${camel(param.name)};`));
|
|
406
|
+
});
|
|
407
|
+
body.line("}");
|
|
408
|
+
body.line();
|
|
409
|
+
javadoc(body, [`A new builder for ${name}.`]);
|
|
410
|
+
body.line("public static Builder builder() {").indent((fn) => fn.line("return new Builder();")).line("}");
|
|
411
|
+
body.line();
|
|
412
|
+
javadoc(body, ["A builder that starts from these parameters, e.g. to change one of them."]);
|
|
413
|
+
body.line("public Builder toBuilder() {").indent((fn) => {
|
|
414
|
+
fn.line("Builder builder = new Builder();");
|
|
415
|
+
params.forEach((param) => fn.line(`builder.${camel(param.name)} = ${camel(param.name)};`));
|
|
416
|
+
fn.line("return builder;");
|
|
417
|
+
});
|
|
418
|
+
body.line("}");
|
|
419
|
+
params.forEach((param) => {
|
|
420
|
+
body.line();
|
|
421
|
+
javadoc(body, [`${param.doc ?? param.name} (${param.in} parameter "${param.name}"); null when not set.`]);
|
|
422
|
+
body.line(`public ${javaType(param.type, param.name)} ${camel(param.name)}() {`).indent((fn) => fn.line(`return ${camel(param.name)};`)).line("}");
|
|
423
|
+
});
|
|
424
|
+
body.line();
|
|
425
|
+
javadoc(body, [`Builds ${name}.`]);
|
|
426
|
+
body.line("public static final class Builder {").indent((builder) => {
|
|
427
|
+
params.forEach((param) => builder.line(`private ${javaType(param.type, param.name)} ${camel(param.name)};`));
|
|
428
|
+
builder.line().line("private Builder() {").line("}");
|
|
429
|
+
params.forEach((param) => {
|
|
430
|
+
builder.line();
|
|
431
|
+
javadoc(builder, [`Sets ${param.name}${param.optional ? "" : " (required)"}.`]);
|
|
432
|
+
builder.line(`public Builder ${camel(param.name)}(${javaType(param.type, param.name)} value) {`).indent((fn) => fn.line(`this.${camel(param.name)} = value;`).line("return this;")).line("}");
|
|
433
|
+
});
|
|
434
|
+
builder.line();
|
|
435
|
+
javadoc(builder, [`Creates the ${name}.`]);
|
|
436
|
+
builder.line(`public ${name} build() {`).indent((fn) => fn.line(`return new ${name}(this);`)).line("}");
|
|
437
|
+
});
|
|
438
|
+
body.line("}");
|
|
439
|
+
});
|
|
440
|
+
return writer.line("}").toString();
|
|
441
|
+
}
|