DarkPatterns.OpenApiCodegen.Client
0.17.1
See the version list below for details.
dotnet add package DarkPatterns.OpenApiCodegen.Client --version 0.17.1
NuGet\Install-Package DarkPatterns.OpenApiCodegen.Client -Version 0.17.1
<PackageReference Include="DarkPatterns.OpenApiCodegen.Client" Version="0.17.1" />
paket add DarkPatterns.OpenApiCodegen.Client --version 0.17.1
#r "nuget: DarkPatterns.OpenApiCodegen.Client, 0.17.1"
// Install DarkPatterns.OpenApiCodegen.Client as a Cake Addin #addin nuget:?package=DarkPatterns.OpenApiCodegen.Client&version=0.17.1 // Install DarkPatterns.OpenApiCodegen.Client as a Cake Tool #tool nuget:?package=DarkPatterns.OpenApiCodegen.Client&version=0.17.1
Adds source generators to generate C# client extension methods from an OpenAPI specification file.
Add this package, select the OpenAPI specification file from your project, and
set the build action to OpenApiSchemaClient
. Within that folder's namespace,
you'll automatically get the model and extension methods to invoke the API.
You can also directly add a reference within the .csproj
file as follows:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<OpenApiSchemaClient Include="schemas/petstore.yaml" />
</ItemGroup>
</Project>
This integrates during the build phase, so you can be sure your classes are up to date with your schema documentation.
Requirements
- C# 11+
- .NET 8
- Roslyn 3.11 or Roslyn 4.0+ (VS 2022 or later, or other up-to-date Roslyn installation.)
- A reference to
DarkPatterns.OpenApiCodegen.Json.Extensions
Other notes
- Take care to include
PrivateAssets="All"
on the reference to the analyzer package; you do not need to ship the package itself. - The namespace of the generated extensions will, by default, match the default namespace and the path for the file within the project (or the Link, if provided.)
Configuration
Additional settings may be added within the .csproj
. For example:
<OpenApiSchemaClient Include="schemas/petstore.yaml" Namespace="My.Extensions" Configuration="path/to/config.yaml" />
Namespace
- Overrides the namespace detected by the default namespace and path of the schema fileConfiguration
- Additional configuration settings specific to this schema. See the configuration yaml documentation below.
In addition, adding the following to an ItemGroup in the csproj (or adding the
yaml file with the build action OpenApiSchemaCSharpClientOptions
via Visual
Studio) will set the configuration yaml file for all client schemas that do not
have one specifically set.
<OpenApiSchemaCSharpClientOptions Include="path/to/config.yaml" />
Configuration Yaml
While the full structure of the yaml can be seen within the source repository, commonly, only one or two parameters are needed. Missing keys are merged with the defaults. For example:
mapType: global::System.Collections.Generic.Dictionary<string, {}>
arrayType: global::System.Collections.Generic.IEnumerable<{}>
types:
number:
formats:
float: float
double: double
default: double
mapType
- Specifies the type to use for JSON maps, which occur when whenadditionalProperties
is specified.{}
is used as a placeholder for the type.arrayType
- Specifies the type to use for JSON arrays.{}
is used as a placeholder for the type.types
must be an object with keys that correspond to the JSON Schematype
properties. Within, the configuration may specify either thedefault
(for if the format is either not specified or not found) or customformats
. Custom types may be used here to customize JSON serialization and deserialization, especially to standardize string formats for currency or APRs.The number example provided will generate a float if the following schema is used:
type: number format: float
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.