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,145 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.IO;
|
|
4
|
+
using System.Net;
|
|
5
|
+
using System.Net.Sockets;
|
|
6
|
+
using System.Text;
|
|
7
|
+
using System.Threading;
|
|
8
|
+
using System.Threading.Tasks;
|
|
9
|
+
|
|
10
|
+
namespace Sdkloom.Runtime.Tests
|
|
11
|
+
{
|
|
12
|
+
public static class TransportTests
|
|
13
|
+
{
|
|
14
|
+
/// <summary>A one-request HTTP/1.1 server; returns its base URL and the raw request it received.</summary>
|
|
15
|
+
private static (string Url, Task<string> Received) Serve(string response, int delayMs = 0)
|
|
16
|
+
{
|
|
17
|
+
var listener = new TcpListener(IPAddress.Loopback, 0);
|
|
18
|
+
listener.Start();
|
|
19
|
+
var url = "http://127.0.0.1:" + ((IPEndPoint)listener.LocalEndpoint).Port;
|
|
20
|
+
var received = Task.Run(async () =>
|
|
21
|
+
{
|
|
22
|
+
using var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
|
|
23
|
+
var stream = client.GetStream();
|
|
24
|
+
var reader = new StreamReader(stream, Encoding.ASCII);
|
|
25
|
+
var head = new StringBuilder();
|
|
26
|
+
var length = 0;
|
|
27
|
+
for (var line = await reader.ReadLineAsync().ConfigureAwait(false); !string.IsNullOrEmpty(line); line = await reader.ReadLineAsync().ConfigureAwait(false))
|
|
28
|
+
{
|
|
29
|
+
head.Append(line).Append('\n');
|
|
30
|
+
if (line.StartsWith("Content-Length:", StringComparison.OrdinalIgnoreCase))
|
|
31
|
+
{
|
|
32
|
+
length = int.Parse(line.Substring(15).Trim());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var body = new char[length];
|
|
37
|
+
var read = 0;
|
|
38
|
+
while (read < length)
|
|
39
|
+
{
|
|
40
|
+
read += await reader.ReadAsync(body, read, length - read).ConfigureAwait(false);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await Task.Delay(delayMs).ConfigureAwait(false);
|
|
44
|
+
var bytes = Encoding.UTF8.GetBytes(response);
|
|
45
|
+
try
|
|
46
|
+
{
|
|
47
|
+
await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
|
48
|
+
}
|
|
49
|
+
catch (IOException)
|
|
50
|
+
{
|
|
51
|
+
// The client gave up (a timeout test).
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
listener.Stop();
|
|
55
|
+
return head + "\n" + new string(body);
|
|
56
|
+
});
|
|
57
|
+
return (url, received);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public static async Task SendsHeadersAndBodyAndReturnsErrorStatusesWithTheirBody()
|
|
61
|
+
{
|
|
62
|
+
var (url, received) = Serve("HTTP/1.1 404 Not Found\r\nContent-Type: application/json\r\nX-Request-Id: r1\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}");
|
|
63
|
+
var request = new HttpRequest("POST", url + "/a?b=1").WithHeader("content-type", "application/json").WithHeader("authorization", "Bearer t").WithBody(Encoding.UTF8.GetBytes("{\"x\":1}"));
|
|
64
|
+
|
|
65
|
+
var response = await new HttpClientTransport().Send(request, new SendOptions(5000, CancellationToken.None));
|
|
66
|
+
|
|
67
|
+
var raw = await received;
|
|
68
|
+
Check.True(raw.StartsWith("POST /a?b=1 HTTP/1.1\n", StringComparison.Ordinal), raw);
|
|
69
|
+
Check.True(raw.Contains("authorization: Bearer t") || raw.Contains("Authorization: Bearer t"), raw);
|
|
70
|
+
Check.True(raw.EndsWith("\n{\"x\":1}", StringComparison.Ordinal), raw);
|
|
71
|
+
Check.Equal(404, response.Status);
|
|
72
|
+
Check.Equal("r1", response.Header("x-request-id"));
|
|
73
|
+
Check.Equal("application/json", response.Header("Content-Type"));
|
|
74
|
+
Check.Equal("{}", response.Text());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static async Task RedirectsAreReturnedNotFollowed()
|
|
78
|
+
{
|
|
79
|
+
var (url, _) = Serve("HTTP/1.1 302 Found\r\nLocation: http://127.0.0.1:1/elsewhere\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
|
|
80
|
+
|
|
81
|
+
var response = await new HttpClientTransport().Send(new HttpRequest("GET", url + "/"), new SendOptions(5000, CancellationToken.None));
|
|
82
|
+
|
|
83
|
+
Check.Equal(302, response.Status);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public static async Task ATimeoutIsATransportErrorButCancellationStaysCancellation()
|
|
87
|
+
{
|
|
88
|
+
var (url, _) = Serve("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", 2000);
|
|
89
|
+
var timeout = await Check.ThrowsAsync<TransportException>(() => new HttpClientTransport().Send(new HttpRequest("GET", url + "/"), new SendOptions(50, CancellationToken.None)));
|
|
90
|
+
Check.Equal("timeout", timeout.Reason);
|
|
91
|
+
|
|
92
|
+
var (other, _) = Serve("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", 2000);
|
|
93
|
+
using var cancel = new CancellationTokenSource(50);
|
|
94
|
+
await Check.ThrowsAsync<OperationCanceledException>(() => new HttpClientTransport().Send(new HttpRequest("GET", other + "/"), new SendOptions(null, cancel.Token)));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static async Task AFailedConnectionIsANetworkError()
|
|
98
|
+
{
|
|
99
|
+
var error = await Check.ThrowsAsync<TransportException>(() => new HttpClientTransport().Send(new HttpRequest("GET", "http://127.0.0.1:1/"), new SendOptions(2000, CancellationToken.None)));
|
|
100
|
+
|
|
101
|
+
Check.Equal("network", error.Reason);
|
|
102
|
+
Check.Equal("TransportError", error.Name);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public static async Task StreamHandsOverASuccessfulBodyAsItArrivesPastTheTimeout()
|
|
106
|
+
{
|
|
107
|
+
var listener = new TcpListener(IPAddress.Loopback, 0);
|
|
108
|
+
listener.Start();
|
|
109
|
+
var url = "http://127.0.0.1:" + ((IPEndPoint)listener.LocalEndpoint).Port;
|
|
110
|
+
var release = new TaskCompletionSource<bool>();
|
|
111
|
+
var server = Task.Run(async () =>
|
|
112
|
+
{
|
|
113
|
+
using var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
|
|
114
|
+
var stream = client.GetStream();
|
|
115
|
+
var reader = new StreamReader(stream, Encoding.ASCII);
|
|
116
|
+
for (var line = await reader.ReadLineAsync().ConfigureAwait(false); !string.IsNullOrEmpty(line); line = await reader.ReadLineAsync().ConfigureAwait(false))
|
|
117
|
+
{
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
var first = Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\ncontent-type: text/event-stream\r\nconnection: close\r\n\r\ndata: one\n\n");
|
|
121
|
+
await stream.WriteAsync(first, 0, first.Length).ConfigureAwait(false);
|
|
122
|
+
await release.Task.ConfigureAwait(false);
|
|
123
|
+
var second = Encoding.ASCII.GetBytes("data: two\n\n");
|
|
124
|
+
await stream.WriteAsync(second, 0, second.Length).ConfigureAwait(false);
|
|
125
|
+
listener.Stop();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
var response = await new HttpClientTransport().Send(new HttpRequest("GET", url + "/events"), new SendOptions(100, CancellationToken.None, stream: true)).ConfigureAwait(false);
|
|
129
|
+
var events = new List<string>();
|
|
130
|
+
await foreach (var item in EventStreams.Read<string>(response, null).ConfigureAwait(false))
|
|
131
|
+
{
|
|
132
|
+
events.Add(item.Data);
|
|
133
|
+
if (events.Count == 1)
|
|
134
|
+
{
|
|
135
|
+
await Task.Delay(200).ConfigureAwait(false);
|
|
136
|
+
release.SetResult(true);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
await server.ConfigureAwait(false);
|
|
141
|
+
Check.Equal(0, response.Body.Length);
|
|
142
|
+
Check.Equal("one,two", string.Join(",", events));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @requirement SDKL-WAIT-001
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Threading.Tasks;
|
|
4
|
+
|
|
5
|
+
namespace Sdkloom.Runtime.Tests
|
|
6
|
+
{
|
|
7
|
+
public static class WaitTests
|
|
8
|
+
{
|
|
9
|
+
public static async Task PollsOnTheClockUntilDoneAndReturnsADoneResultWithoutPolling()
|
|
10
|
+
{
|
|
11
|
+
var clock = new FakeClock();
|
|
12
|
+
var states = new Queue<string>(new[] { "running", "running", "done" });
|
|
13
|
+
var polled = new List<string>();
|
|
14
|
+
var result = await Waits.Until("pending", (current, token) =>
|
|
15
|
+
{
|
|
16
|
+
var status = states.Dequeue();
|
|
17
|
+
polled.Add(status);
|
|
18
|
+
return Task.FromResult(status);
|
|
19
|
+
}, current => current == "done", clock, 500, 10000).ConfigureAwait(false);
|
|
20
|
+
var immediate = await Waits.Until("done", (current, token) => throw new System.InvalidOperationException("polled"), current => current == "done", clock, 500, 10000).ConfigureAwait(false);
|
|
21
|
+
|
|
22
|
+
Check.Equal("done", result);
|
|
23
|
+
Check.Equal("running,running,done", string.Join(",", polled));
|
|
24
|
+
Check.Equal(1500L, clock.Now());
|
|
25
|
+
Check.Equal("done", immediate);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static async Task ThrowsWaitTimeoutExceptionKeepingTheLastResult()
|
|
29
|
+
{
|
|
30
|
+
var clock = new FakeClock();
|
|
31
|
+
var polls = 0;
|
|
32
|
+
var error = await Check.ThrowsAsync<WaitTimeoutException>(() => Waits.Until("pending", (current, token) => Task.FromResult("running " + ++polls), current => false, clock, 400, 1000)).ConfigureAwait(false);
|
|
33
|
+
|
|
34
|
+
Check.Equal("running 2", (string?)error.Last);
|
|
35
|
+
Check.Equal("WaitTimeoutError", error.Name);
|
|
36
|
+
Check.Equal(800L, clock.Now());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @requirement SDKL-HOOK-001
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Text;
|
|
4
|
+
|
|
5
|
+
namespace Sdkloom.Runtime.Tests
|
|
6
|
+
{
|
|
7
|
+
public static class WebhooksTests
|
|
8
|
+
{
|
|
9
|
+
private static readonly WebhookSignature Standard = new WebhookSignature("webhook-signature", "base64", "v1,", " ", "{webhook-id}.{webhook-timestamp}.{body}", "webhook-timestamp", 300, "base64", "whsec_");
|
|
10
|
+
private const string Secret = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw";
|
|
11
|
+
private static readonly byte[] Body = Encoding.UTF8.GetBytes("{\"test\": 2432232314}");
|
|
12
|
+
private static readonly Dictionary<string, string> Headers = new Dictionary<string, string>
|
|
13
|
+
{
|
|
14
|
+
["Webhook-Id"] = "msg_p5jXN8AQM9LWM0D4loKWxJek",
|
|
15
|
+
["webhook-timestamp"] = "1614265330",
|
|
16
|
+
["webhook-signature"] = "v1,bad v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
public static void VerifiesTheStandardWebhooksExample()
|
|
20
|
+
{
|
|
21
|
+
Webhooks.Verify(Standard, Body, Headers, Secret, 1614265330);
|
|
22
|
+
Webhooks.Verify(Standard, Body, Headers, Secret, 1614265330 + 300);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static void RefusesChangesWrongSecretsOldTimestampsAndMissingHeaders()
|
|
26
|
+
{
|
|
27
|
+
var forged = Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(Standard, Encoding.UTF8.GetBytes("{\"test\": 3432232314}"), Headers, Secret, 1614265330));
|
|
28
|
+
Check.Equal("no signature matches: the webhook was not signed with this secret, or was changed after signing", forged.Message);
|
|
29
|
+
Check.Equal("WebhookSignatureError", forged.Name);
|
|
30
|
+
Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(Standard, Body, Headers, "whsec_AAAA", 1614265330));
|
|
31
|
+
Check.Equal("the webhook was signed at 1614265330, more than 300 s from now", Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(Standard, Body, Headers, Secret, 1614265330 + 301)).Message);
|
|
32
|
+
var onlySignature = new Dictionary<string, string> { ["webhook-signature"] = "v1,x" };
|
|
33
|
+
Check.Equal("missing or invalid webhook-timestamp header", Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(Standard, Body, onlySignature, Secret, 1614265330)).Message);
|
|
34
|
+
Check.Equal("the secret is not valid base64", Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(Standard, Body, Headers, "whsec_!!!", 1614265330)).Message);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static void VerifiesAHexSignatureOfTheBodyWithATextSecret()
|
|
38
|
+
{
|
|
39
|
+
var github = new WebhookSignature("x-hub-signature-256", "hex", "sha256=", null, "{body}", null, 0, "text", null);
|
|
40
|
+
var body = Encoding.UTF8.GetBytes("{\"zen\":\"Design for failure.\"}");
|
|
41
|
+
const string signature = "sha256=fb962995c1234ec94fb7a13c015a044d2d0ef7e076c0b619d419a8bf068cc218";
|
|
42
|
+
Webhooks.Verify(github, body, new Dictionary<string, string> { ["X-Hub-Signature-256"] = signature }, "It is a secret", 0);
|
|
43
|
+
Check.Throws<WebhookSignatureException>(() => Webhooks.Verify(github, body, new Dictionary<string, string> { ["x-hub-signature-256"] = signature.Replace("sha256=", "sha1=") }, "It is a secret", 0));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"default": {
|
|
3
|
+
"range": ">=3",
|
|
4
|
+
"test": ["8", "10"]
|
|
5
|
+
},
|
|
6
|
+
"notes": {
|
|
7
|
+
"3": {
|
|
8
|
+
"text": "The SDK is one netstandard2.1 library: .NET Core 3.0+, .NET 5+, Mono 6.4+ and Unity. Its reference assemblies ship with every .NET SDK, so it builds offline. .NET Framework needs netstandard2.0, whose references come from NuGet; that would be an opt-in variant.",
|
|
9
|
+
"source": "https://learn.microsoft.com/en-us/dotnet/standard/net-standard"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
package/kits/go/kit.json
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// sdkloom Go kit: calling one operation.
|
|
2
|
+
package sdkruntime
|
|
3
|
+
|
|
4
|
+
import (
|
|
5
|
+
"context"
|
|
6
|
+
"io"
|
|
7
|
+
"strings"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// @block client.call
|
|
11
|
+
// @summary Sends one operation: refuses one newer than the pinned API version, builds URL, headers (with the API version) and body, runs the middleware chain, sends it and turns a non-2xx response into the declared error.
|
|
12
|
+
// @versions >=1.18
|
|
13
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.5
|
|
14
|
+
// @quote [1] "The 4xx (Client Error) class of status code indicates that the client seems to have erred."
|
|
15
|
+
// @source [2] https://www.rfc-editor.org/rfc/rfc9110#section-15.6
|
|
16
|
+
// @quote [2] "The 5xx (Server Error) class of status code indicates that the server is aware that it has erred or is incapable of performing the requested method."
|
|
17
|
+
// @retrieved 2026-12-05
|
|
18
|
+
// @tests tests/client_test.go
|
|
19
|
+
// @requirement SDKL-ERR-001
|
|
20
|
+
// @requirement SDKL-PIPE-001
|
|
21
|
+
|
|
22
|
+
// Next sends a request on to the rest of the chain.
|
|
23
|
+
type Next func(request Request) (Response, error)
|
|
24
|
+
|
|
25
|
+
// Middleware wraps every call: change the request, call next zero or more times, change the response.
|
|
26
|
+
type Middleware func(request Request, next Next, ctx Context) (Response, error)
|
|
27
|
+
|
|
28
|
+
// MiddlewareEntry is a middleware with its configuration bound.
|
|
29
|
+
type MiddlewareEntry struct {
|
|
30
|
+
Name string
|
|
31
|
+
Run Middleware
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Entry binds a middleware to its configuration.
|
|
35
|
+
func Entry(name string, middleware Middleware, config map[string]any) MiddlewareEntry {
|
|
36
|
+
return MiddlewareEntry{Name: name, Run: func(request Request, next Next, ctx Context) (Response, error) {
|
|
37
|
+
return middleware(request, next, ctx.WithConfig(config))
|
|
38
|
+
}}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Body kinds and result kinds of an operation.
|
|
42
|
+
const (
|
|
43
|
+
KindJSON = "json"
|
|
44
|
+
KindBytes = "bytes"
|
|
45
|
+
KindStream = "stream"
|
|
46
|
+
// KindEvents is a result of server-sent events, read with NewEventStream.
|
|
47
|
+
KindEvents = "events"
|
|
48
|
+
// KindMultipart is a multipart/form-data body (a MultipartForm).
|
|
49
|
+
KindMultipart = "multipart"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// OperationSpec is what generated code knows about one operation.
|
|
53
|
+
type OperationSpec struct {
|
|
54
|
+
Name string
|
|
55
|
+
Method string
|
|
56
|
+
Path string
|
|
57
|
+
// Body is "", KindJSON, KindBytes or KindStream; Result may also be KindEvents.
|
|
58
|
+
Body string
|
|
59
|
+
Result string
|
|
60
|
+
Errors map[int]ErrorFactory
|
|
61
|
+
Use []string
|
|
62
|
+
// Since is the first API version that has the operation; "" for every version.
|
|
63
|
+
Since string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Args are one call's parameters; a nil query or header value is left out.
|
|
67
|
+
type Args struct {
|
|
68
|
+
Path map[string]any
|
|
69
|
+
Query []QueryParam
|
|
70
|
+
Headers []QueryParam
|
|
71
|
+
// Body is a model, plain JSON data, []byte or an io.Reader, by the operation's body kind.
|
|
72
|
+
Body any
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// CallOptions change one call.
|
|
76
|
+
type CallOptions struct {
|
|
77
|
+
TimeoutMs Opt[int64]
|
|
78
|
+
Headers []Header
|
|
79
|
+
BaseURL string
|
|
80
|
+
// URL is called instead of the URL the path and query make (the next page a Link header named); see ResolveURL.
|
|
81
|
+
URL string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// CallOption changes one call, e.g. WithTimeout(5000).
|
|
85
|
+
type CallOption func(*CallOptions)
|
|
86
|
+
|
|
87
|
+
// WithTimeout limits one call to ms milliseconds.
|
|
88
|
+
func WithTimeout(ms int64) CallOption {
|
|
89
|
+
return func(options *CallOptions) { options.TimeoutMs = Some(ms) }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// WithHeader adds a header to one call.
|
|
93
|
+
func WithHeader(name, value string) CallOption {
|
|
94
|
+
return func(options *CallOptions) { options.Headers = append(options.Headers, Header{Name: name, Value: value}) }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// WithBaseURL sends one call to another server.
|
|
98
|
+
func WithBaseURL(url string) CallOption {
|
|
99
|
+
return func(options *CallOptions) { options.BaseURL = url }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// WithURL calls url instead of the URL the operation's path and query make, e.g. the next page a Link header named.
|
|
103
|
+
func WithURL(url string) CallOption {
|
|
104
|
+
return func(options *CallOptions) { options.URL = url }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Runtime is everything a client shares between calls. Safe for concurrent use.
|
|
108
|
+
type Runtime struct {
|
|
109
|
+
BaseURL string
|
|
110
|
+
Transport Transport
|
|
111
|
+
Clock Clock
|
|
112
|
+
State *State
|
|
113
|
+
Middleware []MiddlewareEntry
|
|
114
|
+
Registry map[string]MiddlewareEntry
|
|
115
|
+
UserMiddleware []MiddlewareEntry
|
|
116
|
+
Listeners []EventListener
|
|
117
|
+
TimeoutMs Opt[int64]
|
|
118
|
+
SDK SdkInfo
|
|
119
|
+
// APIVersion is the API version the client is pinned to, or nil when the API has none.
|
|
120
|
+
APIVersion *APIVersion
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// APIVersion is the version a client is pinned to (Value), the header that carries it and every version, oldest first.
|
|
124
|
+
type APIVersion struct {
|
|
125
|
+
Header string
|
|
126
|
+
Value string
|
|
127
|
+
Values []string
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
func indexOf(values []string, value string) int {
|
|
131
|
+
for i, candidate := range values {
|
|
132
|
+
if candidate == value {
|
|
133
|
+
return i
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return -1
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Check refuses an operation newer than the pinned version, or a version the SDK does not know.
|
|
140
|
+
func (v *APIVersion) Check(operation, since string) error {
|
|
141
|
+
if v == nil {
|
|
142
|
+
return nil
|
|
143
|
+
}
|
|
144
|
+
pinned := indexOf(v.Values, v.Value)
|
|
145
|
+
if pinned < 0 {
|
|
146
|
+
return &ArgumentError{Message: "unknown API version " + v.Value + "; this SDK knows " + strings.Join(v.Values, ", ")}
|
|
147
|
+
}
|
|
148
|
+
if since != "" && indexOf(v.Values, since) > pinned {
|
|
149
|
+
return &ArgumentError{Message: operation + " needs API version " + since + " or later; this client uses " + v.Value}
|
|
150
|
+
}
|
|
151
|
+
return nil
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func encodeBody(kind string, value any) ([]byte, string, error) {
|
|
155
|
+
if kind == "" || value == nil {
|
|
156
|
+
return nil, "", nil
|
|
157
|
+
}
|
|
158
|
+
switch kind {
|
|
159
|
+
case KindJSON:
|
|
160
|
+
encoded, err := EncodeJSON(value)
|
|
161
|
+
return encoded, "application/json", err
|
|
162
|
+
case KindBytes:
|
|
163
|
+
data, _ := value.([]byte)
|
|
164
|
+
return data, "application/octet-stream", nil
|
|
165
|
+
case KindMultipart:
|
|
166
|
+
form, _ := value.(MultipartForm)
|
|
167
|
+
boundary := MultipartBoundary()
|
|
168
|
+
return form.Encode(boundary), "multipart/form-data; boundary=" + boundary, nil
|
|
169
|
+
default:
|
|
170
|
+
if reader, ok := value.(io.Reader); ok {
|
|
171
|
+
data, err := io.ReadAll(reader)
|
|
172
|
+
return data, "application/octet-stream", err
|
|
173
|
+
}
|
|
174
|
+
data, _ := value.([]byte)
|
|
175
|
+
return data, "application/octet-stream", nil
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
func buildRequest(runtime *Runtime, spec OperationSpec, args Args, options CallOptions) (Request, error) {
|
|
180
|
+
base := runtime.BaseURL
|
|
181
|
+
if options.BaseURL != "" {
|
|
182
|
+
base = options.BaseURL
|
|
183
|
+
}
|
|
184
|
+
url := ResolveURL(base, options.URL)
|
|
185
|
+
if options.URL == "" {
|
|
186
|
+
built, err := BuildURL(base, spec.Path, args.Path, args.Query)
|
|
187
|
+
if err != nil {
|
|
188
|
+
return Request{}, err
|
|
189
|
+
}
|
|
190
|
+
url = built
|
|
191
|
+
}
|
|
192
|
+
body, contentType, err := encodeBody(spec.Body, args.Body)
|
|
193
|
+
if err != nil {
|
|
194
|
+
return Request{}, err
|
|
195
|
+
}
|
|
196
|
+
accept := "application/json"
|
|
197
|
+
if spec.Result == KindEvents {
|
|
198
|
+
accept = "text/event-stream"
|
|
199
|
+
} else if spec.Result == KindBytes || spec.Result == KindStream {
|
|
200
|
+
accept = "*/*"
|
|
201
|
+
}
|
|
202
|
+
request := NewRequest(spec.Method, url).WithHeader("accept", accept)
|
|
203
|
+
if runtime.APIVersion != nil {
|
|
204
|
+
request = request.WithHeader(runtime.APIVersion.Header, runtime.APIVersion.Value)
|
|
205
|
+
}
|
|
206
|
+
if contentType != "" {
|
|
207
|
+
request = request.WithHeader("content-type", contentType)
|
|
208
|
+
}
|
|
209
|
+
for _, header := range args.Headers {
|
|
210
|
+
if header.Value != nil {
|
|
211
|
+
request = request.WithHeader(header.Name, Scalar(header.Value))
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for _, header := range options.Headers {
|
|
215
|
+
request = request.WithHeader(header.Name, header.Value)
|
|
216
|
+
}
|
|
217
|
+
if body != nil {
|
|
218
|
+
request.Body = body
|
|
219
|
+
}
|
|
220
|
+
return request, nil
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
func errorFor(spec OperationSpec, response Response) error {
|
|
224
|
+
body, err := response.JSON()
|
|
225
|
+
if err != nil {
|
|
226
|
+
body = response.Text()
|
|
227
|
+
}
|
|
228
|
+
if factory, ok := spec.Errors[response.Status]; ok {
|
|
229
|
+
return factory(response.Status, body, response)
|
|
230
|
+
}
|
|
231
|
+
return NewAPIError("ApiError", response.Status, body, response)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
func runPipeline(handlers []func(Request, Next) (Response, error), request Request, last Next) (Response, error) {
|
|
235
|
+
var step func(index int) Next
|
|
236
|
+
step = func(index int) Next {
|
|
237
|
+
return func(current Request) (Response, error) {
|
|
238
|
+
if index >= len(handlers) {
|
|
239
|
+
return last(current)
|
|
240
|
+
}
|
|
241
|
+
return handlers[index](current, step(index+1))
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return step(0)(request)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Call sends one operation through the middleware chain and returns the 2xx response, or the error for any other.
|
|
248
|
+
func Call(goContext context.Context, runtime *Runtime, spec OperationSpec, args Args, opts ...CallOption) (Response, error) {
|
|
249
|
+
if goContext == nil {
|
|
250
|
+
goContext = context.Background()
|
|
251
|
+
}
|
|
252
|
+
options := CallOptions{}
|
|
253
|
+
for _, option := range opts {
|
|
254
|
+
option(&options)
|
|
255
|
+
}
|
|
256
|
+
if err := runtime.APIVersion.Check(spec.Name, spec.Since); err != nil {
|
|
257
|
+
return Response{}, err
|
|
258
|
+
}
|
|
259
|
+
request, err := buildRequest(runtime, spec, args, options)
|
|
260
|
+
if err != nil {
|
|
261
|
+
return Response{}, err
|
|
262
|
+
}
|
|
263
|
+
timeout := runtime.TimeoutMs
|
|
264
|
+
if options.TimeoutMs.Set {
|
|
265
|
+
timeout = options.TimeoutMs
|
|
266
|
+
}
|
|
267
|
+
send := func(current Request) (Response, error) {
|
|
268
|
+
return runtime.Transport.Send(goContext, current, SendOptions{TimeoutMs: timeout, Stream: spec.Result == KindEvents})
|
|
269
|
+
}
|
|
270
|
+
state := runtime.State
|
|
271
|
+
if state == nil {
|
|
272
|
+
state = NewState(runtime.Clock)
|
|
273
|
+
}
|
|
274
|
+
base := Context{
|
|
275
|
+
Go: goContext,
|
|
276
|
+
Operation: OperationInfo{Name: spec.Name, Method: spec.Method, Path: spec.Path},
|
|
277
|
+
Clock: runtime.Clock,
|
|
278
|
+
State: state,
|
|
279
|
+
SDK: runtime.SDK,
|
|
280
|
+
emit: Emitter(runtime.Listeners),
|
|
281
|
+
send: send,
|
|
282
|
+
}
|
|
283
|
+
entries := append([]MiddlewareEntry{}, runtime.Middleware...)
|
|
284
|
+
for _, name := range spec.Use {
|
|
285
|
+
entry, ok := runtime.Registry[name]
|
|
286
|
+
if !ok {
|
|
287
|
+
return Response{}, &MissingMiddlewareError{Name: name}
|
|
288
|
+
}
|
|
289
|
+
entries = append(entries, entry)
|
|
290
|
+
}
|
|
291
|
+
entries = append(entries, runtime.UserMiddleware...)
|
|
292
|
+
handlers := make([]func(Request, Next) (Response, error), len(entries))
|
|
293
|
+
for i, entry := range entries {
|
|
294
|
+
run := entry.Run
|
|
295
|
+
handlers[i] = func(current Request, next Next) (Response, error) { return run(current, next, base) }
|
|
296
|
+
}
|
|
297
|
+
response, err := runPipeline(handlers, request, send)
|
|
298
|
+
if err != nil {
|
|
299
|
+
return Response{}, err
|
|
300
|
+
}
|
|
301
|
+
if response.Status < 200 || response.Status > 299 {
|
|
302
|
+
return response, errorFor(spec, response)
|
|
303
|
+
}
|
|
304
|
+
return response, nil
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// MissingMiddlewareError reports an operation that uses a middleware the client does not have.
|
|
308
|
+
type MissingMiddlewareError struct {
|
|
309
|
+
Name string
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
func (e *MissingMiddlewareError) Error() string {
|
|
313
|
+
return "unknown middleware " + e.Name
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Result is a call's decoded data and the response it came from.
|
|
317
|
+
type Result[T any] struct {
|
|
318
|
+
Data T
|
|
319
|
+
Response Response
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// @end
|