Fluent.Unions.NSwag
1.1.0
dotnet add package Fluent.Unions.NSwag --version 1.1.0
NuGet\Install-Package Fluent.Unions.NSwag -Version 1.1.0
<PackageReference Include="Fluent.Unions.NSwag" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.NSwag" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.NSwag" />
paket add Fluent.Unions.NSwag --version 1.1.0
#r "nuget: Fluent.Unions.NSwag, 1.1.0"
#:package Fluent.Unions.NSwag@1.1.0
#addin nuget:?package=Fluent.Unions.NSwag&version=1.1.0
#tool nuget:?package=Fluent.Unions.NSwag&version=1.1.0
![]()
Fluent.Unions.NSwag
Describes Option<T> as a nullable T in the documents that NSwag generates. It builds on Fluent.Unions and matches the JSON shape of an option: the value, or null for none.
Installation
dotnet add package Fluent.Unions.NSwag
Usage
Register the schema processor on the document settings. Without it, an option is described as an object with value and hasValue.
using Fluent.Unions.NSwag;
builder.Services.AddOpenApiDocument(settings => settings.AddFluentUnions());
Options in a request or response body then become nullable types, so generated clients see them.
public record Product(string Name, Option<string> Nickname, Option<int> Stock, Option<Address> Shipping);
// "nickname": string, nullable; "stock": integer int32, nullable; "shipping": null or Address
A plain T (primitives, arrays, lists, dictionaries) gets nullable: true. A T that NSwag describes through a reference (records, enums, nested options) becomes a oneOf of null and that reference. An option property is not required.
Swagger 2 documents (AddSwaggerDocument) are not supported: Swagger 2 cannot express this, so the processor throws a NotSupportedException instead of writing a wrong schema.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- NSwag.Generation (>= 14.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.