From 0917deb1f40d26ff8b265a37eb06caf3274f426a Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Wed, 30 Jun 2021 16:59:46 -0700 Subject: [PATCH 1/3] chore: generate client name according sdkid not model file name --- codegen/sdk-codegen/build.gradle.kts | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/codegen/sdk-codegen/build.gradle.kts b/codegen/sdk-codegen/build.gradle.kts index 55004b2bb7845..dd2558e3b9f5a 100644 --- a/codegen/sdk-codegen/build.gradle.kts +++ b/codegen/sdk-codegen/build.gradle.kts @@ -13,8 +13,18 @@ * permissions and limitations under the License. */ +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.node.Node import software.amazon.smithy.gradle.tasks.SmithyBuild +import software.amazon.smithy.aws.traits.ServiceTrait +import kotlin.streams.toList + +buildscript { + dependencies { + "classpath"("software.amazon.smithy:smithy-aws-traits:[1.5.1,2.0.0[") + } +} plugins { id("software.amazon.smithy") version "0.5.3" @@ -44,8 +54,27 @@ tasks.register("generate-smithy-build") { val modelsDirProp: String by project val models = project.file(modelsDirProp); - fileTree(models).filter { it.isFile }.files.forEach { file -> - val (sdkId, version, remaining) = file.name.split(".") + fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file -> + val model = Model.assembler() + .addImport(file.absolutePath) + // Grab the result directly rather than worrying about checking for errors via unwrap. + // All we care about here is the service shape, any unchecked errors will be exposed + // as part of the actual build task done by the smithy gradle plugin. + .assemble().result.get(); + val services = model.shapes(ServiceShape::class.javaObjectType).sorted().toList(); + if (services.size != 1) { + throw Exception("There must be exactly one service in each aws model file, but found " + + "${services.size} in ${file.name}: ${services.map { it.id }}"); + } + val service = services[0] + + val serviceTrait = service.getTrait(ServiceTrait::class.javaObjectType).get(); + + val sdkId = serviceTrait.sdkId + .replace(" ", "-") + .toLowerCase(); + val version = service.version.toLowerCase(); + val clientName = sdkId.split("-").toTypedArray() .map { it.capitalize() } .joinToString(separator = " ") From 8ac142b8e550d5cf788bf118d5035fce56630d5c Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Wed, 30 Jun 2021 17:00:31 -0700 Subject: [PATCH 2/3] chore: add option to disable protocol tests when generating clients --- scripts/generate-clients/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/generate-clients/index.js b/scripts/generate-clients/index.js index eb99421c984df..e09695930028c 100644 --- a/scripts/generate-clients/index.js +++ b/scripts/generate-clients/index.js @@ -14,7 +14,12 @@ const { prettifyCode } = require("./code-prettify"); const SDK_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients")); const PROTOCOL_TESTS_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "protocol_tests")); -const { models, globs, output: clientsDir } = yargs +const { + models, + globs, + output: clientsDir, + noProtocolTest, +} = yargs .alias("m", "models") .string("m") .describe("m", "The path to directory with models.") @@ -26,21 +31,24 @@ const { models, globs, output: clientsDir } = yargs .string("o") .describe("o", "The output directory for built clients") .default("o", SDK_CLIENTS_DIR) + .alias("n", "noProtocolTest") + .boolean("n") + .describe("n", "Disable generating protocol test files") .help().argv; (async () => { try { await generateClients(models || globs); - await generateProtocolTests(); + if (!noProtocolTest) await generateProtocolTests(); await prettifyCode(CODE_GEN_SDK_OUTPUT_DIR); - await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR); + if (!noProtocolTest) await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR); await copyToClients(CODE_GEN_SDK_OUTPUT_DIR, clientsDir); - await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR); + if (!noProtocolTest) await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR); emptyDirSync(CODE_GEN_SDK_OUTPUT_DIR); - emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR); + if (!noProtocolTest) emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR); emptyDirSync(TEMP_CODE_GEN_INPUT_DIR); rmdirSync(TEMP_CODE_GEN_INPUT_DIR); From c8b2c45dcd0daecc538ce0d4df99c623c217e4a6 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Wed, 30 Jun 2021 17:03:21 -0700 Subject: [PATCH 3/3] chore: new client generated at v3.0.0 --- codegen/sdk-codegen/build.gradle.kts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/codegen/sdk-codegen/build.gradle.kts b/codegen/sdk-codegen/build.gradle.kts index dd2558e3b9f5a..8827e34ab1bdf 100644 --- a/codegen/sdk-codegen/build.gradle.kts +++ b/codegen/sdk-codegen/build.gradle.kts @@ -57,9 +57,6 @@ tasks.register("generate-smithy-build") { fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file -> val model = Model.assembler() .addImport(file.absolutePath) - // Grab the result directly rather than worrying about checking for errors via unwrap. - // All we care about here is the service shape, any unchecked errors will be exposed - // as part of the actual build task done by the smithy gradle plugin. .assemble().result.get(); val services = model.shapes(ServiceShape::class.javaObjectType).sorted().toList(); if (services.size != 1) { @@ -88,7 +85,7 @@ tasks.register("generate-smithy-build") { .withMember("typescript-codegen", Node.objectNodeBuilder() .withMember("package", "@aws-sdk/client-" + sdkId.toLowerCase()) // Note that this version is replaced by Lerna when publishing. - .withMember("packageVersion", "1.0.0-rc.1") + .withMember("packageVersion", "3.0.0") .withMember("packageJson", manifestOverwrites) .withMember("packageDescription", "AWS SDK for JavaScript " + clientName + " Client for Node.js, Browser and React Native")