<PackageReference Include="NJsonSchema" Version="11.5.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 info = type.ToCachedType(); JsonSchemaAttribute attribute = info.GetAttribute<JsonSchemaAttribute>(true); if (!string.IsNullOrEmpty((attribute != null) ? attribute.get_Name() : null)) return attribute.get_Name(); CachedType cachedType = type.ToCachedType(); if (cachedType.Type.IsConstructedGenericType) return GetName(cachedType).Split(new char[1] { '`' }).First() + "Of" + string.Join("And", from a in cachedType.GenericArguments select Generate(a.OriginalType)); return GetName(cachedType); } private static string GetName(CachedType cType) { if (!(cType.Name == "Int16")) { if (!(cType.Name == "Int32")) { if (!(cType.Name == "Int64")) return GetNullableDisplayName(cType, cType.Name); return GetNullableDisplayName(cType, "Long"); } return GetNullableDisplayName(cType, "Integer"); } return GetNullableDisplayName(cType, "Short"); } private static string GetNullableDisplayName(CachedType type, string actual) { return (type.IsNullableType ? "Nullable" : "") + actual; } } }