Namespace TypedRest.CodeGeneration.CSharp
Generates C# source code for TypedRest .NET clients from OpenAPI/Swagger documents.
Note
NuGet package: TypedRest.CodeGeneration.CSharp
Usage
var reader = new OpenApiStreamReader(new OpenApiReaderSettings().AddTypedRest());
var doc = reader.Read(File.OpenRead("myapi.yml"), out _);
foreach (var type in doc.GenerateTypedRest(new GenerationOptions("MyService")
{
Namespace = "MyCompany.MyService",
GenerateInterfaces = true,
GenerateDtos = true
}))
type.WriteToDirectory("myclient/");
GenerateTypedRest uses the endpoints described by the document's x-typedrest extension, or infers them from the paths if there is no such extension.
Extension points
GenerateTypedRest takes an optional PatternRegistry controlling what is inferred, and an optional BuilderRegistry controlling what is emitted:
var types = doc.GenerateTypedRest(options, patterns, builders);
Implement IBuilder<TEndpoint> to change the code emitted for an endpoint kind. A BuilderRegistry holds at most one builder per kind, so replacing a built-in one means composing the registry yourself rather than adding to BuilderRegistry.Default.
To change how types and properties are named, derive from NamingStrategy and pass it to GenerateTypedRestEndpoints.
API
Namespaces
Classes
- CSharpClientGenerator
Generates the source code of a C# TypedRest client.
- CSharpGeneratedFile
Exposes a generated C# type as an IGeneratedFile.
- GenerationOptions
Options controlling the generation of a C# TypedRest client.
- TypeNameRegistry
Keeps track of the type names handed out during a generation run, so that no two generated types in the same namespace end up with the same name.