diff --git a/codegen-server-test/build.gradle.kts b/codegen-server-test/build.gradle.kts index 87210d60a33..0599fdde009 100644 --- a/codegen-server-test/build.gradle.kts +++ b/codegen-server-test/build.gradle.kts @@ -35,8 +35,8 @@ dependencies { val allCodegenTests = listOf( CodegenTest("com.amazonaws.simple#SimpleService", "simple"), - CodegenTest("aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras"), CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"), + CodegenTest("aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras"), CodegenTest("aws.protocoltests.restjson.validation#RestJsonValidation", "rest_json_validation"), CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10"), CodegenTest("aws.protocoltests.json#JsonProtocol", "json_rpc11"), diff --git a/codegen-server-test/model/rest-json-extras.smithy b/codegen-server-test/model/rest-json-extras.smithy new file mode 120000 index 00000000000..d22b926177e --- /dev/null +++ b/codegen-server-test/model/rest-json-extras.smithy @@ -0,0 +1 @@ +../../codegen-test/model/rest-json-extras.smithy \ No newline at end of file diff --git a/codegen-server-test/model/rest_json_extras.smithy b/codegen-server-test/model/rest_json_extras.smithy deleted file mode 100644 index 826a54b151b..00000000000 --- a/codegen-server-test/model/rest_json_extras.smithy +++ /dev/null @@ -1,126 +0,0 @@ -$version: "1.0" - -namespace aws.protocoltests.restjson - -use aws.protocols#restJson1 -use aws.api#service -use smithy.test#httpRequestTests -use smithy.test#httpResponseTests -use smithy.test#httpMalformedRequestTests - -/// A REST JSON service that sends JSON requests and responses. -@service(sdkId: "Rest Json Protocol") -@restJson1 -service RestJsonExtras { - version: "2019-12-16", - operations: [ - FixedMalformedAcceptWithGenericString, - FixedRegisterService, - ] -} - - -apply FixedMalformedAcceptWithGenericString @httpMalformedRequestTests([ - { - id: "RestJsonWithPayloadExpectsImpliedAcceptFixed", - documentation: """ - When there is a payload without a mediaType trait, the accept must match the - implied content type of the shape.""", - protocol: restJson1, - request: { - method: "POST", - uri: "/FixedMalformedAcceptWithGenericString", - headers: { - // this should be text/plain - "accept": "application/json" - } - }, - response: { - code: 406, - headers: { - "x-amzn-errortype": "NotAcceptableException" - } - }, - tags: [ "accept" ] - } -]) - -@suppress(["UnstableTrait"]) -@http(method: "POST", uri: "/FixedMalformedAcceptWithGenericString") -operation FixedMalformedAcceptWithGenericString { - input: FixedMalformedAcceptWithGenericStringInput -} - -structure FixedMalformedAcceptWithGenericStringInput { - @httpPayload - payload: String -} - -@idempotent -@http(method: "PUT", uri: "/service/{id}") -@documentation("Service register operation") -@httpRequestTests([ - { - id: "FixedRegisterServiceRequestTest", - protocol: "aws.protocols#restJson1", - uri: "/service/1", - headers: { - "Content-Type": "application/json", - }, - params: { id: "1", name: "TestService" }, - body: "{\"name\":\"TestService\"}", - method: "PUT", - } -]) -@httpResponseTests([ - { - id: "FixedRegisterServiceResponseTest", - protocol: "aws.protocols#restJson1", - params: { id: "1", name: "TestService" }, - headers: { - "Content-Type": "TestService", - }, - body: "{\"id\":\"1\"}", - code: 200, - } -]) -operation FixedRegisterService { - input: FixedRegisterServiceInputRequest, - output: FixedRegisterServiceOutputResponse, - errors: [FixedResourceAlreadyExists] -} - -@documentation("Service register input structure") -structure FixedRegisterServiceInputRequest { - @required - @httpLabel - id: ServiceId, - name: ServiceName, -} - -@documentation("Service register output structure") -structure FixedRegisterServiceOutputResponse { - @required - id: ServiceId, - - @required - @httpHeader("Content-Type") - name: ServiceName, -} - -@error("client") -@documentation( - """ - Returned when a new resource cannot be created because one already exists. - """ -) -structure FixedResourceAlreadyExists { - @required - message: String -} - -@documentation("Id of the service that will be registered") -string ServiceId - -@documentation("Name of the service that will be registered") -string ServiceName diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index c2cfc6f37bd..8decca4cf35 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -660,6 +660,7 @@ class ServerProtocolTestGenerator( FailingTest(RestJson, "RestJsonHttpWithEmptyStructurePayload", TestType.Request), FailingTest(RestJson, "RestJsonHttpResponseCodeDefaultsToModeledCode", TestType.Response), + FailingTest(RestJson, "RestJsonWithPayloadExpectsImpliedAccept", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonBodyMalformedBlobInvalidBase64_case1", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonBodyMalformedBlobInvalidBase64_case2", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonBodyByteMalformedValueRejected_case2", TestType.MalformedRequest), diff --git a/codegen-test/model/rest-json-extras.smithy b/codegen-test/model/rest-json-extras.smithy index 508a47e57ea..73a1f7e5bda 100644 --- a/codegen-test/model/rest-json-extras.smithy +++ b/codegen-test/model/rest-json-extras.smithy @@ -4,6 +4,7 @@ namespace aws.protocoltests.restjson use aws.protocols#restJson1 use aws.api#service +use smithy.test#httpMalformedRequestTests use smithy.test#httpRequestTests use smithy.test#httpResponseTests @@ -65,7 +66,9 @@ service RestJsonExtras { CaseInsensitiveErrorOperation, EmptyStructWithContentOnWireOp, // TODO(https://github.com/awslabs/smithy/pull/1042): Remove this once the test case in Smithy is fixed - PostPlayerAction + PostPlayerAction, + FixedMalformedAcceptWithGenericString, + FixedRegisterService, ], errors: [ExtraError] } @@ -328,3 +331,108 @@ structure EmptyStructWithContentOnWireOpOutput { operation EmptyStructWithContentOnWireOp { output: EmptyStructWithContentOnWireOpOutput, } + +apply FixedMalformedAcceptWithGenericString @httpMalformedRequestTests([ + { + id: "RestJsonWithPayloadExpectsImpliedAcceptFixed", + documentation: """ + When there is a payload without a mediaType trait, the accept must match the + implied content type of the shape.""", + protocol: restJson1, + request: { + method: "POST", + uri: "/FixedMalformedAcceptWithGenericString", + headers: { + // this should be text/plain + "accept": "application/json" + } + }, + response: { + code: 406, + headers: { + "x-amzn-errortype": "NotAcceptableException" + } + }, + tags: [ "accept" ] + } +]) + +@suppress(["UnstableTrait"]) +@http(method: "POST", uri: "/FixedMalformedAcceptWithGenericString") +operation FixedMalformedAcceptWithGenericString { + input: FixedMalformedAcceptWithGenericStringInput +} + +structure FixedMalformedAcceptWithGenericStringInput { + @httpPayload + payload: String +} + +@idempotent +@http(method: "PUT", uri: "/service/{id}") +@documentation("Service register operation") +@httpRequestTests([ + { + id: "FixedRegisterServiceRequestTest", + protocol: "aws.protocols#restJson1", + uri: "/service/1", + headers: { + "Content-Type": "application/json", + }, + params: { id: "1", name: "TestService" }, + body: "{\"name\":\"TestService\"}", + method: "PUT", + } +]) +@httpResponseTests([ + { + id: "FixedRegisterServiceResponseTest", + protocol: "aws.protocols#restJson1", + params: { id: "1", name: "TestService" }, + headers: { + "Content-Type": "TestService", + }, + body: "{\"id\":\"1\"}", + code: 200, + } +]) +operation FixedRegisterService { + input: FixedRegisterServiceInputRequest, + output: FixedRegisterServiceOutputResponse, + errors: [FixedResourceAlreadyExists] +} + +@documentation("Service register input structure") +structure FixedRegisterServiceInputRequest { + @required + @httpLabel + id: ServiceId, + name: ServiceName, +} + +@documentation("Service register output structure") +structure FixedRegisterServiceOutputResponse { + @required + id: ServiceId, + + @required + @httpHeader("Content-Type") + name: ServiceName, +} + +@error("client") +@documentation( + """ + Returned when a new resource cannot be created because one already exists. + """ +) +structure FixedResourceAlreadyExists { + @required + message: String +} + +@documentation("Id of the service that will be registered") +string ServiceId + +@documentation("Name of the service that will be registered") +string ServiceName