From 814aaf36737afca5afc0cd55eb2de878fa134d31 Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 10:18:41 -0700 Subject: [PATCH 01/10] add read me --- .../software/amazon/smithy/kotlin/codegen/service/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md new file mode 100644 index 000000000..37966e849 --- /dev/null +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -0,0 +1 @@ +This is README file \ No newline at end of file From e237145f1278f33b06b25c766b98af00c00bfa01 Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 11:05:37 -0700 Subject: [PATCH 02/10] read me --- .../smithy/kotlin/codegen/service/README.md | 180 +++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index 37966e849..e49f3a9ab 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -1 +1,179 @@ -This is README file \ No newline at end of file +# Smithy Kotlin Service Codegen (Ktor) + +## Overview + +This project extends **Smithy Kotlin** to generate **service-side code** from Smithy models, targeting the **Ktor** framework for server implementation. +It produces **complete service stubs**—including routing, serialization/deserialization, authentication, and validation—so developers can focus entirely on implementing business logic. + +While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. + +### Key Features +- **Automatic Service Stub Generation** from Smithy models +- **Protocol Support**: CBOR & JSON +- **Request Routing** generated from Smithy operations +- **Authentication**: Bearer, SigV4, SigV4A +- **Request Constraints & Validation** from Smithy traits +- **Error Handling** with a consistent JSON/CBOR envelope +- **Logging** with structured output for production readiness +- **Extensible Architecture** for alternative frameworks + +--- + +## Getting Started + +### 1. Build & Publish to Local Maven +From the project root, run: +```bash +./gradlew :codegen:smithy-kotlin-codegen:build +./gradlew publishToMavenLocal +``` + +--- + +### 2. Create a New Kotlin Project + +In your **`build.gradle.kts`**: + +```kotlin +plugins { +id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" // check for latest version +} + +repositories { +mavenLocal() +mavenCentral() +} + +dependencies { +smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") +implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") +implementation("software.amazon.smithy:smithy-model:") +implementation("software.amazon.smithy:smithy-build:") +implementation("software.amazon.smithy:smithy-aws-traits:") +} +``` + +--- + +### 3. Configure Smithy Build + +Create `smithy-build.json` in the same directory as `build.gradle.kts`: + +```json +{ +"version": "1.0", +"outputDirectory": "build/generated-src", +"plugins": { +"kotlin-codegen": { +"service": "com.demo#DemoService", +"package": { +"name": "com.demo.server", +"version": "1.0.0" +}, +"build": { +"rootProject": true, +"generateServiceProject": true, +"optInAnnotations": [ +"aws.smithy.kotlin.runtime.InternalApi", +"kotlinx.serialization.ExperimentalSerializationApi" +] +}, +"serviceStub": { +"framework": "ktor" +} +} +} +} +``` + +--- + +### 4. Define Your Smithy Model + +Create a `model` directory and add your `.smithy` files. +Example `model/greeter.smithy`: + +```smithy +$version: "2.0" +namespace com.demo + +use aws.protocols#restJson1 +use smithy.api#httpBearerAuth + +@restJson1 +@httpBearerAuth +service DemoService { +version: "1.0.0" +operations: [SayHello] +} + +@http(method: "POST", uri: "/greet", code: 201) +operation SayHello { +input: SayHelloInput +output: SayHelloOutput +errors: [CustomError] +} + +@input +structure SayHelloInput { +@required +@length(min: 3, max: 10) +name: String +@httpHeader("X-User-ID") +id: Integer +} + +@output +structure SayHelloOutput { +greeting: String +} + +@error("server") +@httpError(500) +structure CustomError { +msg: String +@httpHeader("X-User-error") +err: String +} +``` + +--- + +### 5. Generate the Service + +Run: +```bash +gradle build run +``` + +If you want to clean previously generated code: +```bash +gradle clean +``` + +--- + +### 6. Run the Service + +The generated service will be in the directory specified in `smithy-build.json` (`outputDirectory`). +You can start it by running: +```bash +gradle run +``` +By default, it listens on port **8080**. + +--- + +### 7. Adjust Service Configuration + +You can override runtime settings (such as port or HTTP engine) using command-line arguments: +```bash +gradle run --args="port 8000 engineFactory cio" +``` + +--- + +## Notes +- **Business Logic**: Implement your own logic in the generated operation handler interfaces. +- **Configuration**: Adjust port, engine, auth, and other settings via `ServiceFrameworkConfig` or CLI args. +- **Future Extensions**: Planned support for more serialization formats (JSON, XML) and AWS SigV4 auth. From cfc0bebded8f15ac8abca9118a788e659f4ca0ea Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 11:18:17 -0700 Subject: [PATCH 03/10] read me --- .../smithy/kotlin/codegen/service/README.md | 181 +++++++++++------- 1 file changed, 116 insertions(+), 65 deletions(-) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index e49f3a9ab..a94f9578e 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -7,22 +7,61 @@ It produces **complete service stubs**—including routing, serialization/deseri While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. -### Key Features -- **Automatic Service Stub Generation** from Smithy models -- **Protocol Support**: CBOR & JSON -- **Request Routing** generated from Smithy operations -- **Authentication**: Bearer, SigV4, SigV4A -- **Request Constraints & Validation** from Smithy traits -- **Error Handling** with a consistent JSON/CBOR envelope -- **Logging** with structured output for production readiness -- **Extensible Architecture** for alternative frameworks +--- + +## Feature Summary + +| **Features** | **Description** | +|---------------------------|-----------------| +| Service Framework | Abstracted service framework interface and base implementation with Ktor as the default backend | +| CBOR Protocol | Support for CBOR serialization / deserialization and CBOR protocol traits | +| Json Protocol | Support for Json serialization / deserialization and Json protocol traits | +| Routing | Per-operation routing generation with Ktor DSL; ties to handler and validation | +| Error Handler | Unified exception handling logic mapped to HTTP status codes and support for error trait | +| Authentication (bearer) | Bearer token authentication middleware with model-driven configuration | +| Logging | Structured logging setup | +| Constraints Checker | Validation logic generated from Smithy traits and invoked pre-handler | +| Unit Test | Covers serialization/deserialization, routing, validation, and integration tests | + +--- + +## Smithy Protocol Traits Support + +| **Traits** | **CBOR Protocol** | **Json Protocol** | +|--------------------------|-------------------|-------------------| +| http | Yes | Yes | +| httpError | Yes | Yes | +| httpHeader | Not supported | Yes | +| httpPrefixHeader | Not supported | Yes | +| httpLabel | Not supported | Yes | +| httpQuery | Not supported | Yes | +| httpQueryParams | Not supported | Yes | +| httpPayload | Not supported | Yes | +| jsonName | Not supported | Yes | +| timestampFormat | Not supported | Yes | +| httpChecksumRequired | Not supported | Not implemented yet | +| requestCompression | Not implemented yet | Not implemented yet | + +--- + +## Constraint Traits Support + +| **Traits** | **CBOR Protocol** | **Json Protocol** | +|-----------------|------------------------------|------------------------------| +| required | Yes | Yes | +| length | Yes | Yes | +| pattern | Yes | Yes | +| private | Yes (handled by Smithy) | Yes (handled by Smithy) | +| range | Yes | Yes | +| uniqueItems | Yes | Yes | +| idRef | Not implemented yet | Not implemented yet | --- ## Getting Started -### 1. Build & Publish to Local Maven -From the project root, run: +### Step 1: Build & Publish Codegen to Local Maven +First, in **this repository**, build and publish the code generator locally: ```bash ./gradlew :codegen:smithy-kotlin-codegen:build ./gradlew publishToMavenLocal @@ -30,65 +69,73 @@ From the project root, run: --- -### 2. Create a New Kotlin Project +### Step 2: Create a New Kotlin Project +Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. + +From this point forward, **all steps apply to the new Kotlin project** you just created. -In your **`build.gradle.kts`**: +--- + +### Step 3: Configure `build.gradle.kts` in the New Project ```kotlin plugins { -id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" // check for latest version + alias(libs.plugins.kotlin.jvm) + id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" // check for latest version + application } repositories { -mavenLocal() -mavenCentral() + mavenLocal() + mavenCentral() } dependencies { -smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") -implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") -implementation("software.amazon.smithy:smithy-model:") -implementation("software.amazon.smithy:smithy-build:") -implementation("software.amazon.smithy:smithy-aws-traits:") + smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") + implementation("software.amazon.smithy:smithy-model:") + implementation("software.amazon.smithy:smithy-build:") + implementation("software.amazon.smithy:smithy-aws-traits:") + ... } ``` --- -### 3. Configure Smithy Build - -Create `smithy-build.json` in the same directory as `build.gradle.kts`: - +### Step 4: Create `smithy-build.json` in the New Project +This is an example of smithy-build.json. ```json { -"version": "1.0", -"outputDirectory": "build/generated-src", -"plugins": { -"kotlin-codegen": { -"service": "com.demo#DemoService", -"package": { -"name": "com.demo.server", -"version": "1.0.0" -}, -"build": { -"rootProject": true, -"generateServiceProject": true, -"optInAnnotations": [ -"aws.smithy.kotlin.runtime.InternalApi", -"kotlinx.serialization.ExperimentalSerializationApi" -] -}, -"serviceStub": { -"framework": "ktor" -} -} -} + "version": "1.0", + "outputDirectory": "build/generated-src", // define the output path + "plugins": { + "kotlin-codegen": { + // change based on smithy model # + "service": "com.demo#DemoService", + "package": { + "name": "com.demo.server", + "version": "1.0.0" + }, + "build": { + "rootProject": true, + "generateServiceProject": true, + "optInAnnotations": [ + "aws.smithy.kotlin.runtime.InternalApi", + "kotlinx.serialization.ExperimentalSerializationApi" + ] + }, + "serviceStub": { + // choose server framework, only ktor is supported now + "framework": "ktor" + } + } + } } ``` --- -### 4. Define Your Smithy Model +### Step 5: Define Your Smithy Model in the New Project Create a `model` directory and add your `.smithy` files. Example `model/greeter.smithy`: @@ -103,43 +150,47 @@ use smithy.api#httpBearerAuth @restJson1 @httpBearerAuth service DemoService { -version: "1.0.0" -operations: [SayHello] + version: "1.0.0" + operations: [ + SayHello + ] } @http(method: "POST", uri: "/greet", code: 201) operation SayHello { -input: SayHelloInput -output: SayHelloOutput -errors: [CustomError] + input: SayHelloInput + output: SayHelloOutput + errors: [ + CustomError + ] } @input structure SayHelloInput { -@required -@length(min: 3, max: 10) -name: String -@httpHeader("X-User-ID") -id: Integer + @required + @length(min: 3, max: 10) + name: String + @httpHeader("X-User-ID") + id: Integer } @output structure SayHelloOutput { -greeting: String + greeting: String } @error("server") @httpError(500) structure CustomError { -msg: String -@httpHeader("X-User-error") -err: String + msg: String + @httpHeader("X-User-error") + err: String } ``` --- -### 5. Generate the Service +### Step 6: Generate the Service in the New Project Run: ```bash @@ -153,7 +204,7 @@ gradle clean --- -### 6. Run the Service +### Step 7: Run the Generated Service The generated service will be in the directory specified in `smithy-build.json` (`outputDirectory`). You can start it by running: @@ -164,7 +215,7 @@ By default, it listens on port **8080**. --- -### 7. Adjust Service Configuration +### Step 8: Adjust Service Configuration You can override runtime settings (such as port or HTTP engine) using command-line arguments: ```bash From 3ba5e78890717b23f8e3680da6e5c8ba877f72cf Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 11:20:28 -0700 Subject: [PATCH 04/10] read me --- .../amazon/smithy/kotlin/codegen/service/README.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index a94f9578e..59271d6ff 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -3,7 +3,7 @@ ## Overview This project extends **Smithy Kotlin** to generate **service-side code** from Smithy models, targeting the **Ktor** framework for server implementation. -It produces **complete service stubs**—including routing, serialization/deserialization, authentication, and validation—so developers can focus entirely on implementing business logic. +It produces **complete service stubs**, including routing, serialization/deserialization, authentication, and validation, so developers can focus entirely on implementing business logic. While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. @@ -67,14 +67,11 @@ First, in **this repository**, build and publish the code generator locally: ./gradlew publishToMavenLocal ``` ---- - ### Step 2: Create a New Kotlin Project Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. From this point forward, **all steps apply to the new Kotlin project** you just created. ---- ### Step 3: Configure `build.gradle.kts` in the New Project @@ -100,7 +97,6 @@ dependencies { } ``` ---- ### Step 4: Create `smithy-build.json` in the New Project This is an example of smithy-build.json. @@ -133,8 +129,6 @@ This is an example of smithy-build.json. } ``` ---- - ### Step 5: Define Your Smithy Model in the New Project Create a `model` directory and add your `.smithy` files. @@ -188,8 +182,6 @@ structure CustomError { } ``` ---- - ### Step 6: Generate the Service in the New Project Run: @@ -202,8 +194,6 @@ If you want to clean previously generated code: gradle clean ``` ---- - ### Step 7: Run the Generated Service The generated service will be in the directory specified in `smithy-build.json` (`outputDirectory`). @@ -213,8 +203,6 @@ gradle run ``` By default, it listens on port **8080**. ---- - ### Step 8: Adjust Service Configuration You can override runtime settings (such as port or HTTP engine) using command-line arguments: From 77403e7d890332a8f77a655c041eff2862ffe4b9 Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 11:24:06 -0700 Subject: [PATCH 05/10] read me --- .../amazon/smithy/kotlin/codegen/service/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index 59271d6ff..e845e6c87 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -103,10 +103,9 @@ This is an example of smithy-build.json. ```json { "version": "1.0", - "outputDirectory": "build/generated-src", // define the output path + "outputDirectory": "build/generated-src", "plugins": { "kotlin-codegen": { - // change based on smithy model # "service": "com.demo#DemoService", "package": { "name": "com.demo.server", @@ -121,7 +120,6 @@ This is an example of smithy-build.json. ] }, "serviceStub": { - // choose server framework, only ktor is supported now "framework": "ktor" } } @@ -129,6 +127,12 @@ This is an example of smithy-build.json. } ``` +**Notes:** +- The most important fields are: + - **`outputDirectory`** — defines where the generated service code will be placed in your new project. + - **`service`** — must match your Smithy model’s `#`. + - **`serviceStub.framework`** — defines the server framework for generated code. Currently only `"ktor"` is supported. + ### Step 5: Define Your Smithy Model in the New Project Create a `model` directory and add your `.smithy` files. From 46fed3fac4ca9b46c400a981e176f06bdec937e8 Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 15:44:51 -0700 Subject: [PATCH 06/10] read me --- .../smithy/kotlin/codegen/service/README.md | 228 ++---------------- .../codegen/service/docs/GettingStarted.md | 161 +++++++++++++ .../kotlin/codegen/service/docs/Summary.md | 47 ++++ 3 files changed, 233 insertions(+), 203 deletions(-) create mode 100644 codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md create mode 100644 codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index e845e6c87..4099f36a2 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -1,222 +1,44 @@ -# Smithy Kotlin Service Codegen (Ktor) +# Smithy Kotlin Service Codegen (SKSC) ## Overview -This project extends **Smithy Kotlin** to generate **service-side code** from Smithy models, targeting the **Ktor** framework for server implementation. -It produces **complete service stubs**, including routing, serialization/deserialization, authentication, and validation, so developers can focus entirely on implementing business logic. - -While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. - ---- - -## Feature Summary - -| **Features** | **Description** | -|---------------------------|-----------------| -| Service Framework | Abstracted service framework interface and base implementation with Ktor as the default backend | -| CBOR Protocol | Support for CBOR serialization / deserialization and CBOR protocol traits | -| Json Protocol | Support for Json serialization / deserialization and Json protocol traits | -| Routing | Per-operation routing generation with Ktor DSL; ties to handler and validation | -| Error Handler | Unified exception handling logic mapped to HTTP status codes and support for error trait | -| Authentication (bearer) | Bearer token authentication middleware with model-driven configuration | -| Logging | Structured logging setup | -| Constraints Checker | Validation logic generated from Smithy traits and invoked pre-handler | -| Unit Test | Covers serialization/deserialization, routing, validation, and integration tests | - ---- - -## Smithy Protocol Traits Support - -| **Traits** | **CBOR Protocol** | **Json Protocol** | -|--------------------------|-------------------|-------------------| -| http | Yes | Yes | -| httpError | Yes | Yes | -| httpHeader | Not supported | Yes | -| httpPrefixHeader | Not supported | Yes | -| httpLabel | Not supported | Yes | -| httpQuery | Not supported | Yes | -| httpQueryParams | Not supported | Yes | -| httpPayload | Not supported | Yes | -| jsonName | Not supported | Yes | -| timestampFormat | Not supported | Yes | -| httpChecksumRequired | Not supported | Not implemented yet | -| requestCompression | Not implemented yet | Not implemented yet | - --- -## Constraint Traits Support +This project generate **service-side code** from Smithy models, producing **complete service stubs**, including routing, serialization/deserialization, authentication, and validation, so developers can focus entirely on implementing business logic. -| **Traits** | **CBOR Protocol** | **Json Protocol** | -|-----------------|------------------------------|------------------------------| -| required | Yes | Yes | -| length | Yes | Yes | -| pattern | Yes | Yes | -| private | Yes (handled by Smithy) | Yes (handled by Smithy) | -| range | Yes | Yes | -| uniqueItems | Yes | Yes | -| idRef | Not implemented yet | Not implemented yet | +While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. ---- ## Getting Started -### Step 1: Build & Publish Codegen to Local Maven -First, in **this repository**, build and publish the code generator locally: -```bash -./gradlew :codegen:smithy-kotlin-codegen:build -./gradlew publishToMavenLocal -``` - -### Step 2: Create a New Kotlin Project -Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. - -From this point forward, **all steps apply to the new Kotlin project** you just created. - - -### Step 3: Configure `build.gradle.kts` in the New Project - -```kotlin -plugins { - alias(libs.plugins.kotlin.jvm) - id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" // check for latest version - application -} - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") - implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") - implementation("software.amazon.smithy:smithy-model:") - implementation("software.amazon.smithy:smithy-build:") - implementation("software.amazon.smithy:smithy-aws-traits:") - ... -} -``` - - -### Step 4: Create `smithy-build.json` in the New Project -This is an example of smithy-build.json. -```json -{ - "version": "1.0", - "outputDirectory": "build/generated-src", - "plugins": { - "kotlin-codegen": { - "service": "com.demo#DemoService", - "package": { - "name": "com.demo.server", - "version": "1.0.0" - }, - "build": { - "rootProject": true, - "generateServiceProject": true, - "optInAnnotations": [ - "aws.smithy.kotlin.runtime.InternalApi", - "kotlinx.serialization.ExperimentalSerializationApi" - ] - }, - "serviceStub": { - "framework": "ktor" - } - } - } -} -``` - -**Notes:** -- The most important fields are: - - **`outputDirectory`** — defines where the generated service code will be placed in your new project. - - **`service`** — must match your Smithy model’s `#`. - - **`serviceStub.framework`** — defines the server framework for generated code. Currently only `"ktor"` is supported. - -### Step 5: Define Your Smithy Model in the New Project - -Create a `model` directory and add your `.smithy` files. -Example `model/greeter.smithy`: - -```smithy -$version: "2.0" -namespace com.demo - -use aws.protocols#restJson1 -use smithy.api#httpBearerAuth - -@restJson1 -@httpBearerAuth -service DemoService { - version: "1.0.0" - operations: [ - SayHello - ] -} - -@http(method: "POST", uri: "/greet", code: 201) -operation SayHello { - input: SayHelloInput - output: SayHelloOutput - errors: [ - CustomError - ] -} - -@input -structure SayHelloInput { - @required - @length(min: 3, max: 10) - name: String - @httpHeader("X-User-ID") - id: Integer -} +--- -@output -structure SayHelloOutput { - greeting: String -} +- Get an [introduction to Smithy](https://smithy.io/2.0/index.html) +- Follow [Smithy's quickstart guide](https://smithy.io/2.0/quickstart.html) +- See the [Guide](docs/GettingStarted.md) to learn how to use SKSC to generate service. +- See a [Summary of Service Support](docs/Summary.md) to learn which features are supported -@error("server") -@httpError(500) -structure CustomError { - msg: String - @httpHeader("X-User-error") - err: String -} -``` -### Step 6: Generate the Service in the New Project +## Development -Run: -```bash -gradle build run -``` - -If you want to clean previously generated code: -```bash -gradle clean -``` +--- -### Step 7: Run the Generated Service +### Module Structure -The generated service will be in the directory specified in `smithy-build.json` (`outputDirectory`). -You can start it by running: -```bash -gradle run -``` -By default, it listens on port **8080**. +- `constraints` – directory that contains the constraints validation generator. + - `ConstraintsGenerator.kt` - main generator for constraints. + - `ConstraintUtilsGenerator` - generator for constraint utilities. + - For each constraint trait, there is a dedicated file. +- `ktor` – directory that stores all features generators specific to Ktor. + - `ktorStubGenerator.kt` – main generator for ktor framework service stub generator. +- `ServiceStubConfiguration.kt` – configuration file for the service stub generator. +- `ServiceStubGenerator.kt` – abstract service stub generator file. +- `ServiceTypes.kt` – file that includes service component symbols. +- `utils.kt` – utilities file. -### Step 8: Adjust Service Configuration +### Testing -You can override runtime settings (such as port or HTTP engine) using command-line arguments: +The **service code generation tests** are located in `tests/codegen/service-codegen-tests`. These end-to-end tests generate the service, launch the server, send HTTP requests to validate functionality, and then shut down the service once testing is complete. This process typically takes around 2 minutes. To run tests specifically for SKSC, use the following command: ```bash -gradle run --args="port 8000 engineFactory cio" -``` - ---- - -## Notes -- **Business Logic**: Implement your own logic in the generated operation handler interfaces. -- **Configuration**: Adjust port, engine, auth, and other settings via `ServiceFrameworkConfig` or CLI args. -- **Future Extensions**: Planned support for more serialization formats (JSON, XML) and AWS SigV4 auth. + ./gradlew :tests:codegen:service-codegen-tests:test +``` \ No newline at end of file diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md new file mode 100644 index 000000000..a21a9e68c --- /dev/null +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md @@ -0,0 +1,161 @@ +# Getting Started + +### Step 1: Build & Publish Codegen to Local Maven +First, in **this repository**, build and publish the code generator locally: +```bash + ./gradlew :codegen:smithy-kotlin-codegen:build + ./gradlew publishToMavenLocal +``` + +### Step 2: Create a New Kotlin Project +Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. + +From this point forward, **all steps apply to the new Kotlin project** you just created. + + +### Step 3: Configure `build.gradle.kts` in the New Project + +```kotlin +plugins { + alias(libs.plugins.kotlin.jvm) + id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" // check for latest version + application +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") + implementation("software.amazon.smithy:smithy-model:") + implementation("software.amazon.smithy:smithy-build:") + implementation("software.amazon.smithy:smithy-aws-traits:") + ... +} +``` + + +### Step 4: Create `smithy-build.json` in the New Project +This is an example of smithy-build.json. +```json +{ + "version": "1.0", + "outputDirectory": "build/generated-src", + "plugins": { + "kotlin-codegen": { + "service": "com.demo#DemoService", + "package": { + "name": "com.demo.server", + "version": "1.0.0" + }, + "build": { + "rootProject": true, + "generateServiceProject": true, + "optInAnnotations": [ + "aws.smithy.kotlin.runtime.InternalApi", + "kotlinx.serialization.ExperimentalSerializationApi" + ] + }, + "serviceStub": { + "framework": "ktor" + } + } + } +} +``` + +**Notes:** +- The most important fields are: + - **`outputDirectory`** — defines where the generated service code will be placed in your new project. + - **`service`** — must match your Smithy model’s `#`. + - **`serviceStub.framework`** — defines the server framework for generated code. Currently only `"ktor"` is supported. + +### Step 5: Define Your Smithy Model in the New Project + +Create a `model` directory and add your `.smithy` files. +Example `model/greeter.smithy`: + +```smithy +$version: "2.0" +namespace com.demo + +use aws.protocols#restJson1 +use smithy.api#httpBearerAuth + +@restJson1 +@httpBearerAuth +service DemoService { + version: "1.0.0" + operations: [ + SayHello + ] +} + +@http(method: "POST", uri: "/greet", code: 201) +operation SayHello { + input: SayHelloInput + output: SayHelloOutput + errors: [ + CustomError + ] +} + +@input +structure SayHelloInput { + @required + @length(min: 3, max: 10) + name: String + @httpHeader("X-User-ID") + id: Integer +} + +@output +structure SayHelloOutput { + greeting: String +} + +@error("server") +@httpError(500) +structure CustomError { + msg: String + @httpHeader("X-User-error") + err: String +} +``` + +### Step 6: Generate the Service in the New Project + +Run: +```bash + gradle build run +``` + +If you want to clean previously generated code: +```bash + gradle clean +``` + +### Step 7: Run the Generated Service + +The generated service will be in the directory specified in `smithy-build.json` (`outputDirectory`). +You can start it by running: +```bash + gradle run +``` +By default, it listens on port **8080**. + +### Step 8: Adjust Service Configuration + +You can override runtime settings (such as port or HTTP engine) using command-line arguments: +```bash + gradle run --args="port 8000 engineFactory cio" +``` + +--- + +## Notes +- **Business Logic**: Implement your own logic in the generated operation handler interfaces. +- **Configuration**: Adjust port, engine, auth, and other settings via `ServiceFrameworkConfig` or CLI args. diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md new file mode 100644 index 000000000..c98dc764e --- /dev/null +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md @@ -0,0 +1,47 @@ +# Summary + +--- + +### Features Support + +| **Features** | **Description** | +|-----------------------------------|-------------------------------------------------------------------------------------------------| +| Service Framework | Abstracted service framework interface and base implementation with Ktor as the default backend | +| CBOR Protocol | Support for CBOR serialization / deserialization and CBOR protocol traits | +| Json Protocol | Support for Json serialization / deserialization and Json protocol traits | +| Routing | Per-operation routing generation with Ktor DSL; ties to handler and validation | +| Error Handler | Unified exception handling logic mapped to HTTP status codes and support for error trait | +| Authentication (bearer) | Bearer token authentication middleware with model-driven configuration | +| Authentication (SigV4 and SigV4A) | SigV4 and SigV4A authentication middleware with model-driven configuration | +| Logging | Structured logging setup | +| Constraints Checker | Validation logic generated from Smithy traits and invoked pre-handler | +| Unit Test | Covers serialization/deserialization, routing, validation, and integration tests | + +### Smithy Protocol Traits Support + +| **Traits** | **CBOR Protocol** | **Json Protocol** | +|--------------------------|-------------------|-------------------| +| http | Yes | Yes | +| httpError | Yes | Yes | +| httpHeader | Not supported | Yes | +| httpPrefixHeader | Not supported | Yes | +| httpLabel | Not supported | Yes | +| httpQuery | Not supported | Yes | +| httpQueryParams | Not supported | Yes | +| httpPayload | Not supported | Yes | +| jsonName | Not supported | Yes | +| timestampFormat | Not supported | Yes | +| httpChecksumRequired | Not supported | Not implemented yet | +| requestCompression | Not implemented yet | Not implemented yet | + +### Constraint Traits Support + +| **Traits** | **CBOR Protocol** | **Json Protocol** | +|-----------------|------------------------------|------------------------------| +| required | Yes | Yes | +| length | Yes | Yes | +| pattern | Yes | Yes | +| private | Yes (handled by Smithy) | Yes (handled by Smithy) | +| range | Yes | Yes | +| uniqueItems | Yes | Yes | +| idRef | Not implemented yet | Not implemented yet | From 16bd523e2ccd6177dcc662466107189b013a818d Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 15:47:57 -0700 Subject: [PATCH 07/10] fix --- .../amazon/smithy/kotlin/codegen/service/README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index 4099f36a2..eb4905fb0 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -2,8 +2,6 @@ ## Overview ---- - This project generate **service-side code** from Smithy models, producing **complete service stubs**, including routing, serialization/deserialization, authentication, and validation, so developers can focus entirely on implementing business logic. While Ktor is the default backend, the architecture is framework-agnostic, allowing future support for other server frameworks. @@ -11,8 +9,6 @@ While Ktor is the default backend, the architecture is framework-agnostic, allow ## Getting Started ---- - - Get an [introduction to Smithy](https://smithy.io/2.0/index.html) - Follow [Smithy's quickstart guide](https://smithy.io/2.0/quickstart.html) - See the [Guide](docs/GettingStarted.md) to learn how to use SKSC to generate service. @@ -21,8 +17,6 @@ While Ktor is the default backend, the architecture is framework-agnostic, allow ## Development ---- - ### Module Structure - `constraints` – directory that contains the constraints validation generator. @@ -41,4 +35,9 @@ While Ktor is the default backend, the architecture is framework-agnostic, allow The **service code generation tests** are located in `tests/codegen/service-codegen-tests`. These end-to-end tests generate the service, launch the server, send HTTP requests to validate functionality, and then shut down the service once testing is complete. This process typically takes around 2 minutes. To run tests specifically for SKSC, use the following command: ```bash ./gradlew :tests:codegen:service-codegen-tests:test -``` \ No newline at end of file +``` + +## Feedback + +You can provide feedback or report a bug by submitting an [issue](https://github.com/smithy-lang/smithy-kotlin/issues/new/choose). +This is the preferred mechanism to give feedback so that other users can engage in the conversation, +1 issues, etc. \ No newline at end of file From 3548e9cf229c23b2ebb08742eb77ad643711ac66 Mon Sep 17 00:00:00 2001 From: luigi Date: Fri, 15 Aug 2025 15:52:49 -0700 Subject: [PATCH 08/10] fix --- .../amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md index a21a9e68c..858bdb557 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md @@ -153,6 +153,7 @@ You can override runtime settings (such as port or HTTP engine) using command-li ```bash gradle run --args="port 8000 engineFactory cio" ``` +You can find all available settings [here](https://github.com/smithy-lang/smithy-kotlin/blob/16bd523e2ccd6177dcc662466107189b013a818d/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/ServiceStubGenerator.kt#L179C1-L186C38) --- From b5874150cba238164c5df70837dfe714485f6c29 Mon Sep 17 00:00:00 2001 From: luigi Date: Mon, 18 Aug 2025 13:38:01 -0700 Subject: [PATCH 09/10] fix --- .../smithy/kotlin/codegen/service/README.md | 2 +- .../service/docs/{Summary.md => FEATURES.md} | 12 +++++ .../codegen/service/docs/GettingStarted.md | 17 +++--- examples/service-codegen/build.gradle.kts | 54 +++++++++++++++++++ examples/service-codegen/model/demo.smithy | 49 +++++++++++++++++ examples/service-codegen/smithy-build.json | 30 +++++++++++ .../test/kotlin/com/test/CborServiceTest.kt | 2 +- .../src/test/kotlin/com/test/utils.kt | 2 +- 8 files changed, 158 insertions(+), 10 deletions(-) rename codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/{Summary.md => FEATURES.md} (75%) create mode 100644 examples/service-codegen/build.gradle.kts create mode 100644 examples/service-codegen/model/demo.smithy create mode 100644 examples/service-codegen/smithy-build.json diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md index eb4905fb0..18832f7e6 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/README.md @@ -12,7 +12,7 @@ While Ktor is the default backend, the architecture is framework-agnostic, allow - Get an [introduction to Smithy](https://smithy.io/2.0/index.html) - Follow [Smithy's quickstart guide](https://smithy.io/2.0/quickstart.html) - See the [Guide](docs/GettingStarted.md) to learn how to use SKSC to generate service. -- See a [Summary of Service Support](docs/Summary.md) to learn which features are supported +- See a [Summary of Service Support](docs/FEATURES.md) to learn which features are supported ## Development diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/FEATURES.md similarity index 75% rename from codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md rename to codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/FEATURES.md index c98dc764e..03784e96b 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/Summary.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/FEATURES.md @@ -45,3 +45,15 @@ | range | Yes | Yes | | uniqueItems | Yes | Yes | | idRef | Not implemented yet | Not implemented yet | + + +### Future Features + +| Feature | Description | +|-----------------------------------|-------------------------------------------------------------------------------------------------| +| Additional Protocols | XML, Ec2Query, AWSQuery protocols | +| Middleware / Interceptors | Cross-cutting logic support (e.g., metrics, headers, rate limiting) via middleware architecture | +| API Versioning | Built-in support for versioned APIs to maintain backward compatibility | +| gRPC / WebSocket Protocol Support | High-performance binary RPC and real-time bidirectional communication | +| Metrics & Tracing | Observability support with metrics, logs, and distributed tracing for debugging and monitoring | +| Caching Middleware | Per-route or global cache support to improve response times and reduce backend load | diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md index 858bdb557..1f6d8c9bd 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/docs/GettingStarted.md @@ -8,7 +8,7 @@ First, in **this repository**, build and publish the code generator locally: ``` ### Step 2: Create a New Kotlin Project -Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. +Now, create a **new Kotlin project** where you will use the Smithy Kotlin service code generator. You can find a full example demo project [here](../../../../../../../../../../../../examples/service-codegen) From this point forward, **all steps apply to the new Kotlin project** you just created. @@ -27,12 +27,15 @@ repositories { mavenCentral() } +val codegenVersion = "0.35.2-SNAPSHOT" +val smithyVersion = "1.60.2" + dependencies { - smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:") - implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:") - implementation("software.amazon.smithy:smithy-model:") - implementation("software.amazon.smithy:smithy-build:") - implementation("software.amazon.smithy:smithy-aws-traits:") + smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:$codegenVersion") + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:$codegenVersion") + implementation("software.amazon.smithy:smithy-model:$smithyVersion") + implementation("software.amazon.smithy:smithy-build:$smithyVersion") + implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") ... } ``` @@ -130,7 +133,7 @@ structure CustomError { Run: ```bash - gradle build run + gradle build ``` If you want to clean previously generated code: diff --git a/examples/service-codegen/build.gradle.kts b/examples/service-codegen/build.gradle.kts new file mode 100644 index 000000000..28003a6fe --- /dev/null +++ b/examples/service-codegen/build.gradle.kts @@ -0,0 +1,54 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Kotlin application project to get you started. + * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.14.2/userguide/building_java_projects.html in the Gradle documentation. + */ + +plugins { + // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. + alias(libs.plugins.kotlin.jvm) + + id("software.amazon.smithy.gradle.smithy-jar") version "1.3.0" + // Apply the application plugin to add support for building a CLI application in Java. + application +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() + mavenLocal() +} + +val codegenVersion = "0.35.2-SNAPSHOT" +val smithyVersion = "1.60.2" + +dependencies { + smithyBuild("software.amazon.smithy.kotlin:smithy-kotlin-codegen:$codegenVersion") + implementation("software.amazon.smithy.kotlin:smithy-aws-kotlin-codegen:$codegenVersion") + implementation("software.amazon.smithy:smithy-model:$smithyVersion") + implementation("software.amazon.smithy:smithy-build:$smithyVersion") + implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") + // Use the Kotlin JUnit 5 integration. + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + + // Use the JUnit 5 integration. + testImplementation(libs.junit.jupiter.engine) + + testRuntimeOnly("org.junit.platform:junit-platform-launcher") + + // This dependency is used by the application. + implementation(libs.guava) +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +tasks.named("test") { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} diff --git a/examples/service-codegen/model/demo.smithy b/examples/service-codegen/model/demo.smithy new file mode 100644 index 000000000..b887aa4e2 --- /dev/null +++ b/examples/service-codegen/model/demo.smithy @@ -0,0 +1,49 @@ +// model/greeter.smithy +$version: "2.0" + +namespace com.demo + +use aws.protocols#restJson1 +use smithy.api#httpBearerAuth + +@restJson1 +@httpBearerAuth +service DemoService { + version: "1.0.0" + operations: [ + SayHello + ] +} + +@http(method: "POST", uri: "/greet", code: 201) +operation SayHello { + input: SayHelloInput + output: SayHelloOutput + errors: [ + CustomError + ] +} + +@input +structure SayHelloInput { + @required + @length(min: 3, max: 10) + name: String + + @httpHeader("X-User-ID") + id: Integer +} + +@output +structure SayHelloOutput { + greeting: String +} + +@error("server") +@httpError(500) +structure CustomError { + msg: String + + @httpHeader("X-User-error") + err: String +} diff --git a/examples/service-codegen/smithy-build.json b/examples/service-codegen/smithy-build.json new file mode 100644 index 000000000..7b1948b71 --- /dev/null +++ b/examples/service-codegen/smithy-build.json @@ -0,0 +1,30 @@ +{ + "version": "1.0", + "outputDirectory": "build/generated-src-test", + "plugins": { + "kotlin-codegen": { + "service": "com.demo#DemoService", + + "package": { + "name": "com.demo.server", + "version": "1.0.0" + }, + + "build": { + "rootProject": true, + "generateServiceProject": true, + "optInAnnotations": [ + "aws.smithy.kotlin.runtime.InternalApi", + "kotlinx.serialization.ExperimentalSerializationApi" + ] + }, + + "serviceStub": { + "framework": "ktor" + } + } + } +} + + + diff --git a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt index 629e23b48..15c4e7680 100644 --- a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt +++ b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt @@ -36,7 +36,7 @@ class CborServiceTest { @BeforeAll fun boot() { proc = startService("netty", port, closeGracePeriodMillis, closeTimeoutMillis, requestBodyLimit, projectDir) - val ready = waitForPort(port, portListnerTimeout) + val ready = waitForPort(port, portListnerTimeout, proc) assertTrue(ready, "Service did not start within $portListnerTimeout s") } diff --git a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt index 87954d03e..a542456e7 100644 --- a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt +++ b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt @@ -80,7 +80,7 @@ internal fun cleanupService(proc: Process, gracefulWindow: Long = 5_000L) { private fun isWindows() = System.getProperty("os.name").lowercase().contains("windows") -internal fun waitForPort(port: Int, timeoutSec: Long = 180): Boolean { +internal fun waitForPort(port: Int, timeoutSec: Long = 180, proc: Process? = null): Boolean { val deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toNanos(timeoutSec) while (System.currentTimeMillis() < deadline) { try { From f72885eca2610dfe64861cfd0a1fe0d0a2cf02c2 Mon Sep 17 00:00:00 2001 From: luigi Date: Mon, 18 Aug 2025 13:47:39 -0700 Subject: [PATCH 10/10] fix --- .../src/test/kotlin/com/test/CborServiceTest.kt | 2 +- .../service-codegen-tests/src/test/kotlin/com/test/utils.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt index 15c4e7680..629e23b48 100644 --- a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt +++ b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt @@ -36,7 +36,7 @@ class CborServiceTest { @BeforeAll fun boot() { proc = startService("netty", port, closeGracePeriodMillis, closeTimeoutMillis, requestBodyLimit, projectDir) - val ready = waitForPort(port, portListnerTimeout, proc) + val ready = waitForPort(port, portListnerTimeout) assertTrue(ready, "Service did not start within $portListnerTimeout s") } diff --git a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt index a542456e7..87954d03e 100644 --- a/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt +++ b/tests/codegen/service-codegen-tests/src/test/kotlin/com/test/utils.kt @@ -80,7 +80,7 @@ internal fun cleanupService(proc: Process, gracefulWindow: Long = 5_000L) { private fun isWindows() = System.getProperty("os.name").lowercase().contains("windows") -internal fun waitForPort(port: Int, timeoutSec: Long = 180, proc: Process? = null): Boolean { +internal fun waitForPort(port: Int, timeoutSec: Long = 180): Boolean { val deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toNanos(timeoutSec) while (System.currentTimeMillis() < deadline) { try {