<PackageReference Include="NJsonSchema" Version="11.3.2" />

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 attribute = AttributeExtensions.GetAttribute<JsonSchemaAttribute>(val, true); if (!string.IsNullOrEmpty((attribute != null) ? attribute.get_Name() : null)) return attribute.get_Name(); CachedType val2 = ContextualTypeExtensions.ToCachedType(type); if (val2.get_Type().IsConstructedGenericType) return Enumerable.First(GetName(val2).Split(new char[1] { '`' })) + "Of" + string.Join("And", Enumerable.Select(val2.get_GenericArguments(), (CachedType a) => Generate(a.get_OriginalType()))); return GetName(val2); } private static string GetName(CachedType cType) { if (!(cType.get_Name() == "Int16")) { if (!(cType.get_Name() == "Int32")) { if (!(cType.get_Name() == "Int64")) return GetNullableDisplayName(cType, cType.get_Name()); 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; } } }