ContractForge is a .NET tool for generating RPC clients, servers, and OpenAPI specifications from Thrift IDL files. It supports code generation for C# and TypeScript, enabling seamless cross-language RPC communication.
- Parse Thrift IDL files using ANTLR.
- Generate C# server code.
- Generate TypeScript client code.
- Generate OpenAPI JSON specifications.
- Command-line interface for easy integration.
- Clone the repository:
git clone https://github.com/AdeAttwood/ContractForge.git - Build the solution:
dotnet build ContractForge.sln
- Build and pack the tool:
dotnet pack src/ContractForge.Cli/ContractForge.Cli.csproj - Install globally:
dotnet tool install -g --add-source ./src/ContractForge.Cli/bin/Release ContractForge.Cli
Run the installed tool to generate code from a Thrift file:
contractforge --entry path/to/thrift/file.thrift --generator csharp-jsonapiYou can also specify multiple entry points for services that share common includes:
contractforge --entry service1.thrift --entry service2.thrift --generator csharp-jsonapiOptions:
--entry(-e): Path to the Thrift IDL file. Can be specified multiple times for multiple entry points.--generator(-g): Code generator (csharp-jsonapifor C#,typescript-clientfor TypeScript, oropenapifor OpenAPI JSON).--include(-i): Add a directory to the list of directories searched for include directives. Can be specified multiple times.--output(-o): The output file to save the generated code to (optional, defaults to console).
Generated code is output to the console by default. Redirect to a file if
needed, e.g., contractforge ... > output.cs, or use the --output option.
See the samples/ directory for working examples:
DotnetJsonWebApi: ASP.NET Core Web API with generated C# service.DenoTypescriptClient: Deno TypeScript client for RPC calls.
- Restore dependencies:
dotnet restore - Build:
dotnet build - Run tests:
dotnet test
Contributions are welcome! Please submit issues and pull requests.