From f6322802a3c3bcc351d08fba8275cc1a2ea6cd1f Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:58:13 +0300 Subject: [PATCH] Refactor --- src/Kiota.Builder/CodeDOM/CodeFile.cs | 4 ---- src/Kiota.Builder/Refiners/TypeScriptRefiner.cs | 15 ++++++--------- .../TypeScript/CodeFileDeclarationWriter.cs | 3 +-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Kiota.Builder/CodeDOM/CodeFile.cs b/src/Kiota.Builder/CodeDOM/CodeFile.cs index 27e9312598..9b52d59d7a 100644 --- a/src/Kiota.Builder/CodeDOM/CodeFile.cs +++ b/src/Kiota.Builder/CodeDOM/CodeFile.cs @@ -6,10 +6,6 @@ namespace Kiota.Builder.CodeDOM; public class CodeFile : CodeBlock { - public IEnumerable Namespaces => InnerChildElements.Values.OfType(); - public IEnumerable Classes => InnerChildElements.Values.OfType(); - public IEnumerable Enums => InnerChildElements.Values.OfType(); - public IEnumerable Functions => InnerChildElements.Values.OfType(); public IEnumerable Interfaces => InnerChildElements.Values.OfType(); public IEnumerable AddElements(params T[] elements) where T : CodeElement diff --git a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs index 9ca32ae83c..32b6d1f586 100644 --- a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs +++ b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs @@ -181,14 +181,11 @@ private static void GenerateModelCodeFile(CodeInterface codeInterface, CodeNames { if (element is CodeFunction codeFunction) { - if (codeFunction.OriginalLocalMethod.IsOfKind(CodeMethodKind.Deserializer, CodeMethodKind.Serializer)) + if (codeFunction.OriginalLocalMethod.IsOfKind(CodeMethodKind.Deserializer, CodeMethodKind.Serializer) && + codeFunction.OriginalLocalMethod.Parameters + .Any(x => x?.Type?.Name?.Equals(codeInterface.Name, StringComparison.OrdinalIgnoreCase) ?? false)) { - var exists = codeFunction.OriginalLocalMethod.Parameters - .Any(x => x?.Type?.Name?.Equals(codeInterface.Name, StringComparison.OrdinalIgnoreCase) ?? false); - - if (exists) - functions.Add(codeFunction); - + functions.Add(codeFunction); } else if (codeFunction.OriginalLocalMethod.IsOfKind(CodeMethodKind.Factory) && codeInterface.Name.EqualsIgnoreCase(codeFunction.OriginalMethodParentClass.Name) && @@ -198,8 +195,8 @@ private static void GenerateModelCodeFile(CodeInterface codeInterface, CodeNames } } } - String modelName = codeInterface.Name; - codeNamespace.TryAddCodeFile(modelName, functions.ToArray()); + + codeNamespace.TryAddCodeFile(codeInterface.Name, functions.ToArray()); } private static void GenerateRequestBuilderCodeFile(CodeClass codeClass, CodeNamespace codeNamespace) diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs index a065b4f35a..5fd774dad6 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs @@ -21,14 +21,13 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW { var usings = cf.GetChildElements().SelectMany(static x => { - var startBlockUsings = x switch + return x switch { CodeFunction f => f.StartBlock.Usings, CodeInterface ci => ci.Usings, CodeClass cc => cc.Usings, _ => Enumerable.Empty() }; - return startBlockUsings; } ); _codeUsingWriter.WriteCodeElement(usings, ns, writer);