-
Notifications
You must be signed in to change notification settings - Fork 55
Enable general client generation from smithy models #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
32810f4
Cause AWS codegen to be published as a module. Add docs for generati…
kggilmer b28c2a7
Merge branch 'main' into feat-smithy-client-generation
kggilmer 8187c28
Merge branch 'main' into feat-smithy-client-generation
kggilmer 910b777
Predicate publishing on group based on PR feedback
kggilmer 44dc8f3
Fixes from testing
kggilmer 3666e79
More fixes from PR feedback
kggilmer fad86af
make change consistent with other build files
kggilmer ee707d8
Merge branch 'main' into feat-smithy-client-generation
kggilmer 9def626
Reduce unnecessary build changes based on PR feedback
kggilmer 2740177
cleanup
kggilmer f694022
Add mavenLocal from PR feedback
kggilmer 44ed1f2
Merge branch 'main' into feat-smithy-client-generation
kggilmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # 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:<latest version>") | ||
| } | ||
| ``` | ||
| 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 `<namespace>`, `<service-name>`, and `<version>` for literals from your model and service: | ||
| ```json | ||
| { | ||
| "version": "1.0", | ||
| "plugins": { | ||
| "kotlin-codegen": { | ||
| "service": "<namespace>#<service-name>", | ||
| "package": { | ||
| "name": "<namespace>", | ||
| "version": "<version>", | ||
| "description": "<service-name>" | ||
| }, | ||
| "sdkId": "<service-name>", | ||
| "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/<project name>/source/kotlin-codegen` for a generated Gradle project of the Kotlin client. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,13 @@ | ||
| 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") | ||
| } | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| }} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| rootProject.name = "aws-sdk-kotlin-examples" | ||
|
|
||
| include(":client-generator") | ||
| include(":dynamodb-movies") | ||
| include(":s3-media-ingestion") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Do we want to leave
mavenLocal()here for local building/testing using the example projects?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, my assumption was that once we were public we wouldn't need this. What in particular will need a local dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline and added mavenLocal