Skip to content

Commit f239221

Browse files
authored
chore: generate client name according to sdkId (#2536)
* chore: generate client name according sdkid not model file name * chore: add option to disable protocol tests when generating clients * chore: new client generated at v3.0.0
1 parent 401c054 commit f239221

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

codegen/sdk-codegen/build.gradle.kts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16+
import software.amazon.smithy.model.Model
17+
import software.amazon.smithy.model.shapes.ServiceShape
1618
import software.amazon.smithy.model.node.Node
1719
import software.amazon.smithy.gradle.tasks.SmithyBuild
20+
import software.amazon.smithy.aws.traits.ServiceTrait
21+
import kotlin.streams.toList
22+
23+
buildscript {
24+
dependencies {
25+
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.5.1,2.0.0[")
26+
}
27+
}
1828

1929
plugins {
2030
id("software.amazon.smithy") version "0.5.3"
@@ -44,8 +54,24 @@ tasks.register("generate-smithy-build") {
4454
val modelsDirProp: String by project
4555
val models = project.file(modelsDirProp);
4656

47-
fileTree(models).filter { it.isFile }.files.forEach { file ->
48-
val (sdkId, version, remaining) = file.name.split(".")
57+
fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file ->
58+
val model = Model.assembler()
59+
.addImport(file.absolutePath)
60+
.assemble().result.get();
61+
val services = model.shapes(ServiceShape::class.javaObjectType).sorted().toList();
62+
if (services.size != 1) {
63+
throw Exception("There must be exactly one service in each aws model file, but found " +
64+
"${services.size} in ${file.name}: ${services.map { it.id }}");
65+
}
66+
val service = services[0]
67+
68+
val serviceTrait = service.getTrait(ServiceTrait::class.javaObjectType).get();
69+
70+
val sdkId = serviceTrait.sdkId
71+
.replace(" ", "-")
72+
.toLowerCase();
73+
val version = service.version.toLowerCase();
74+
4975
val clientName = sdkId.split("-").toTypedArray()
5076
.map { it.capitalize() }
5177
.joinToString(separator = " ")
@@ -59,7 +85,7 @@ tasks.register("generate-smithy-build") {
5985
.withMember("typescript-codegen", Node.objectNodeBuilder()
6086
.withMember("package", "@aws-sdk/client-" + sdkId.toLowerCase())
6187
// Note that this version is replaced by Lerna when publishing.
62-
.withMember("packageVersion", "1.0.0-rc.1")
88+
.withMember("packageVersion", "3.0.0")
6389
.withMember("packageJson", manifestOverwrites)
6490
.withMember("packageDescription", "AWS SDK for JavaScript "
6591
+ clientName + " Client for Node.js, Browser and React Native")

scripts/generate-clients/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const { prettifyCode } = require("./code-prettify");
1414
const SDK_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients"));
1515
const PROTOCOL_TESTS_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "protocol_tests"));
1616

17-
const { models, globs, output: clientsDir } = yargs
17+
const {
18+
models,
19+
globs,
20+
output: clientsDir,
21+
noProtocolTest,
22+
} = yargs
1823
.alias("m", "models")
1924
.string("m")
2025
.describe("m", "The path to directory with models.")
@@ -26,21 +31,24 @@ const { models, globs, output: clientsDir } = yargs
2631
.string("o")
2732
.describe("o", "The output directory for built clients")
2833
.default("o", SDK_CLIENTS_DIR)
34+
.alias("n", "noProtocolTest")
35+
.boolean("n")
36+
.describe("n", "Disable generating protocol test files")
2937
.help().argv;
3038

3139
(async () => {
3240
try {
3341
await generateClients(models || globs);
34-
await generateProtocolTests();
42+
if (!noProtocolTest) await generateProtocolTests();
3543

3644
await prettifyCode(CODE_GEN_SDK_OUTPUT_DIR);
37-
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
45+
if (!noProtocolTest) await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
3846

3947
await copyToClients(CODE_GEN_SDK_OUTPUT_DIR, clientsDir);
40-
await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);
48+
if (!noProtocolTest) await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);
4149

4250
emptyDirSync(CODE_GEN_SDK_OUTPUT_DIR);
43-
emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
51+
if (!noProtocolTest) emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
4452
emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);
4553

4654
rmdirSync(TEMP_CODE_GEN_INPUT_DIR);

0 commit comments

Comments
 (0)