Skip to content

Commit 7828a9c

Browse files
authored
update types exporter to 7 (#30)
1 parent 4889172 commit 7828a9c

File tree

4 files changed

+350
-64
lines changed

4 files changed

+350
-64
lines changed

src/Nest.TypescriptExporter/ClientTypesExporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ private static string FormatMember(TsProperty property)
6363
var attributes = new List<Attribute>();
6464
if (ifaceProperty != null) attributes.AddRange(ifaceProperty.GetCustomAttributes());
6565
attributes.AddRange(property.MemberInfo.GetCustomAttributes());
66-
if (attributes.Any(a => a.TypeId.ToString() == "Nest.Json.JsonIgnoreAttribute"))
66+
if (attributes.Any(a => a.TypeId.ToString() == "System.Runtime.Serialization.IgnoreDataMemberAttribute"))
6767
property.IsIgnored = true;
6868

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

7272
var jsonPropertyAttribute = attributes.FirstOrDefault(a => a.TypeId.ToString() == "Nest.Json.JsonPropertyAttribute");
7373
if (jsonPropertyAttribute != null)

src/Nest.TypescriptExporter/ClientTypescriptGenerator.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public ClientTypescriptGenerator(CsharpTypeInfoProvider typeInfoProvider, CSharp
6464
typeof (AllField),
6565
#pragma warning restore 618
6666
typeof (Indices.ManyIndices),
67+
typeof (PostType),
68+
typeof (IDescriptor),
6769
});
6870

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

138-
void EnforceBaseClass<TInterface, TBase>()
140+
void EnforceBaseClass<TInterface, TBase>(bool force = false)
139141
{
140-
if (classModel.BaseType != null) return;
142+
if (!force && classModel.BaseType != null) return;
141143
if (classModel.Type == typeof(TBase)) return;
142144
if (typeof(TInterface).IsAssignableFrom(classModel.Type)) classModel.BaseType = new TsClass(typeof(TBase));
143145
}
@@ -148,6 +150,7 @@ void EnforceBaseClass<TInterface, TBase>()
148150
EnforceBaseClass<ICharFilter, CharFilterBase>();
149151
EnforceBaseClass<IProperty, PropertyBase>();
150152
EnforceBaseClass<IResponse, ResponseBase>();
153+
EnforceBaseClass<WriteResponseBase, WriteResponseBase>(true);
151154

152155
if (classModel.BaseType != null)
153156
{
@@ -192,6 +195,7 @@ private void GenerateProperties(TsClass classModel, ScriptBuilder sb, TsGenerato
192195
{
193196
foreach (var property in members)
194197
{
198+
if (property.Name == "IsValid") continue;
195199
if (property.IsIgnored ||
196200
PropertyTypesToIgnore(property.PropertyType.Type) ||
197201
(_typesPropertiesToIgnore.ContainsKey(classModel.Type) && _typesPropertiesToIgnore[classModel.Type].Contains(property.Name)))
@@ -254,7 +258,7 @@ private void AddDocCommentForCustomJsonConverter(ScriptBuilder sb, TsProperty pr
254258
sb.AppendLineIndented("@request_parameter()");
255259
}
256260

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

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

311315
private static bool GetConverter(Attribute converter, out Type type)
312316
{
313-
type = (Type) converter.GetType().GetProperty("ConverterType").GetGetMethod().Invoke(converter, new object[] { });
314-
if (type.Name.StartsWith("ReadAsTypeJsonConverter")) return true;
317+
type = (Type) converter.GetType().GetProperty("FormatterType").GetGetMethod().Invoke(converter, new object[] { });
318+
if (type.Name.StartsWith("ReadAsType")) return true;
315319
if (type.Name.StartsWith("VerbatimDictionary")) return true;
316320
if (type.Name.Contains("DictionaryResponse")) return true;
317321
if (type.Name.StartsWith("StringEnum")) return true;
@@ -445,6 +449,11 @@ protected bool Ignore(TsClass classModel)
445449
{
446450
if (TypeRenames.ContainsKey(classModel.Name)) return false;
447451
if (typeof(IRequestParameters).IsAssignableFrom(classModel.Type)) return true;
452+
if (typeof(IConnectionPool).IsAssignableFrom(classModel.Type)) return true;
453+
if (typeof(IConnection).IsAssignableFrom(classModel.Type)) return true;
454+
if (typeof(IElasticsearchSerializer).IsAssignableFrom(classModel.Type)) return true;
455+
if (typeof(IMemoryStreamFactory).IsAssignableFrom(classModel.Type)) return true;
456+
if (typeof(IPostData<>).IsAssignableFrom(classModel.Type)) return true;
448457
if (IsClrType(classModel.Type)) return true;
449458
if (_typesToIgnore.Contains(classModel.Type)) return true;
450459
return false;

src/Nest.TypescriptExporter/CsharpTypeInfoProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public CsharpTypeInfoProvider()
6868
private static bool TypeFilter(Type t) => TypeFilter(t, ExposedInterfacesImplementations);
6969

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

0 commit comments

Comments
 (0)