Table of Contents

Namespace TypedRest.CodeGeneration

Parses OpenAPI/Swagger documents and infers TypedRest Endpoints from patterns in the described paths.

Note

NuGet package: TypedRest.CodeGeneration

Usage

Register the x-typedrest extension parser when reading a document, then either read the endpoints the document already describes or infer them from its paths:

var reader = new OpenApiStreamReader(new OpenApiReaderSettings().AddTypedRest());
var doc = reader.Read(File.OpenRead("myapi.yml"), out _);

EntryEndpoint endpoints = doc.GetTypedRest() ?? doc.MatchTypedRestPatterns();

MatchTypedRestPatterns arranges the paths into a tree and matches each node against the patterns in PatternRegistry.Default. Write the result back into the document with SetTypedRest to persist or hand-edit it.

Extension points

Implement IPattern and add it to a PatternRegistry to recognize path shapes of your own:

var patterns = PatternRegistry.Default.Add(new MyPattern());
var endpoints = doc.MatchTypedRestPatterns(patterns);

Patterns added later take precedence; the first one that matches a node wins.

Implement IEndpoint and add it to an EndpointRegistry to introduce a new endpoint kind, then pass the registry to AddTypedRest so that x-typedrest extensions using that kind can be parsed.

API

Namespaces

TypedRest.CodeGeneration.CSharp

Generates C# source code for TypedRest .NET clients from OpenAPI/Swagger documents.

TypedRest.CodeGeneration.Endpoints
TypedRest.CodeGeneration.Patterns

Classes

DictionaryExtensions

Provides extension methods for IDictionary<TKey, TValue>s.

KeyValuePairExtensions
OpenApiDocumentExtensions

Provides extension methods for OpenApiDocuments.

OpenApiObjectExtensions

Provides extension methods for OpenApiObjects.

OpenApiOperationExtensions
OpenApiReaderSettingsExtensions

Provides extension methods for OpenApiReaderSettingss.

OpenApiReferenceableExtensions

Provides extension methods for IOpenApiReferenceables.

OpenApiWriterExtensions

Provides extension methods for IOpenApiWriters.