Skip to content

Commit 32d8e24

Browse files
committed
#1397 Add polymorphism support to generated OpenAPI json and UI using Swashbuckle:
- Removed redundant changes;
1 parent 2432b60 commit 32d8e24

File tree

4 files changed

+4
-56
lines changed

4 files changed

+4
-56
lines changed

VirtoCommerce.Platform.Core/Common/AttributeExtensions.cs

-17
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,5 @@ public static string[] SplitString(this Attribute attribute, string original, ch
2121

2222
return result;
2323
}
24-
25-
/// <summary>
26-
/// Gets type attribute value https://stackoverflow.com/a/2656211/5907312
27-
/// </summary>
28-
/// <typeparam name="TAttribute">Attribute type</typeparam>
29-
/// <typeparam name="TValue">Value type</typeparam>
30-
/// <param name="type">Type for getting attribute</param>
31-
/// <param name="valueSelector">Attribute value selector</param>
32-
/// <returns>Attribute value</returns>
33-
public static TValue GetAttributeValue<TAttribute, TValue>(
34-
this Type type,
35-
Func<TAttribute, TValue> valueSelector)
36-
where TAttribute : Attribute
37-
{
38-
var att = type.GetCustomAttributes(typeof(TAttribute), true).FirstOrDefault() as TAttribute;
39-
return (att != null) ? valueSelector(att) : default(TValue);
40-
}
4124
}
4225
}

VirtoCommerce.Platform.Core/Modularity/ManifestModuleInfo.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ public ManifestModuleInfo(ModuleManifest manifest)
6262
Groups.AddRange(manifest.Groups);
6363
}
6464
Incompatibilities = new List<ModuleIdentity>();
65-
if (manifest.Incompatibilities != null)
65+
if(manifest.Incompatibilities != null)
6666
{
6767
Incompatibilities.AddRange(manifest.Incompatibilities.Select(x => new ModuleIdentity(x.Id, x.Version)));
6868
}
6969

70-
OpenAPIPolymorphicTypes = manifest.OpenAPIPolymorphicTypes?.Select(x => x.Trim()) ?? Enumerable.Empty<string>();
71-
7270
InitializationMode = InitializationMode.OnDemand;
7371
}
7472

@@ -103,7 +101,6 @@ public ManifestModuleInfo(ModuleManifest manifest)
103101
public ICollection<ModuleSettingsGroup> Settings { get; private set; }
104102
public ICollection<string> Errors { get; set; }
105103
public bool UseFullTypeNameInSwagger { get; set; }
106-
public IEnumerable<string> OpenAPIPolymorphicTypes { get; private set; }
107104

108105
public override string ToString()
109106
{

VirtoCommerce.Platform.Core/Modularity/ModuleManifest.cs

-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,5 @@ public class ModuleManifest
8888

8989
[XmlElement("useFullTypeNameInSwagger")]
9090
public bool UseFullTypeNameInSwagger { get; set; }
91-
92-
[XmlArray("openAPIPolymorphicTypes")]
93-
[XmlArrayItem("assemblyQualifiedTypeName")]
94-
public string[] OpenAPIPolymorphicTypes { get; set; }
9591
}
9692
}

VirtoCommerce.Platform.Data/Common/AssemblyExtensions.cs

+3-31
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
57

68
namespace VirtoCommerce.Platform.Data.Common
79
{
810
public static class AssemblyExtensions
911
{
1012
public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
1113
{
12-
if (assembly == null)
13-
throw new ArgumentNullException("assembly");
14+
if (assembly == null) throw new ArgumentNullException("assembly");
1415
try
1516
{
1617
return assembly.GetTypes();
@@ -20,34 +21,5 @@ public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
2021
return e.Types.Where(t => t != null);
2122
}
2223
}
23-
24-
/// <summary>
25-
/// Gets all assembly types with custom attribute specified.
26-
/// </summary>
27-
/// <param name="assembly">Assembly to get types</param>
28-
/// <param name="customAttributeType">Custom attribute type to check</param>
29-
/// <param name="inherited"></param>
30-
/// <returns></returns>
31-
public static IEnumerable<Type> GetTypesWithAttribute(this Assembly assembly, Type customAttributeType, bool inherited)
32-
{
33-
if (assembly == null)
34-
{
35-
throw new ArgumentNullException(nameof(assembly));
36-
}
37-
38-
if (customAttributeType == null)
39-
{
40-
throw new ArgumentNullException(nameof(customAttributeType));
41-
}
42-
43-
try
44-
{
45-
return assembly.GetTypes().Where(x => x.GetCustomAttributes(customAttributeType, inherited).Length > 0);
46-
}
47-
catch (ReflectionTypeLoadException e)
48-
{
49-
return e.Types.Where(x => x.GetCustomAttributes(customAttributeType, inherited).Length > 0);
50-
}
51-
}
5224
}
5325
}

0 commit comments

Comments
 (0)