Skip to content

update types exporter to 7 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Nest.TypescriptExporter/ClientTypesExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ private static string FormatMember(TsProperty property)
var attributes = new List<Attribute>();
if (ifaceProperty != null) attributes.AddRange(ifaceProperty.GetCustomAttributes());
attributes.AddRange(property.MemberInfo.GetCustomAttributes());
if (attributes.Any(a => a.TypeId.ToString() == "Nest.Json.JsonIgnoreAttribute"))
if (attributes.Any(a => a.TypeId.ToString() == "System.Runtime.Serialization.IgnoreDataMemberAttribute"))
property.IsIgnored = true;

if (attributes.Any(a => a.TypeId.ToString() == "System.Runtime.Serialization.DataMemberAttribute"))
property.IsIgnored = true;
//if (attributes.Any(a => a.TypeId.ToString() == "System.Runtime.Serialization.DataMemberAttribute"))
// property.IsIgnored = true;

var jsonPropertyAttribute = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Nest.Json.JsonPropertyAttribute");
if (jsonPropertyAttribute != null)
Expand Down
21 changes: 15 additions & 6 deletions src/Nest.TypescriptExporter/ClientTypescriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public ClientTypescriptGenerator(CsharpTypeInfoProvider typeInfoProvider, CSharp
typeof (AllField),
#pragma warning restore 618
typeof (Indices.ManyIndices),
typeof (PostType),
typeof (IDescriptor),
});

private readonly Dictionary<Type, string[]> _typesPropertiesToIgnore = new Dictionary<Type, string[]>
Expand Down Expand Up @@ -135,9 +137,9 @@ private void AppendClassDef(TsClass classModel, ScriptBuilder sb, TsGeneratorOut
return;
}

void EnforceBaseClass<TInterface, TBase>()
void EnforceBaseClass<TInterface, TBase>(bool force = false)
{
if (classModel.BaseType != null) return;
if (!force && classModel.BaseType != null) return;
if (classModel.Type == typeof(TBase)) return;
if (typeof(TInterface).IsAssignableFrom(classModel.Type)) classModel.BaseType = new TsClass(typeof(TBase));
}
Expand All @@ -148,6 +150,7 @@ void EnforceBaseClass<TInterface, TBase>()
EnforceBaseClass<ICharFilter, CharFilterBase>();
EnforceBaseClass<IProperty, PropertyBase>();
EnforceBaseClass<IResponse, ResponseBase>();
EnforceBaseClass<WriteResponseBase, WriteResponseBase>(true);

if (classModel.BaseType != null)
{
Expand Down Expand Up @@ -192,6 +195,7 @@ private void GenerateProperties(TsClass classModel, ScriptBuilder sb, TsGenerato
{
foreach (var property in members)
{
if (property.Name == "IsValid") continue;
if (property.IsIgnored ||
PropertyTypesToIgnore(property.PropertyType.Type) ||
(_typesPropertiesToIgnore.ContainsKey(classModel.Type) && _typesPropertiesToIgnore[classModel.Type].Contains(property.Name)))
Expand Down Expand Up @@ -254,7 +258,7 @@ private void AddDocCommentForCustomJsonConverter(ScriptBuilder sb, TsProperty pr
sb.AppendLineIndented("@request_parameter()");
}

var converter = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Nest.Json.JsonConverterAttribute");
var converter = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Elasticsearch.Net.Utf8Json.JsonFormatterAttribute");
if (converter != null)
{
if (GetConverter(converter, out var type)) return;
Expand Down Expand Up @@ -294,7 +298,7 @@ private static void AddDocCommentForCustomJsonConverter(ScriptBuilder sb, TsClas
if (iface != null) attributes.AddRange(iface.GetCustomAttributes());
attributes.AddRange(classModel.Type.GetCustomAttributes());

var converter = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Nest.Json.JsonConverterAttribute");
var converter = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Elasticsearch.Net.Utf8Json.JsonFormatterAttribute");
if (converter != null)
{
if (GetConverter(converter, out var type)) return;
Expand All @@ -310,8 +314,8 @@ private static string GetDescriptorFor(Attribute attribute, string classModelNam

private static bool GetConverter(Attribute converter, out Type type)
{
type = (Type) converter.GetType().GetProperty("ConverterType").GetGetMethod().Invoke(converter, new object[] { });
if (type.Name.StartsWith("ReadAsTypeJsonConverter")) return true;
type = (Type) converter.GetType().GetProperty("FormatterType").GetGetMethod().Invoke(converter, new object[] { });
if (type.Name.StartsWith("ReadAsType")) return true;
if (type.Name.StartsWith("VerbatimDictionary")) return true;
if (type.Name.Contains("DictionaryResponse")) return true;
if (type.Name.StartsWith("StringEnum")) return true;
Expand Down Expand Up @@ -445,6 +449,11 @@ protected bool Ignore(TsClass classModel)
{
if (TypeRenames.ContainsKey(classModel.Name)) return false;
if (typeof(IRequestParameters).IsAssignableFrom(classModel.Type)) return true;
if (typeof(IConnectionPool).IsAssignableFrom(classModel.Type)) return true;
if (typeof(IConnection).IsAssignableFrom(classModel.Type)) return true;
if (typeof(IElasticsearchSerializer).IsAssignableFrom(classModel.Type)) return true;
if (typeof(IMemoryStreamFactory).IsAssignableFrom(classModel.Type)) return true;
if (typeof(IPostData<>).IsAssignableFrom(classModel.Type)) return true;
if (IsClrType(classModel.Type)) return true;
if (_typesToIgnore.Contains(classModel.Type)) return true;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Nest.TypescriptExporter/CsharpTypeInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public CsharpTypeInfoProvider()
private static bool TypeFilter(Type t) => TypeFilter(t, ExposedInterfacesImplementations);

private static bool TypeFilter(Type t, IEnumerable<Type> interfaces) =>
(t.IsEnum && !t.Namespace.StartsWith("Nest.Json") && (t.Namespace.StartsWith("Nest") || t.Namespace.StartsWith("Elasticsearch.Net")))
(t.IsEnum && !t.Namespace.StartsWith("Elasticsearch.Net.Utf8Json") && (t.Namespace.StartsWith("Nest") || t.Namespace.StartsWith("Elasticsearch.Net")))
|| (interfaces.Any(i=> i.IsAssignableFrom(t)) && t.IsClass && !BadClassRegex.IsMatch(t.Name));
}
}
Loading