A tool for generating C# code from Smithy 2.0 IDL files
$ dotnet add package Smithy.CSharpA robust code generator that transforms Smithy 2.0 service models into idiomatic C# code.
The Smithy to C# code generator is a tool that allows developers to define their service models using the Smithy 2.0 IDL (Interface Definition Language) and generate production-ready C# code. This project aims to bridge the gap between the Smithy specification and .NET ecosystem by providing a comprehensive code generation solution.
# Install the tool globally
dotnet tool install -g Smithy.CSharp
# Clone the repository
git clone https://github.com/options/smithy-csharp.git
cd smithy-csharp
# Build the solution
dotnet build
# Package the tool
# On Windows
.\pack-tool.ps1
# On Linux/macOS
./pack-tool.sh
# Install from local package
dotnet tool install -g --add-source ./nupkg Smithy.CSharp
The project follows semantic versioning (SemVer). When creating releases:
Update the version in Smithy.Cli/Smithy.Cli.csproj:
<Version>X.Y.Z</Version>
<AssemblyVersion>X.Y.Z.0</AssemblyVersion>
<FileVersion>X.Y.Z.0</FileVersion>
Create and push a tag that matches the version:
git tag vX.Y.Z
git push origin vX.Y.Z
This will trigger the GitHub Actions release workflow which will:
You can also use the provided scripts:
- Windows: `.\pack-tool.ps1`
- macOS/Linux: `./pack-tool.sh`
## 📝 Usage
### Basic Usage
```bash
# Generate C# code from a Smithy model
smithy-cli generate path/to/smithy/file.smithy
# Specify output directory
smithy-cli generate path/to/smithy/file.smithy --output MyGeneratedCode
# Get help
smithy-cli --help
# Check version
smithy-cli --version
smithy-cli generate --input-dir path/to/smithy/files --output MyGeneratedCode
smithy-cli generate path/to/model.json --output MyGeneratedCode
smithy-cli generate path/to/smithy/file.smithy --output MyGeneratedCode --namespace MyCompany.Services
namespace example.weather
/// Weather forecast service
@restJson1
service WeatherService {
version: "2023-01-01",
operations: [GetForecast]
}
/// Get weather forecast operation
@http(method: "GET", uri: "/forecast/{locationId}")
operation GetForecast {
input := {
@required
@httpLabel
locationId: String,
@httpQuery("units")
units: String = "celsius"
},
output := {
forecast: ForecastData
}
}
structure ForecastData {
@required
temperature: Float,
description: String,
precipitation: Float
}
namespace example.weather
{
/// <summary>
/// Weather forecast service
/// </summary>
[ApiController]
[Route("api/v2023-01-01/weather-service")]
public class WeatherServiceController : ControllerBase, IWeatherService
{
/// <summary>
/// Get weather forecast operation
/// </summary>
[HttpGet("/forecast/{locationId}")]
public Task<GetForecastOutput> GetForecast(GetForecastInput input)
{
// TODO: Implement service operation
return Task.FromResult(new GetForecastOutput());
}
}
public interface IWeatherService
{
/// <summary>
/// Get weather forecast operation
/// </summary>
Task<GetForecastOutput> GetForecast(GetForecastInput input);
}
public class GetForecastInput
{
[Required]
[FromRoute]
public string LocationId { get; set; }
[FromQuery(Name = "units")]
public string Units { get; set; } = "celsius";
}
public class GetForecastOutput
{
public ForecastData Forecast { get; set; }
}
public class ForecastData
{
[Required]
public float Temperature { get; set; }
public string Description { get; set; }
public float? Precipitation { get; set; }
}
}
The project currently supports approximately 95% of the Smithy 2.0 specification, with only a few advanced features still in development. The generated code is production-ready and follows best practices for C# development.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.