From 7a70891565ab92f8df8fb265f8fbfdc9ecad5a9e Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 12 Aug 2026 09:33:25 -0500 Subject: [PATCH] Schema-based RestJSON in protocol tests only --- .../AWSSDKSwiftCLI/Resources/Package.Base.txt | 1 + Package.swift | 1 + codegen/Package.swift | 4 ++++ .../protocol-test-codegen-local/build.gradle.kts | 13 ++++++++----- codegen/protocol-test-codegen/build.gradle.kts | 13 +++++++------ ...tomizations.kt => AWSRestJSON1Customizations.kt} | 6 +++++- .../restjson/AWSRestJson1ProtocolGenerator.kt | 2 +- scripts/protogen.sh | 6 +++--- 8 files changed, 30 insertions(+), 16 deletions(-) rename codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/{RestJSONCustomizations.kt => AWSRestJSON1Customizations.kt} (58%) diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt index 0388b6005f6..9bb90fbbce0 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt @@ -21,6 +21,7 @@ extension Target.Dependency { static var Smithy: Self { .product(name: "Smithy", package: "smithy-swift") } static var SmithyAWSJSON: Self { .product(name: "SmithyAWSJSON", package: "smithy-swift") } static var SmithyRPCv2CBOR: Self { .product(name: "SmithyRPCv2CBOR", package: "smithy-swift") } + static var SmithyRestJSON1: Self { .product(name: "SmithyRestJSON1", package: "smithy-swift") } static var SmithyCBOR: Self { .product(name: "SmithyCBOR", package: "smithy-swift") } static var SmithyChecksumsAPI: Self { .product(name: "SmithyChecksumsAPI", package: "smithy-swift") } static var SmithyChecksums: Self { .product(name: "SmithyChecksums", package: "smithy-swift") } diff --git a/Package.swift b/Package.swift index 7e5132dddff..475ea807c6c 100644 --- a/Package.swift +++ b/Package.swift @@ -2223,6 +2223,7 @@ extension Target.Dependency { static var Smithy: Self { .product(name: "Smithy", package: "smithy-swift") } static var SmithyAWSJSON: Self { .product(name: "SmithyAWSJSON", package: "smithy-swift") } static var SmithyRPCv2CBOR: Self { .product(name: "SmithyRPCv2CBOR", package: "smithy-swift") } + static var SmithyRestJSON1: Self { .product(name: "SmithyRestJSON1", package: "smithy-swift") } static var SmithyCBOR: Self { .product(name: "SmithyCBOR", package: "smithy-swift") } static var SmithyChecksumsAPI: Self { .product(name: "SmithyChecksumsAPI", package: "smithy-swift") } static var SmithyChecksums: Self { .product(name: "SmithyChecksums", package: "smithy-swift") } diff --git a/codegen/Package.swift b/codegen/Package.swift index 372620c27f2..82ee67ec994 100644 --- a/codegen/Package.swift +++ b/codegen/Package.swift @@ -38,7 +38,9 @@ extension Target.Dependency { static var smithyWaitersAPI: Self { .product(name: "SmithyWaitersAPI", package: "smithy-swift") } static var smithyTestUtils: Self { .product(name: "SmithyTestUtil", package: "smithy-swift") } static var smithyStreams: Self { .product(name: "SmithyStreams", package: "smithy-swift") } + static var smithyAWSJSON: Self { .product(name: "SmithyAWSJSON", package: "smithy-swift") } static var smithyRPCv2CBOR: Self { .product(name: "SmithyRPCv2CBOR", package: "smithy-swift") } + static var smithyRestJSON1: Self { .product(name: "SmithyRestJSON1", package: "smithy-swift") } } // MARK: - Base Package @@ -108,7 +110,9 @@ private var protocolTestTargets: [Target] { dependencies: [ .clientRuntime, .awsClientRuntime, + .smithyAWSJSON, .smithyRPCv2CBOR, + .smithyRestJSON1, .smithyRetriesAPI, .smithyRetries, .smithy, diff --git a/codegen/protocol-test-codegen-local/build.gradle.kts b/codegen/protocol-test-codegen-local/build.gradle.kts index 74fb8fef898..4fb4e187eb2 100644 --- a/codegen/protocol-test-codegen-local/build.gradle.kts +++ b/codegen/protocol-test-codegen-local/build.gradle.kts @@ -27,11 +27,12 @@ dependencies { implementation(project(":smithy-aws-swift-codegen")) } -data class CodegenTest(val service: String, val module: String) +data class CodegenTest(val service: String, val module: String, val forceSchemaBased: Boolean = false) val codegenTests = listOf( CodegenTest( "aws.protocoltests.restjson#RestJsonExtras", - "rest_json_extras" + "rest_json_extras", + forceSchemaBased = true ), CodegenTest( "aws.protocoltests.query#AwsQueryExtras", @@ -39,7 +40,8 @@ val codegenTests = listOf( ), CodegenTest( "aws.protocoltests.eventstream#TestService", - "EventStream" + "EventStream", + forceSchemaBased = true ), CodegenTest( "aws.protocoltests.eventstream#RPCTestService", @@ -47,7 +49,8 @@ val codegenTests = listOf( ), CodegenTest( "aws.endpointtests.stringarray#EndpointStringArray", - "StringArrayEndpointParam" + "StringArrayEndpointParam", + forceSchemaBased = true ) ) @@ -74,7 +77,7 @@ fun generateSmithyBuild(tests: List): String { "rootProject": true }, "mergeModels": true, - "copyrightNotice": "//\n// Copyright Amazon.com Inc. or its affiliates.\n// All Rights Reserved.\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n\n// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n" + "copyrightNotice": "//\n// Copyright Amazon.com Inc. or its affiliates.\n// All Rights Reserved.\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n\n// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n"${if (it.forceSchemaBased) ",\n \"forceSchemaBased\": true" else ""} } } } diff --git a/codegen/protocol-test-codegen/build.gradle.kts b/codegen/protocol-test-codegen/build.gradle.kts index 8398785bda1..130b2ebaa08 100644 --- a/codegen/protocol-test-codegen/build.gradle.kts +++ b/codegen/protocol-test-codegen/build.gradle.kts @@ -31,8 +31,8 @@ val enabledProtocols = listOf( ProtocolTest("ec2-query", "aws.protocoltests.ec2#AwsEc2", "Ec2QueryTestSDK"), ProtocolTest("aws-json-10", "aws.protocoltests.json10#JsonRpc10", "AWSJson10TestSDK"), ProtocolTest("aws-json-11", "aws.protocoltests.json#JsonProtocol", "AWSJson11TestSDK"), - ProtocolTest("aws-restjson", "aws.protocoltests.restjson#RestJson", "AWSRestJsonTestSDK"), - ProtocolTest("aws-restjson-validation", "aws.protocoltests.restjson.validation#RestJsonValidation", "AWSRestJsonValidationTestSDK"), + ProtocolTest("aws-restjson", "aws.protocoltests.restjson#RestJson", "AWSRestJsonTestSDK", forceSchemaBased = true), + ProtocolTest("aws-restjson-validation", "aws.protocoltests.restjson.validation#RestJsonValidation", "AWSRestJsonValidationTestSDK", forceSchemaBased = true), ProtocolTest("rest-xml", "aws.protocoltests.restxml#RestXml", "RestXmlTestSDK"), ProtocolTest("rest-xml-xmlns", "aws.protocoltests.restxml.xmlns#RestXmlWithNamespace", "RestXmlWithNamespaceTestSDK"), ProtocolTest("aws-query", "aws.protocoltests.query#AwsQuery", "AWSQueryTestSDK"), @@ -42,8 +42,8 @@ val enabledProtocols = listOf( ProtocolTest("smithy-rpcv2-cbor-non-query-compat", "aws.protocoltests.rpcv2cbor#NonQueryCompatibleRpcV2Protocol", "RPCV2CBORTestNonQueryCompatSDK"), // service specific tests - ProtocolTest("apigateway", "com.amazonaws.apigateway#BackplaneControlService", "APIGatewayTestSDK"), - ProtocolTest("glacier", "com.amazonaws.glacier#Glacier", "GlacierTestSDK"), + ProtocolTest("apigateway", "com.amazonaws.apigateway#BackplaneControlService", "APIGatewayTestSDK", forceSchemaBased = true), + ProtocolTest("glacier", "com.amazonaws.glacier#Glacier", "GlacierTestSDK", forceSchemaBased = true), ProtocolTest("s3", "com.amazonaws.s3#AmazonS3", "S3TestSDK"), ProtocolTest("machinelearning", "com.amazonaws.machinelearning#AmazonML_20141212", "MachineLearningTestSDK"), ) @@ -83,7 +83,8 @@ enabledProtocols.forEach { data class ProtocolTest(val projectionName: String, val serviceShapeId: String, - val moduleName: String) { + val moduleName: String, + val forceSchemaBased: Boolean = false) { val packageName: String get() = projectionName.lowercase().filter { it.isLetterOrDigit() } } @@ -118,7 +119,7 @@ fun generateSmithyBuild(tests: List): String { "sdkId": "${ShapeId.from(test.serviceShapeId).name}", "swiftVersion": "5.9.0", "mergeModels": true, - "copyrightNotice": "//\n// Copyright Amazon.com Inc. or its affiliates.\n// All Rights Reserved.\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n\n// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n" + "copyrightNotice": "//\n// Copyright Amazon.com Inc. or its affiliates.\n// All Rights Reserved.\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n\n// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n"${if (test.forceSchemaBased) ",\n \"forceSchemaBased\": true" else ""} } } }""" diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/RestJSONCustomizations.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJSON1Customizations.kt similarity index 58% rename from codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/RestJSONCustomizations.kt rename to codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJSON1Customizations.kt index 21f2dd7d9db..f007589ed0b 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/RestJSONCustomizations.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJSON1Customizations.kt @@ -7,8 +7,12 @@ package software.amazon.smithy.aws.swift.codegen.protocols.restjson import software.amazon.smithy.aws.swift.codegen.AWSHTTPProtocolCustomizations import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes +import software.amazon.smithy.swift.codegen.swiftmodules.SmithyRestJson1Types -class RestJSONCustomizations : AWSHTTPProtocolCustomizations() { +class AWSRestJSON1Customizations : AWSHTTPProtocolCustomizations() { override val baseErrorSymbol: Symbol = ClientRuntimeTypes.RestJSON.RestJSONError + + override fun renderClientProtocol(writer: SwiftWriter): String = writer.format("\$N()", SmithyRestJson1Types.HTTPClientProtocol) } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJson1ProtocolGenerator.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJson1ProtocolGenerator.kt index 0a49ca6fc63..0821f0fa227 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJson1ProtocolGenerator.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJson1ProtocolGenerator.kt @@ -11,7 +11,7 @@ import software.amazon.smithy.swift.codegen.aws.protocols.restjson.RestJson1Prot class AWSRestJson1ProtocolGenerator : RestJson1ProtocolGenerator( - customizations = RestJSONCustomizations(), + customizations = AWSRestJSON1Customizations(), operationEndpointResolverMiddlewareFactory = { ctx, sym -> AWSOperationEndpointResolverMiddleware(ctx, sym) }, userAgentMiddlewareFactory = { ctx -> UserAgentMiddleware(ctx.settings) }, serviceErrorProtocolSymbolOverride = AWSClientRuntimeTypes.Core.AWSServiceError, diff --git a/scripts/protogen.sh b/scripts/protogen.sh index 3a8723accec..fa3c0f474b2 100755 --- a/scripts/protogen.sh +++ b/scripts/protogen.sh @@ -18,8 +18,8 @@ rm -rf codegen/protocol-test-codegen-local/build # Delete the generated Package.swift for protocol test packages so they may be seen in Xcode rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-restjson/swift-codegen/AWSRestJsonTestSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-restjson-validation/swift-codegen/AWSRestJsonValidationTestSDK/Package.swift -rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-10/swift-codegen/AWSJson1_0TestSDK/Package.swift -rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-11/swift-codegen/AWSJson1_1TestSDK/Package.swift +rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-10/swift-codegen/AWSJson10TestSDK/Package.swift +rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-11/swift-codegen/AWSJson11TestSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/rest-xml/swift-codegen/RestXmlTestSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/rest-xml-xmlns/swift-codegen/RestXmlWithNamespaceTestSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/ec2-query/swift-codegen/Ec2QueryTestSDK/Package.swift @@ -31,7 +31,7 @@ rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codege rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/smithy-rpcv2-cbor/swift-codegen/RPCV2CBORTestSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/smithy-rpcv2-cbor-non-query-compat/swift-codegen/RPCV2CBORTestNonQueryCompatSDK/Package.swift rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/smithy-rpcv2-cbor-query-compat/swift-codegen/RPCV2CBORTestQueryCompatSDK/Package.swift -rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-10-query-compat/swift-codegen/AWSJson1_0TestQueryCompatSDK/Package.swift +rm -f codegen/protocol-test-codegen/build/smithyprojections/protocol-test-codegen/aws-json-10-query-compat/swift-codegen/AWSJson10TestQueryCompatSDK/Package.swift # Now do the same for local protocol tests rm -f codegen/protocol-test-codegen-local/build/smithyprojections/protocol-test-codegen-local/rest_json_extras/swift-codegen/rest_json_extras/Package.swift