diff --git a/codegen-client-test/build.gradle.kts b/codegen-client-test/build.gradle.kts index 21a90ac47b..c69a4ae719 100644 --- a/codegen-client-test/build.gradle.kts +++ b/codegen-client-test/build.gradle.kts @@ -66,16 +66,7 @@ val allCodegenTests = listOf( ClientTest( "aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras", - dependsOn = listOf( - "rest-json-extras.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2310): Can be deleted when consumed in next Smithy version. - "rest-json-extras-2310.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2314): Can be deleted when consumed in next Smithy version. - "rest-json-extras-2314.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2315): Can be deleted when consumed in next Smithy version. - // TODO(https://github.com/smithy-lang/smithy/pull/2331): Can be deleted when consumed in next Smithy version. - "rest-json-extras-2315.smithy", - ), + dependsOn = listOf("rest-json-extras.smithy"), ), ClientTest("aws.protocoltests.misc#MiscService", "misc", dependsOn = listOf("misc.smithy")), ClientTest("aws.protocoltests.restxml#RestXml", "rest_xml", addMessageToErrors = false), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolTestGenerator.kt index 8cfb496023..5936438adb 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolTestGenerator.kt @@ -5,6 +5,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol +import software.amazon.smithy.model.node.NumberNode import software.amazon.smithy.model.shapes.DoubleShape import software.amazon.smithy.model.shapes.FloatShape import software.amazon.smithy.model.shapes.OperationShape @@ -27,7 +28,9 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.Broke import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.FailingTest import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTestGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ServiceShapeId import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ServiceShapeId.AWS_JSON_10 +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ServiceShapeId.REST_JSON import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.TestCase import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq @@ -73,7 +76,38 @@ class ClientProtocolTestGenerator( FailingTest.RequestTest(AWS_JSON_10, "AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse"), FailingTest.RequestTest(AWS_JSON_10, "AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults"), FailingTest.RequestTest(AWS_JSON_10, "AwsJson10ClientPopulatesDefaultValuesInInput"), + FailingTest.RequestTest(REST_JSON, "RestJsonClientPopulatesDefaultValuesInInput"), + FailingTest.RequestTest(REST_JSON, "RestJsonClientUsesExplicitlyProvidedMemberValuesOverDefaults"), ) + + private val BrokenTests: + Set = + setOf( + BrokenTest.ResponseTest( + ServiceShapeId.REST_JSON, + "RestJsonClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse", + howToFixItFn = ::fixRestJsonClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse, + inAtLeast = setOf("1.50.0"), + trackedIn = + setOf( + // TODO(https://github.com/smithy-lang/smithy/pull/2341) + "https://github.com/smithy-lang/smithy/pull/2341", + ), + ), + ) + + private fun fixRestJsonClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse( + testCase: TestCase.ResponseTest, + ): TestCase.ResponseTest { + val fixedParams = + testCase.testCase.params.toBuilder().withMember("defaultTimestamp", NumberNode.from(2)).build() + return TestCase.ResponseTest( + testCase.testCase.toBuilder() + .params(fixedParams) + .build(), + testCase.targetShape, + ) + } } override val appliesTo: AppliesTo @@ -85,7 +119,7 @@ class ClientProtocolTestGenerator( override val disabledTests: Set get() = emptySet() override val brokenTests: Set - get() = emptySet() + get() = BrokenTests override val logger: Logger = Logger.getLogger(javaClass.name) diff --git a/codegen-core/common-test-models/rest-json-extras-2310.smithy b/codegen-core/common-test-models/rest-json-extras-2310.smithy deleted file mode 100644 index afd8a1c443..0000000000 --- a/codegen-core/common-test-models/rest-json-extras-2310.smithy +++ /dev/null @@ -1,35 +0,0 @@ -$version: "1.0" - -namespace aws.protocoltests.restjson - -use aws.protocols#restJson1 -use smithy.test#httpMalformedRequestTests - -@http(method: "POST", uri: "/MalformedContentTypeWithBody") -operation MalformedContentTypeWithBody2 { - input: GreetingStruct -} - -structure GreetingStruct { - salutation: String, -} - -apply MalformedContentTypeWithBody2 @httpMalformedRequestTests([ - { - id: "RestJsonWithBodyExpectsApplicationJsonContentTypeNoHeaders", - documentation: "When there is modeled input, the content type must be application/json", - protocol: restJson1, - request: { - method: "POST", - uri: "/MalformedContentTypeWithBody", - body: "{}", - }, - response: { - code: 415, - headers: { - "x-amzn-errortype": "UnsupportedMediaTypeException" - } - }, - tags: [ "content-type" ] - } -]) diff --git a/codegen-core/common-test-models/rest-json-extras-2314.smithy b/codegen-core/common-test-models/rest-json-extras-2314.smithy deleted file mode 100644 index 3ff64f1b95..0000000000 --- a/codegen-core/common-test-models/rest-json-extras-2314.smithy +++ /dev/null @@ -1,39 +0,0 @@ -$version: "1.0" - -namespace aws.protocoltests.restjson - -use aws.protocols#restJson1 -use smithy.test#httpRequestTests - -/// This example serializes a blob shape in the payload. -/// -/// In this example, no JSON document is synthesized because the payload is -/// not a structure or a union type. -@http(uri: "/HttpPayloadTraits", method: "POST") -operation HttpPayloadTraits2 { - input: HttpPayloadTraitsInputOutput, - output: HttpPayloadTraitsInputOutput -} - -apply HttpPayloadTraits2 @httpRequestTests([ - { - id: "RestJsonHttpPayloadTraitsWithBlobAcceptsNoContentType", - documentation: """ - Servers must accept no content type for blob inputs - without the media type trait.""", - protocol: restJson1, - method: "POST", - uri: "/HttpPayloadTraits", - body: "This is definitely a jpeg", - bodyMediaType: "application/octet-stream", - headers: { - "X-Foo": "Foo", - }, - params: { - foo: "Foo", - blob: "This is definitely a jpeg" - }, - appliesTo: "server", - tags: [ "content-type" ] - } -]) diff --git a/codegen-core/common-test-models/rest-json-extras-2315.smithy b/codegen-core/common-test-models/rest-json-extras-2315.smithy deleted file mode 100644 index 955bb14c96..0000000000 --- a/codegen-core/common-test-models/rest-json-extras-2315.smithy +++ /dev/null @@ -1,133 +0,0 @@ -$version: "2.0" - -namespace aws.protocoltests.restjson - -use smithy.test#httpRequestTests -use smithy.test#httpResponseTests -use smithy.test#httpMalformedRequestTests -use smithy.framework#ValidationException - -@http(uri: "/EnumPayload2", method: "POST") -@httpRequestTests([ - { - id: "RestJsonEnumPayloadRequest2", - uri: "/EnumPayload2", - headers: { "Content-Type": "text/plain" }, - body: "enumvalue", - params: { payload: "enumvalue" }, - method: "POST", - protocol: "aws.protocols#restJson1" - } -]) -@httpResponseTests([ - { - id: "RestJsonEnumPayloadResponse2", - headers: { "Content-Type": "text/plain" }, - body: "enumvalue", - params: { payload: "enumvalue" }, - protocol: "aws.protocols#restJson1", - code: 200 - } -]) -operation HttpEnumPayload2 { - input: EnumPayloadInput, - output: EnumPayloadInput - errors: [ValidationException] -} - -@http(uri: "/StringPayload2", method: "POST") -@httpRequestTests([ - { - id: "RestJsonStringPayloadRequest2", - uri: "/StringPayload2", - body: "rawstring", - bodyMediaType: "text/plain", - headers: { - "Content-Type": "text/plain", - }, - requireHeaders: [ - "Content-Length" - ], - params: { payload: "rawstring" }, - method: "POST", - protocol: "aws.protocols#restJson1" - } -]) -@httpResponseTests([ - { - id: "RestJsonStringPayloadResponse2", - headers: { "Content-Type": "text/plain" }, - body: "rawstring", - bodyMediaType: "text/plain", - params: { payload: "rawstring" }, - protocol: "aws.protocols#restJson1", - code: 200 - } -]) -@httpMalformedRequestTests([ - { - id: "RestJsonStringPayloadNoContentType2", - documentation: "Serializes a string in the HTTP payload without a content-type header", - protocol: "aws.protocols#restJson1", - request: { - method: "POST", - uri: "/StringPayload2", - body: "rawstring", - // We expect a `Content-Type` header but none was provided. - }, - response: { - code: 415, - headers: { - "x-amzn-errortype": "UnsupportedMediaTypeException" - } - }, - tags: [ "content-type" ] - }, - { - id: "RestJsonStringPayloadWrongContentType2", - documentation: "Serializes a string in the HTTP payload without the expected content-type header", - protocol: "aws.protocols#restJson1", - request: { - method: "POST", - uri: "/StringPayload2", - body: "rawstring", - headers: { - // We expect `text/plain`. - "Content-Type": "application/json", - }, - }, - response: { - code: 415, - headers: { - "x-amzn-errortype": "UnsupportedMediaTypeException" - } - }, - tags: [ "content-type" ] - }, - { - id: "RestJsonStringPayloadUnsatisfiableAccept2", - documentation: "Serializes a string in the HTTP payload with an unstatisfiable accept header", - protocol: "aws.protocols#restJson1", - request: { - method: "POST", - uri: "/StringPayload2", - body: "rawstring", - headers: { - "Content-Type": "text/plain", - // We can't satisfy this requirement; the server will return `text/plain`. - "Accept": "application/json", - }, - }, - response: { - code: 406, - headers: { - "x-amzn-errortype": "NotAcceptableException" - } - }, - tags: [ "accept" ] - }, -]) -operation HttpStringPayload2 { - input: StringPayloadInput, - output: StringPayloadInput -} diff --git a/codegen-core/common-test-models/rest-json-extras.smithy b/codegen-core/common-test-models/rest-json-extras.smithy index df1d8992ac..01f095756a 100644 --- a/codegen-core/common-test-models/rest-json-extras.smithy +++ b/codegen-core/common-test-models/rest-json-extras.smithy @@ -66,13 +66,6 @@ service RestJsonExtras { CaseInsensitiveErrorOperation, EmptyStructWithContentOnWireOp, QueryPrecedence, - // TODO(https://github.com/smithy-lang/smithy/pull/2314) - HttpPayloadTraits2, - // TODO(https://github.com/smithy-lang/smithy/pull/2310) - MalformedContentTypeWithBody2, - // TODO(https://github.com/smithy-lang/smithy/pull/2315) - HttpEnumPayload2, - HttpStringPayload2, ], errors: [ExtraError] } diff --git a/codegen-core/common-test-models/rest-xml-extras.smithy b/codegen-core/common-test-models/rest-xml-extras.smithy deleted file mode 100644 index 5a47976009..0000000000 --- a/codegen-core/common-test-models/rest-xml-extras.smithy +++ /dev/null @@ -1,53 +0,0 @@ -$version: "2.0" - -namespace aws.protocoltests.restxml - -use aws.api#service -use aws.protocols#restXml -use smithy.test#httpRequestTests - -/// A REST XML service that sends XML requests and responses. -@service(sdkId: "Rest Xml Protocol") -@restXml -@title("Sample Rest Xml Protocol Service") -service RestXmlExtras { - version: "2024-04-15", - operations: [ - ContentTypeParameters - ] -} - -/// The example tests how servers must support requests -/// containing a `Content-Type` header with parameters. -@http(uri: "/ContentTypeParameters", method: "PUT") -operation ContentTypeParameters { - input: ContentTypeParametersInput, - output: ContentTypeParametersOutput -} - -apply ContentTypeParameters @httpRequestTests([ - { - id: "RestXmlMustSupportParametersInContentType", - documentation: "A server should ignore parameters added to the content type", - protocol: restXml, - method: "PUT", - headers: { - "Content-Type": "application/xml; charset=utf-8" - }, - uri: "/ContentTypeParameters", - body: "5", - bodyMediaType: "application/xml", - params: { - value: 5, - }, - appliesTo: "server" - } -]) - -@input -structure ContentTypeParametersInput { - value: Integer, -} - -@output -structure ContentTypeParametersOutput {} diff --git a/codegen-server-test/build.gradle.kts b/codegen-server-test/build.gradle.kts index 36d942c840..4134cdd039 100644 --- a/codegen-server-test/build.gradle.kts +++ b/codegen-server-test/build.gradle.kts @@ -63,16 +63,7 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels -> CodegenTest( "aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras", - imports = listOf( - "$commonModels/rest-json-extras.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2310): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2310.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2314): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2314.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2315): Can be deleted when consumed in next Smithy version. - // TODO(https://github.com/smithy-lang/smithy/pull/2331): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2315.smithy", - ), + imports = listOf("$commonModels/rest-json-extras.smithy"), ), CodegenTest( "aws.protocoltests.restjson.validation#RestJsonValidation", @@ -100,11 +91,6 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels -> "pokemon-service-awsjson-server-sdk", imports = listOf("$commonModels/pokemon-awsjson.smithy", "$commonModels/pokemon-common.smithy"), ), - CodegenTest( - "aws.protocoltests.restxml#RestXmlExtras", - "rest_xml_extras", - imports = listOf("$commonModels/rest-xml-extras.smithy"), - ), ) } diff --git a/codegen-server-test/python/build.gradle.kts b/codegen-server-test/python/build.gradle.kts index 2cfe8c5f99..b6ee22147a 100644 --- a/codegen-server-test/python/build.gradle.kts +++ b/codegen-server-test/python/build.gradle.kts @@ -60,15 +60,7 @@ val allCodegenTests = "../../codegen-core/common-test-models".let { commonModels CodegenTest( "aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras", - imports = listOf( - "$commonModels/rest-json-extras.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2310): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2310.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2314): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2314.smithy", - // TODO(https://github.com/smithy-lang/smithy/pull/2315): Can be deleted when consumed in next Smithy version. - "$commonModels/rest-json-extras-2315.smithy", - ), + imports = listOf("$commonModels/rest-json-extras.smithy"), ), // TODO(https://github.com/smithy-lang/smithy-rs/issues/2477) // CodegenTest( 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 cb03181d7c..cbcbca16e3 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 @@ -68,9 +68,6 @@ class ServerProtocolTestGenerator( FailingTest.RequestTest(REST_JSON, "RestJsonEndpointTrait"), FailingTest.RequestTest(REST_JSON, "RestJsonEndpointTraitWithHostLabel"), FailingTest.RequestTest(REST_JSON, "RestJsonOmitsEmptyListQueryValues"), - // TODO(https://github.com/smithy-lang/smithy/pull/2315): Can be deleted when fixed tests are consumed in next Smithy version - FailingTest.RequestTest(REST_JSON, "RestJsonEnumPayloadRequest"), - FailingTest.RequestTest(REST_JSON, "RestJsonStringPayloadRequest"), // Tests involving `@range` on floats. // Pending resolution from the Smithy team, see https://github.com/smithy-lang/smithy-rs/issues/2007. FailingTest.MalformedRequestTest(REST_JSON_VALIDATION, "RestJsonMalformedRangeFloat_case0"), @@ -141,12 +138,17 @@ class ServerProtocolTestGenerator( // These tests are broken because they are missing a target header. FailingTest.RequestTest(AWS_JSON_10, "AwsJson10ServerPopulatesNestedDefaultsWhenMissingInRequestBody"), FailingTest.RequestTest(AWS_JSON_10, "AwsJson10ServerPopulatesDefaultsWhenMissingInRequestBody"), - // Response defaults are not set when builders are not used https://github.com/smithy-lang/smithy-rs/issues/3339 + // For the following 4 tests, response defaults are not set when builders are not used + // https://github.com/smithy-lang/smithy-rs/issues/3339 FailingTest.ResponseTest(AWS_JSON_10, "AwsJson10ServerPopulatesDefaultsInResponseWhenMissingInParams"), FailingTest.ResponseTest( AWS_JSON_10, "AwsJson10ServerPopulatesNestedDefaultValuesWhenMissingInInResponseParams", ), + FailingTest.ResponseTest(REST_JSON, "RestJsonServerPopulatesDefaultsInResponseWhenMissingInParams"), + FailingTest.ResponseTest(REST_JSON, "RestJsonServerPopulatesNestedDefaultValuesWhenMissingInInResponseParams"), + // TODO(https://github.com/smithy-lang/smithy-rs/issues/3735): Null `Document` may come through a request even though its shape is `@required` + FailingTest.RequestTest(REST_JSON, "RestJsonServerPopulatesDefaultsWhenMissingInRequestBody"), ) private val BrokenTests: diff --git a/gradle.properties b/gradle.properties index 3180aa95ff..b08522207d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ kotlin.code.style=official # codegen smithyGradlePluginVersion=0.9.0 -smithyVersion=1.49.0 +smithyVersion=1.50.0 allowLocalDeps=false # kotlin