From 115e47a3029fe3b1a5a5c88ff93ef42f85356156 Mon Sep 17 00:00:00 2001 From: Denis Rosca Date: Thu, 13 Jun 2024 19:06:23 +0300 Subject: [PATCH 1/4] Add compliance test for sparse query parameters --- .../resources/META-INF/smithy/Pizza.smithy | 27 ++++++++++++++++++- .../smithy/SparseQueryParameter.smithy | 25 +++++++++++++++++ .../resources/META-INF/smithy/manifest | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy diff --git a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy index 1a5124fc..4695a0a4 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy @@ -9,7 +9,7 @@ use alloy#simpleRestJson service PizzaAdminService { version: "1.0.0", errors: [GenericServerError, GenericClientError], - operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault] + operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault, SparseQueryParam] } @http(method: "POST", uri: "/restaurant/{restaurant}/menu/item", code: 201) @@ -316,3 +316,28 @@ structure HttpPayloadWithDefaultInputOutput { @default("default value") body: String, } + + +@readonly +@http(uri: "/sparseQueryParam", method: "GET") +operation SparseQueryParam { + input: SparseQueryParamInput, + output: SparseQueryParamOutput +} + +structure SparseQueryParamInput { + @httpQuery("foo") + @required + foo: FooList +} + +structure SparseQueryParamOutput { + @httpPayload + @required + foo: FooList +} + +@sparse +list FooList { + member: String +} \ No newline at end of file diff --git a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy new file mode 100644 index 00000000..53dfbffb --- /dev/null +++ b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy @@ -0,0 +1,25 @@ +$version: "2.0" + +namespace alloy.test + +use alloy#simpleRestJson +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +apply SparseQueryParam @httpRequestTests([ + { + id: "SparseQueryParam" + protocol: simpleRestJson + method: "GET" + uri: "/sparse-query-param" + params: { + foo: ["bar", null, "baz"] + } + queryParams: [ + "foo=bar", + "foo", + "foo=baz" + ] + + } +]) \ No newline at end of file diff --git a/modules/protocol-tests/resources/META-INF/smithy/manifest b/modules/protocol-tests/resources/META-INF/smithy/manifest index 66b4cb5d..ba64dba2 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/manifest +++ b/modules/protocol-tests/resources/META-INF/smithy/manifest @@ -9,4 +9,5 @@ Pizza.smithy RoundTrip.smithy Version.smithy HttpPayloadWithDefault.smithy +SparseQueryParameter.smithy test-config.json From 1af00d86a0f56fc85944a450cc3efad3393db662 Mon Sep 17 00:00:00 2001 From: Denis Rosca Date: Fri, 14 Jun 2024 19:42:50 +0300 Subject: [PATCH 2/4] Fix uri path --- .../resources/META-INF/smithy/Pizza.smithy | 2 +- .../META-INF/smithy/SparseQueryParameter.smithy | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy index 4695a0a4..454fbead 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy @@ -340,4 +340,4 @@ structure SparseQueryParamOutput { @sparse list FooList { member: String -} \ No newline at end of file +} diff --git a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy index 53dfbffb..8189866e 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy @@ -9,17 +9,19 @@ use smithy.test#httpResponseTests apply SparseQueryParam @httpRequestTests([ { id: "SparseQueryParam" + documentation: "Tests sparse query param serialization" protocol: simpleRestJson method: "GET" - uri: "/sparse-query-param" + uri: "/sparseQueryParam" params: { - foo: ["bar", null, "baz"] + foo: ["bar", null, "baz", ""] } queryParams: [ "foo=bar", "foo", - "foo=baz" + "foo=baz", + "foo=" ] } -]) \ No newline at end of file +]) From 80fa85ff364a26e2e854f6fbec2792c94dce103d Mon Sep 17 00:00:00 2001 From: Denis Rosca Date: Tue, 18 Jun 2024 17:34:24 +0300 Subject: [PATCH 3/4] Add integer query params --- .../resources/META-INF/smithy/Pizza.smithy | 9 +++++++++ .../META-INF/smithy/SparseQueryParameter.smithy | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy index 454fbead..1aca4b9e 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy @@ -329,6 +329,10 @@ structure SparseQueryParamInput { @httpQuery("foo") @required foo: FooList + + @httpQuery("bar") + @required + bar: BarList } structure SparseQueryParamOutput { @@ -341,3 +345,8 @@ structure SparseQueryParamOutput { list FooList { member: String } + +@sparse +list BarList { + member: Integer +} diff --git a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy index 8189866e..98ffa068 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy @@ -14,13 +14,17 @@ apply SparseQueryParam @httpRequestTests([ method: "GET" uri: "/sparseQueryParam" params: { - foo: ["bar", null, "baz", ""] + foo: ["bar", null, "baz", ""], + bar: [1, null, 2] } queryParams: [ "foo=bar", "foo", "foo=baz", - "foo=" + "foo=", + "bar=1", + "bar", + "bar=2" ] } From 3805e7d37f0dd6768c728f47316b3eca0d20a192 Mon Sep 17 00:00:00 2001 From: Denis Rosca Date: Tue, 18 Jun 2024 20:21:09 +0300 Subject: [PATCH 4/4] Handle missing vs empty argument for integers --- .../resources/META-INF/smithy/SparseQueryParameter.smithy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy index 98ffa068..9f50adad 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy +++ b/modules/protocol-tests/resources/META-INF/smithy/SparseQueryParameter.smithy @@ -15,7 +15,7 @@ apply SparseQueryParam @httpRequestTests([ uri: "/sparseQueryParam" params: { foo: ["bar", null, "baz", ""], - bar: [1, null, 2] + bar: [1, null, 2, null] } queryParams: [ "foo=bar", @@ -24,7 +24,8 @@ apply SparseQueryParam @httpRequestTests([ "foo=", "bar=1", "bar", - "bar=2" + "bar=2", + "bar=" ] }