From 32810f4dbb436f2e53b4f12d3e28a20ecaa0d9a7 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Wed, 11 Aug 2021 16:34:12 -0700 Subject: [PATCH 1/8] Cause AWS codegen to be published as a module. Add docs for generating service clients. --- .../build.gradle.kts | 19 +++ docs/generate-smithy-client.md | 113 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 docs/generate-smithy-client.md diff --git a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts index de5ec34670c..87e80c1ed70 100644 --- a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts +++ b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts @@ -5,6 +5,7 @@ plugins { kotlin("jvm") jacoco + `maven-publish` } val sdkVersion: String by project @@ -89,3 +90,21 @@ tasks.jacocoTestReport { // Always run the jacoco test report after testing. tasks["test"].finalizedBy(tasks["jacocoTestReport"]) + +val sourcesJar by tasks.creating(Jar::class) { + group = "publishing" + description = "Assembles Kotlin sources jar" + classifier = "sources" + from(sourceSets.getByName("main").allSource) +} + +publishing { + publications { + create("codegen") { + from(components["java"]) + artifact(sourcesJar) + } + } +} + +apply(from = rootProject.file("gradle/publish.gradle")) \ No newline at end of file diff --git a/docs/generate-smithy-client.md b/docs/generate-smithy-client.md new file mode 100644 index 00000000000..451ee0e7d08 --- /dev/null +++ b/docs/generate-smithy-client.md @@ -0,0 +1,113 @@ +# Generating a Kotlin Client from a Smithy Model + +## Overview + +This page covers how to generate a Kotlin client from any valid Smithy model. This generated Kotlin client could then be used to interact with a service instance from a Kotlin program. The Kotlin codegen is under active development and there remains several details that must be implemented before this approach can be used to create a fully functional client. However, using the code generator can give insights into how API models translate into working Kotlin code that service customers may interact with in the future. + +### Limitations + +* The generated project requires some additions to the Gradle build file in order to successfully build the project (covered below). +* AWS-specific logic will be included in the generated client that should be disregarded. In a future release this will be fixed. For now please ignore AWS specific logic such as AWS regions. +* Until Brazil integration is released, there is no way of producing a complete model from a dependency closure of several model partials spread across Brazil packages. You'll need to include all model dependencies directly in a local project. + +### Prerequisites + +* Intellij IDE installed locally +* Kotlin AWS SDK installed locally (local maven repo) +* A valid Smithy model + +## Steps + +1. Create a new Intellij Kotlin project, accepting defaults. +2. Add the following lines to the already generated Gradle `build.gradle.kts` file: + ```kotlin + plugins { + ... + id("software.amazon.smithy").version("0.5.3") + } + ``` + ```kotlin + repositories { + ... + mavenLocal() + } + ``` + ```kotlin + dependencies { + ... + implementation("software.amazon.smithy:smithy-aws-kotlin-codegen:") + } + ``` +3. Add your model file(s) into a new directory at the root of your project called `model`. +4. Add a `smithy-build.json` file into the root of your project. Substitute ``, ``, and `` for literals from your model and service: + ```json + { + "version": "1.0", + "plugins": { + "kotlin-codegen": { + "service": "#", + "package": { + "name": "", + "version": "", + "description": "" + }, + "sdkId": "", + "build": { + "generateDefaultBuildFiles": true + } + }} + } + ``` +5. Refresh the project model and run the `build` Gradle task to generate the service client. +6. Look in `build/smithyprojections//source/kotlin-codegen` for a generated Gradle project of the Kotlin client. + +## Appendix + +### 1. Sample Project File Tree + +``` +├── build.gradle.kts +├── gradle +│   └── wrapper +│   ├── gradle-wrapper.jar +│   └── gradle-wrapper.properties +├── gradle.properties +├── gradlew +├── gradlew.bat +├── model +│   ├── exceptions.smithy +│   ├── ids.smithy +│   └── main.smithy +├── settings.gradle.kts +└── smithy-build.json +``` + +### 2. Updating the Generated Project to Build the Client + +1. Open the generated client in an Intellij instance +2. Add an empty `settings.gradle.kts` file in the project root +3. Add the Kotlin version in the plugin declaration. For example if Kotlin 1.5.10 is the latest version: + ```kotlin + plugins { + kotlin("jvm") version "1.5.10" + } + ``` +4. Add repositories section: + ```kotlin + repositories { + mavenLocal() + mavenCentral() + } + ``` +5. Disable internal annotation guards: + ```kotlin + kotlin.sourceSets.all { + listOf( + "aws.smithy.kotlin.runtime.util.InternalApi", + "aws.sdk.kotlin.runtime.InternalSdkApi" + ).forEach { languageSettings.useExperimentalAnnotation(it) } + } + ``` +6. The client should now build successfully. + + From 910b777a5103fe4d04b11cbbd82744739a2f8ec3 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Thu, 19 Aug 2021 17:31:20 -0700 Subject: [PATCH 2/8] Predicate publishing on group based on PR feedback --- .../build.gradle.kts | 15 ++-- gradle/publish.gradle | 87 ++++++++++--------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts index 0d943268c1b..787e329a007 100644 --- a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts +++ b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts @@ -98,11 +98,16 @@ val sourcesJar by tasks.creating(Jar::class) { from(sourceSets.getByName("main").allSource) } -publishing { - publications { - create("codegen") { - from(components["java"]) - artifact(sourcesJar) +if ( + !project.hasProperty("publishGroupName") || + group.toString().startsWith(project.property("publishGroupName") as String) +) { + publishing { + publications { + create("codegen") { + from(components["java"]) + artifact(sourcesJar) + } } } } diff --git a/gradle/publish.gradle b/gradle/publish.gradle index f7d1aca7f3f..1ca2c72a533 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -12,56 +12,61 @@ tasks.register("javadocJar", Jar) { from() } -publishing { - repositories { - maven { name = "testLocal"; url = "$rootProject.buildDir/m2" } - maven { - name = "awsCodeArtifact" - url = project.findProperty("codeartifact.url") - credentials { - username = "aws" - password = project.findProperty("codeartifact.token") ?: System.getenv("CODEARTIFACT_TOKEN") +if ( + !project.hasProperty("publishGroupName") || + group.toString().startsWith(project.property("publishGroupName") as String) +) { + publishing { + repositories { + maven { name = "testLocal"; url = "$rootProject.buildDir/m2" } + maven { + name = "awsCodeArtifact" + url = project.findProperty("codeartifact.url") + credentials { + username = "aws" + password = project.findProperty("codeartifact.token") ?: System.getenv("CODEARTIFACT_TOKEN") + } } } - } - publications.all { - project.afterEvaluate { - pom { - name = project.name - description = project.description - url = "https://github.com/awslabs/aws-sdk-kotlin" - licenses { - license { - name = "The Apache License, Version 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + publications.all { + project.afterEvaluate { + pom { + name = project.name + description = project.description + url = "https://github.com/awslabs/aws-sdk-kotlin" + licenses { + license { + name = "The Apache License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } } - } - developers { - developer { - id = "aws-sdk-kotlin" - name = "AWS SDK Kotlin Team" - // TODO - team email? + developers { + developer { + id = "aws-sdk-kotlin" + name = "AWS SDK Kotlin Team" + // TODO - team email? + } + } + scm { + connection = "scm:git:git://github.com/awslabs/aws-sdk-kotlin.git" + developerConnection = "scm:git:ssh://github.com/awslabs/aws-sdk-kotlin.git" + url = "https://github.com/awslabs/aws-sdk-kotlin" } - } - scm { - connection = "scm:git:git://github.com/awslabs/aws-sdk-kotlin.git" - developerConnection = "scm:git:ssh://github.com/awslabs/aws-sdk-kotlin.git" - url = "https://github.com/awslabs/aws-sdk-kotlin" - } - artifact(tasks["javadocJar"]) + artifact(tasks["javadocJar"]) + } } } - } - if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { - signing { - useInMemoryPgpKeys( - (String) project.property("signingKey"), - (String) project.property("signingPassword") - ) - sign(publications) + if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { + signing { + useInMemoryPgpKeys( + (String) project.property("signingKey"), + (String) project.property("signingPassword") + ) + sign(publications) + } } } } From 44dc8f3dca22b0aef27e99baca1c0377740dac22 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Thu, 19 Aug 2021 17:57:37 -0700 Subject: [PATCH 3/8] Fixes from testing --- .../build.gradle.kts | 4 +- gradle/publish.gradle | 62 +++++++++---------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts index 787e329a007..dee64ffa2af 100644 --- a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts +++ b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts @@ -110,6 +110,6 @@ if ( } } } -} -apply(from = rootProject.file("gradle/publish.gradle")) \ No newline at end of file + apply(from = rootProject.file("gradle/publish.gradle")) +} \ No newline at end of file diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 1ca2c72a533..f3b04343461 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -3,34 +3,32 @@ * SPDX-License-Identifier: Apache-2.0. */ -apply plugin: 'maven-publish' -apply plugin: 'signing' - // FIXME: Create a real "javadoc" JAR from the Dokka output tasks.register("javadocJar", Jar) { archiveClassifier.set("javadoc") from() } -if ( - !project.hasProperty("publishGroupName") || - group.toString().startsWith(project.property("publishGroupName") as String) -) { - publishing { - repositories { - maven { name = "testLocal"; url = "$rootProject.buildDir/m2" } - maven { - name = "awsCodeArtifact" - url = project.findProperty("codeartifact.url") - credentials { - username = "aws" - password = project.findProperty("codeartifact.token") ?: System.getenv("CODEARTIFACT_TOKEN") +project.afterEvaluate { + String publishGroupName = project.findProperty("publishGroupName") + if (publishGroupName == null || project.group.startsWith(publishGroupName)) { + apply plugin: 'maven-publish' + apply plugin: 'signing' + + publishing { + repositories { + maven { name = "testLocal"; url = "$rootProject.buildDir/m2" } + maven { + name = "awsCodeArtifact" + url = project.findProperty("codeartifact.url") + credentials { + username = "aws" + password = project.findProperty("codeartifact.token") ?: System.getenv("CODEARTIFACT_TOKEN") + } } } - } - publications.all { - project.afterEvaluate { + publications.all { pom { name = project.name description = project.description @@ -57,21 +55,21 @@ if ( artifact(tasks["javadocJar"]) } } - } - if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { - signing { - useInMemoryPgpKeys( - (String) project.property("signingKey"), - (String) project.property("signingPassword") - ) - sign(publications) + if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { + signing { + useInMemoryPgpKeys( + (String) project.property("signingKey"), + (String) project.property("signingPassword") + ) + sign(publications) + } } } - } -} -tasks.register('publishToAwsCodeArtifact') { - dependsOn 'publishAllPublicationsToAwsCodeArtifactRepository' - group 'publishing' + tasks.register('publishToAwsCodeArtifact') { + dependsOn 'publishAllPublicationsToAwsCodeArtifactRepository' + group 'publishing' + } + } } From 3666e79117c0f2b0ce797a54c6a808a8cab88b89 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Fri, 20 Aug 2021 09:07:28 -0700 Subject: [PATCH 4/8] More fixes from PR feedback --- build.gradle.kts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 50bccb76790..bc8c76edb7e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,8 +8,6 @@ plugins { id("io.github.gradle-nexus.publish-plugin") version "1.1.0" } -group = "aws.sdk.kotlin" - dependencies { dokkaPlugin(project(":dokka-aws")) } @@ -82,9 +80,15 @@ tasks.dokkaHtmlMultiModule { removeChildTasks(excludeFromDocumentation) } -if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) { +if ( + project.hasProperty("sonatypeUsername") && + project.hasProperty("sonatypePassword") && + project.hasProperty("publishGroupName") +) { apply(plugin = "io.github.gradle-nexus.publish-plugin") + group = project.property("publishGroupName") as String + nexusPublishing { repositories { create("awsNexus") { From fad86af3fdb97bcb5bd12568ac06bf6cf81a5fd0 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Fri, 20 Aug 2021 09:12:38 -0700 Subject: [PATCH 5/8] make change consistent with other build files --- build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index bc8c76edb7e..2f094bf4f7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -87,7 +87,8 @@ if ( ) { apply(plugin = "io.github.gradle-nexus.publish-plugin") - group = project.property("publishGroupName") as String + val publishGroupName = project.property("publishGroupName") as String + group = publishGroupName nexusPublishing { repositories { From 9def6262a15da1e479c056aafdbef4d2147fdf1d Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Fri, 20 Aug 2021 13:58:38 -0700 Subject: [PATCH 6/8] Reduce unnecessary build changes based on PR feedback Create code sample project with weather example Update docs and dependencies --- docs/generate-smithy-client.md | 113 ------------------ docs/howto/client-generator.md | 84 +++++++++++++ examples/build.gradle.kts | 10 +- examples/client-generator/build.gradle.kts | 11 ++ .../model/weather-service.smithy | 111 +++++++++++++++++ examples/client-generator/smithy-build.json | 21 ++++ examples/settings.gradle.kts | 1 + 7 files changed, 230 insertions(+), 121 deletions(-) delete mode 100644 docs/generate-smithy-client.md create mode 100644 docs/howto/client-generator.md create mode 100644 examples/client-generator/build.gradle.kts create mode 100644 examples/client-generator/model/weather-service.smithy create mode 100644 examples/client-generator/smithy-build.json diff --git a/docs/generate-smithy-client.md b/docs/generate-smithy-client.md deleted file mode 100644 index 451ee0e7d08..00000000000 --- a/docs/generate-smithy-client.md +++ /dev/null @@ -1,113 +0,0 @@ -# Generating a Kotlin Client from a Smithy Model - -## Overview - -This page covers how to generate a Kotlin client from any valid Smithy model. This generated Kotlin client could then be used to interact with a service instance from a Kotlin program. The Kotlin codegen is under active development and there remains several details that must be implemented before this approach can be used to create a fully functional client. However, using the code generator can give insights into how API models translate into working Kotlin code that service customers may interact with in the future. - -### Limitations - -* The generated project requires some additions to the Gradle build file in order to successfully build the project (covered below). -* AWS-specific logic will be included in the generated client that should be disregarded. In a future release this will be fixed. For now please ignore AWS specific logic such as AWS regions. -* Until Brazil integration is released, there is no way of producing a complete model from a dependency closure of several model partials spread across Brazil packages. You'll need to include all model dependencies directly in a local project. - -### Prerequisites - -* Intellij IDE installed locally -* Kotlin AWS SDK installed locally (local maven repo) -* A valid Smithy model - -## Steps - -1. Create a new Intellij Kotlin project, accepting defaults. -2. Add the following lines to the already generated Gradle `build.gradle.kts` file: - ```kotlin - plugins { - ... - id("software.amazon.smithy").version("0.5.3") - } - ``` - ```kotlin - repositories { - ... - mavenLocal() - } - ``` - ```kotlin - dependencies { - ... - implementation("software.amazon.smithy:smithy-aws-kotlin-codegen:") - } - ``` -3. Add your model file(s) into a new directory at the root of your project called `model`. -4. Add a `smithy-build.json` file into the root of your project. Substitute ``, ``, and `` for literals from your model and service: - ```json - { - "version": "1.0", - "plugins": { - "kotlin-codegen": { - "service": "#", - "package": { - "name": "", - "version": "", - "description": "" - }, - "sdkId": "", - "build": { - "generateDefaultBuildFiles": true - } - }} - } - ``` -5. Refresh the project model and run the `build` Gradle task to generate the service client. -6. Look in `build/smithyprojections//source/kotlin-codegen` for a generated Gradle project of the Kotlin client. - -## Appendix - -### 1. Sample Project File Tree - -``` -├── build.gradle.kts -├── gradle -│   └── wrapper -│   ├── gradle-wrapper.jar -│   └── gradle-wrapper.properties -├── gradle.properties -├── gradlew -├── gradlew.bat -├── model -│   ├── exceptions.smithy -│   ├── ids.smithy -│   └── main.smithy -├── settings.gradle.kts -└── smithy-build.json -``` - -### 2. Updating the Generated Project to Build the Client - -1. Open the generated client in an Intellij instance -2. Add an empty `settings.gradle.kts` file in the project root -3. Add the Kotlin version in the plugin declaration. For example if Kotlin 1.5.10 is the latest version: - ```kotlin - plugins { - kotlin("jvm") version "1.5.10" - } - ``` -4. Add repositories section: - ```kotlin - repositories { - mavenLocal() - mavenCentral() - } - ``` -5. Disable internal annotation guards: - ```kotlin - kotlin.sourceSets.all { - listOf( - "aws.smithy.kotlin.runtime.util.InternalApi", - "aws.sdk.kotlin.runtime.InternalSdkApi" - ).forEach { languageSettings.useExperimentalAnnotation(it) } - } - ``` -6. The client should now build successfully. - - diff --git a/docs/howto/client-generator.md b/docs/howto/client-generator.md new file mode 100644 index 00000000000..2e6c1d753cd --- /dev/null +++ b/docs/howto/client-generator.md @@ -0,0 +1,84 @@ +# Generating a Kotlin Client from a Smithy Model + +## Overview + +This page covers how to generate a Kotlin client from any valid Smithy model. This generated Kotlin client could then be used to interact with a service instance from a Kotlin program. The Kotlin codegen is under active development and there remains several details that must be implemented before this approach can be used to create a fully functional client. However, using the code generator can give insights into how API models translate into working Kotlin code that service customers may interact with in the future. + +### Limitations + +* The generated project requires some additions to the Gradle build file in order to successfully build the project (covered below). +* AWS-specific logic will be included in the generated client that should be disregarded. In a future release this will be fixed. For now please ignore AWS specific logic such as AWS regions. +* You'll need to include all model dependencies directly in a local project. + +### Prerequisites + +* Intellij IDE installed locally +* Kotlin AWS SDK installed locally (local maven repo) +* A valid Smithy model + +## Steps + +The following steps will create a project that will codegen a client when built. Either follow these steps or check out the example provided in `/examples/client-generator`. + +1. Create a new Intellij Kotlin project, accepting defaults. +2. Add the following lines to the already generated Gradle `build.gradle.kts` file: + ```kotlin + plugins { + ... + id("software.amazon.smithy").version("0.5.3") + } + ``` + ```kotlin + dependencies { + ... + // NOTE: More smithy dependencies may be required depending on what's referenced by your API models. + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") + } + ``` +3. Add your model file(s) into a new directory at the root of your project called `model`. + 1. Add a `smithy-build.json` file into the root of your project. Substitute ``, ``, and `` for literals from your model and service: + ```json + { + "version": "1.0", + "plugins": { + "kotlin-codegen": { + "service": "#", + "package": { + "name": "", + "version": "", + "description": "" + }, + "sdkId": "", + "build": { + "generateDefaultBuildFiles": true, + "optInAnnotations": [ + "aws.smithy.kotlin.runtime.util.InternalApi", + "aws.sdk.kotlin.runtime.InternalSdkApi" + ], + "rootProject": true + } + }} + } + ``` +4. Run the `build` Gradle task to generate the service client. +5. Look in `build/smithyprojections//source/kotlin-codegen` for a generated Gradle project of the Kotlin client. + +## Appendix + +### 1. Sample Project File Tree + +The following illustrates the files added or changed as part of this exercise: + +``` +. +├── build.gradle.kts +├── model +│   ├── errors.smithy +│   ├── main.smithy +│   ├── resources +│   │   ├── beer.smithy +│   │   ├── logo.smithy +│   │   └── review.smithy +│   └── validation.smithy +└── smithy-build.json +``` diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index ee693b68292..cdf2a4ee4f4 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,18 +1,12 @@ plugins { - kotlin("jvm") version "1.5.0" + kotlin("jvm") version "1.5.20" } allprojects { group = "aws.sdk.kotlin.example" - version = "0.3.0-SNAPSHOT" + version = "0.4.0-SNAPSHOT" repositories { - maven { - name = "kotlinSdkLocal" - url = uri(TODO("set your local repository path")) - // e.g. - //url = uri("file:///tmp/aws-sdk-kotlin-repo/m2") - } mavenCentral() } } diff --git a/examples/client-generator/build.gradle.kts b/examples/client-generator/build.gradle.kts new file mode 100644 index 00000000000..2cc266e33fb --- /dev/null +++ b/examples/client-generator/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + kotlin("jvm") + id("software.amazon.smithy").version("0.5.3") +} + +val awsSdkKotlinVersion: String by project + +dependencies { + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:$awsSdkKotlinVersion") + // NOTE: More smithy dependencies may be required depending on what's referenced by your API models. +} diff --git a/examples/client-generator/model/weather-service.smithy b/examples/client-generator/model/weather-service.smithy new file mode 100644 index 00000000000..cfcd21f9471 --- /dev/null +++ b/examples/client-generator/model/weather-service.smithy @@ -0,0 +1,111 @@ +namespace example.weather + +use aws.protocols#awsJson1_0 +use aws.api#service + +@service(sdkId: "Weather") +@awsJson1_0 +service Weather { + version: "2006-03-01", + resources: [City], + operations: [GetCurrentTime] +} + +resource City { + identifiers: { cityId: CityId }, + read: GetCity, + list: ListCities, + resources: [Forecast] +} + +resource Forecast { + identifiers: { cityId: CityId }, + read: GetForecast +} + +// Pattern is a trait. +@pattern("^[A-Za-z0-9 ]+$") +string CityId + +@readonly +operation GetCurrentTime { + output: GetCurrentTimeOutput +} + +structure GetCurrentTimeOutput { + time: smithy.api#Timestamp +} + +@readonly +operation GetForecast { + input: GetForecastInput, + output: GetForecastOutput, + errors: [NoSuchResource] +} + +structure GetForecastInput { + @required cityId: CityId +} + +structure GetForecastOutput { + @required chanceOfRain: smithy.api#Float, + @required low: smithy.api#Integer, + @required high: smithy.api#Integer +} + +@readonly +operation GetCity { + input: GetCityInput, + output: GetCityOutput, + errors: [NoSuchResource] +} + +structure GetCityInput { + @required cityId: CityId +} + +structure GetCityOutput { + @required name: smithy.api#String, + @required coordinates: CityCoordinates +} + +@readonly +@paginated(inputToken: "nextToken", outputToken: "nextToken", + pageSize: "pageSize", items: "items") +operation ListCities { + input: ListCitiesInput, + output: ListCitiesOutput +} + +structure ListCitiesInput { + nextToken: smithy.api#String, + pageSize: smithy.api#Integer +} + +// Traits can be applied outside of the definition. +apply ListCitiesInput @documentation("hello!") + +structure ListCitiesOutput { + nextToken: smithy.api#String, + @required items: CitySummaries +} + +structure CityCoordinates { + @required latitude: smithy.api#Float, + @required longitude: smithy.api#Float +} + +@error("client") +structure NoSuchResource { + @required resourceType: smithy.api#String +} + +list CitySummaries { + member: CitySummary +} + +@references([{resource: City}]) +structure CitySummary { + @required cityId: CityId, + @required name: smithy.api#String +} diff --git a/examples/client-generator/smithy-build.json b/examples/client-generator/smithy-build.json new file mode 100644 index 00000000000..25ee90ff4d6 --- /dev/null +++ b/examples/client-generator/smithy-build.json @@ -0,0 +1,21 @@ +{ + "version": "1.0", + "plugins": { + "kotlin-codegen": { + "service": "example.weather#Weather", + "package": { + "name": "example.weather", + "version": "0.1.0", + "description": "Weather" + }, + "sdkId": "Weather", + "build": { + "generateDefaultBuildFiles": true, + "optInAnnotations": [ + "aws.smithy.kotlin.runtime.util.InternalApi", + "aws.sdk.kotlin.runtime.InternalSdkApi" + ], + "rootProject": true + } + }} +} \ No newline at end of file diff --git a/examples/settings.gradle.kts b/examples/settings.gradle.kts index 23281e6fb9f..1fe917a0ae6 100644 --- a/examples/settings.gradle.kts +++ b/examples/settings.gradle.kts @@ -1,4 +1,5 @@ rootProject.name = "aws-sdk-kotlin-examples" +include(":client-generator") include(":dynamodb-movies") include(":s3-media-ingestion") From 274017751abcf499ecf456abeece09ba98252566 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Fri, 20 Aug 2021 14:02:26 -0700 Subject: [PATCH 7/8] cleanup --- docs/howto/client-generator.md | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/docs/howto/client-generator.md b/docs/howto/client-generator.md index 2e6c1d753cd..52b749490e4 100644 --- a/docs/howto/client-generator.md +++ b/docs/howto/client-generator.md @@ -62,23 +62,3 @@ The following steps will create a project that will codegen a client when built. ``` 4. Run the `build` Gradle task to generate the service client. 5. Look in `build/smithyprojections//source/kotlin-codegen` for a generated Gradle project of the Kotlin client. - -## Appendix - -### 1. Sample Project File Tree - -The following illustrates the files added or changed as part of this exercise: - -``` -. -├── build.gradle.kts -├── model -│   ├── errors.smithy -│   ├── main.smithy -│   ├── resources -│   │   ├── beer.smithy -│   │   ├── logo.smithy -│   │   └── review.smithy -│   └── validation.smithy -└── smithy-build.json -``` From f69402273cd350428ae3c9e9d89b9c3a66b5f066 Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Fri, 20 Aug 2021 15:08:11 -0700 Subject: [PATCH 8/8] Add mavenLocal from PR feedback --- examples/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index cdf2a4ee4f4..4a05c1abdc6 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -7,6 +7,7 @@ allprojects { version = "0.4.0-SNAPSHOT" repositories { + mavenLocal() mavenCentral() } }