Urbanite.Extensions.Swagger 0.2.1

dotnet add package Urbanite.Extensions.Swagger --version 0.2.1
                    
NuGet\Install-Package Urbanite.Extensions.Swagger -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Urbanite.Extensions.Swagger" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Urbanite.Extensions.Swagger" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Urbanite.Extensions.Swagger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Urbanite.Extensions.Swagger --version 0.2.1
                    
#r "nuget: Urbanite.Extensions.Swagger, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Urbanite.Extensions.Swagger@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Urbanite.Extensions.Swagger&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Urbanite.Extensions.Swagger&version=0.2.1
                    
Install as a Cake Tool

Urbanite

This library extends System.Text.Json to make it easier to serialize polymorphic types. Especially when working with type hierarchies that are not easily described using attributes.

This library works with type hierarhies described using attributes as well as using dependency injection extensions. To use it, register Urbanite using DIExtension

services.AddUrbanite();

and then use AddUrbaniteSerializableType to register types that should be serialized polymorphically and couldn't be described using attributes.

interface IAnimal { }
class Dog : IAnimal { }
class Cat : IAnimal { }

services.AddUrbaniteSerializableType<IAnimal, Dog>("dog");
services.AddUrbaniteSerializableType<IAnimal, Cat>("cat");

To serialize polymorphically, use JsonSerializerOptions with PolymorphicTypeResolver:

class JsonOptionsConfiguration : IConfigureOptions<JsonOptions>
{
	private readonly PolymorphicTypeResolver _resolver;

	public JsonOptionsConfiguration(PolymorphicTypeResolver resolver)
	{
		_resolver = resolver;
	}

	public void Configure(JsonOptions options)
	{
		options.JsonSerializerOptions.TypeInfoResolver = _resolver;
	}
}

To change type discriminator property name, use the JsonPolymorphic attirbute

[JsonPolymorphic(TypeDiscriminatorPropertyName = "$my_discriminator")]
interface IBase{}

Swagger

To make swagger work with polymorphic types, use Urbanite.Extensions.Swagger:

services.AddUrbaniteSwaggerDocumentationPolymorphism();

It will configure swagger to use PolymorphicTypeResolver to describe polymorphic types (selecting derived types and type discriminators). And set polymorphic type handling to use All of for inheritance.

Packages

Urbanite NuGet version (Urbanite) Urbanite.Extensions.Swagger NuGet version (Urbanite.Extensions.Swagger)

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 221 1/22/2024
0.2.0 264 8/30/2023
0.1.1 192 8/28/2023
0.1.0 163 8/24/2023
0.0.4 186 8/10/2023
0.0.3 190 8/10/2023
0.0.2 176 8/10/2023
0.0.1 196 8/10/2023