<PackageReference Include="NJsonSchema" Version="11.0.0-preview005" />

DefaultSchemaNameGenerator

The default schema name generator implementation.
using Namotion.Reflection; using NJsonSchema.Annotations; using System; using System.Linq; using System.Runtime.CompilerServices; namespace NJsonSchema.Generation { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class DefaultSchemaNameGenerator : ISchemaNameGenerator { public virtual string Generate(Type type) { CachedType val = ContextualTypeExtensions.ToCachedType(type); JsonSchemaAttribute inheritedAttribute = val.GetInheritedAttribute<JsonSchemaAttribute>(); if (!string.IsNullOrEmpty(inheritedAttribute?.Name)) return inheritedAttribute.Name; CachedType val2 = ContextualTypeExtensions.ToCachedType(type); if (val2.get_Type().IsConstructedGenericType) return GetName(val2).Split(new char[1] { '`' }).First() + "Of" + string.Join("And", from a in val2.get_GenericArguments() select Generate(a.get_OriginalType())); return GetName(val2); } private static string GetName(CachedType cType) { if (!(cType.get_TypeName() == "Int16")) { if (!(cType.get_TypeName() == "Int32")) { if (!(cType.get_TypeName() == "Int64")) return GetNullableDisplayName(cType, cType.get_TypeName()); return GetNullableDisplayName(cType, "Long"); } return GetNullableDisplayName(cType, "Integer"); } return GetNullableDisplayName(cType, "Short"); } private static string GetNullableDisplayName(CachedType type, string actual) { return (type.get_IsNullableType() ? "Nullable" : "") + actual; } } }