namespace DealerSelection.Common.Helpers; public class SwashbuckleSchemaHelper { private readonly Dictionary _schemaNameRepetition = new (); /// /// Eliminate the case where more than one method returns the same type in different controllers /// swagger documentation to fail /// /// /// public string GetSchemaId(Type modelType) { string id = DefaultSchemaIdSelector (modelType); if(!_schemaNameRepetition.ContainsKey(id)) _schemaNameRepetition.Add(id, 0); int count = _schemaNameRepetition[id] + 1; _schemaNameRepetition[id] = count; return $"{id}{(count > 1 ? count.ToString() : "")}"; } private string DefaultSchemaIdSelector(Type modelType) { if (!modelType.IsConstructedGenericType) return modelType.Name.Replace("[]", "Array"); string prefix = modelType.GetGenericArguments() .Select(genericArg => DefaultSchemaIdSelector(genericArg)) .Aggregate((previous, current) => previous + current); return prefix + modelType.Name.Split('`').First(); } }