diff --git a/modules/protocol-tests/resources/META-INF/smithy/HttpPayloadWithDefault.smithy b/modules/protocol-tests/resources/META-INF/smithy/HttpPayloadWithDefault.smithy new file mode 100644 index 0000000..117d27d --- /dev/null +++ b/modules/protocol-tests/resources/META-INF/smithy/HttpPayloadWithDefault.smithy @@ -0,0 +1,56 @@ +$version: "2" + +namespace alloy.test + +use alloy#simpleRestJson +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +apply HttpPayloadWithDefault @httpRequestTests([{ + id: "SimpleRestJsonSomeHttpPayloadWithDefault" + documentation: "Pass JSON string value as is if payload provided" + protocol: simpleRestJson + method: "PUT" + uri: "/httpPayloadWithDefault" + body: "\"custom value\"" + headers: { + "Content-Type": "application/json" + } + requireHeaders: ["Content-Length"] + params: { + body: "custom value" + } + bodyMediaType: "application/json" +}, { + id: "SimpleRestJsonNoneHttpPayloadWithDefault" + documentation: "Use default value when there is no payload" + protocol: simpleRestJson + method: "PUT" + uri: "/httpPayloadWithDefault" + params: { + body: "default value" + } +}]) + +apply HttpPayloadWithDefault @httpResponseTests([{ + id: "SimpleRestJsonSomeHttpPayloadWithDefault" + documentation: "Pass JSON string value as is if payload provided" + protocol: simpleRestJson + code: 200 + body: "\"custom value\"" + bodyMediaType: "application/json" + headers: { + "Content-Type": "application/json" + } + params: { + body: "custom value" + } +}, { + id: "SimpleRestJsonNoneHttpPayloadWithDefault" + documentation: "Use default value when there is no payload" + protocol: simpleRestJson + code: 200 + params: { + body: "default value" + } +}]) diff --git a/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy b/modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy index e6cf710..1a5124f 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] + operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault] } @http(method: "POST", uri: "/restaurant/{restaurant}/menu/item", code: 201) @@ -302,4 +302,17 @@ structure CustomCodeInput { structure CustomCodeOutput { @httpResponseCode code: Integer -} \ No newline at end of file +} + +@idempotent +@http(uri: "/httpPayloadWithDefault", method: "PUT") +operation HttpPayloadWithDefault { + input: HttpPayloadWithDefaultInputOutput, + output: HttpPayloadWithDefaultInputOutput +} + +structure HttpPayloadWithDefaultInputOutput { + @httpPayload + @default("default value") + body: String, +} diff --git a/modules/protocol-tests/resources/META-INF/smithy/manifest b/modules/protocol-tests/resources/META-INF/smithy/manifest index d157431..66b4cb5 100644 --- a/modules/protocol-tests/resources/META-INF/smithy/manifest +++ b/modules/protocol-tests/resources/META-INF/smithy/manifest @@ -8,4 +8,5 @@ Health.smithy Pizza.smithy RoundTrip.smithy Version.smithy -test-config.json \ No newline at end of file +HttpPayloadWithDefault.smithy +test-config.json