From d8281415e2d3ad549937f2cf992613ee3ce95084 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 16 Feb 2022 12:03:33 -0500 Subject: [PATCH] - reflects kind refactoring after merge --- src/Kiota.Builder/KiotaBuilder.cs | 8 +- src/Kiota.Builder/Refiners/ShellRefiner.cs | 8 +- .../Writers/Shell/ShellCodeMethodWriter.cs | 6 +- .../Refiners/ShellRefinerTests.cs | 12 +-- .../Shell/ShellCodeMethodWriterTests.cs | 76 +++++++++---------- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index d39d7c44cb..8e47c8e361 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -647,7 +647,7 @@ private static void SetPathAndQueryParameters(CodeMethod target, OpenApiUrlTreeN Name = x.Name.TrimStart('$').SanitizePathParameterName(), Type = GetQueryParameterType(x.Schema), Description = x.Description, - ParameterKind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter, + Kind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter, Optional = !x.Required }) .Union(operation @@ -658,7 +658,7 @@ private static void SetPathAndQueryParameters(CodeMethod target, OpenApiUrlTreeN Name = x.Name.TrimStart('$').SanitizePathParameterName(), Type = GetQueryParameterType(x.Schema), Description = x.Description, - ParameterKind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter, + Kind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter, Optional = !x.Required })) .ToArray(); @@ -902,7 +902,7 @@ private CodeTypeBase GetCodeTypeForMapping(OpenApiUrlTreeNode currentNode, strin } var className = currentNode.GetClassName(schema: discriminatorSchema); var shouldInherit = discriminatorSchema.AllOf.Any(x => currentSchema.Reference.Id.Equals(x.Reference?.Id, StringComparison.OrdinalIgnoreCase)); - var codeClass = AddModelDeclarationIfDoesntExit(currentNode, discriminatorSchema, className, currentNamespace, shouldInherit ? currentClass : null); + var codeClass = AddModelDeclarationIfDoesntExist(currentNode, discriminatorSchema, className, currentNamespace, shouldInherit ? currentClass : null); return new CodeType { Name = codeClass.Name, TypeDefinition = codeClass, diff --git a/src/Kiota.Builder/Refiners/ShellRefiner.cs b/src/Kiota.Builder/Refiners/ShellRefiner.cs index 4da99c323f..94b8b02482 100644 --- a/src/Kiota.Builder/Refiners/ShellRefiner.cs +++ b/src/Kiota.Builder/Refiners/ShellRefiner.cs @@ -69,7 +69,7 @@ private static void CreateCommandBuilders(CodeElement currentElement) Name = "BuildRootCommand", Description = clientConstructor.Description, IsAsync = false, - MethodKind = CodeMethodKind.CommandBuilder, + Kind = CodeMethodKind.CommandBuilder, ReturnType = new CodeType { Name = "Command", IsExternal = true }, OriginalMethod = clientConstructor, }; @@ -95,7 +95,7 @@ private static void CreateCommandBuildersFromRequestExecutors(CodeClass currentC clone.Name = $"Build{cmdName}Command"; clone.Description = requestMethod.Description; clone.ReturnType = CreateCommandType(); - clone.MethodKind = CodeMethodKind.CommandBuilder; + clone.Kind = CodeMethodKind.CommandBuilder; clone.OriginalMethod = requestMethod; clone.SimpleName = cmdName; clone.ClearParameters(); @@ -112,7 +112,7 @@ private static void CreateCommandBuildersFromIndexers(CodeClass currentClass, IE { Name = "BuildCommand", IsAsync = false, - MethodKind = CodeMethodKind.CommandBuilder, + Kind = CodeMethodKind.CommandBuilder, OriginalIndexer = indexer }; @@ -139,7 +139,7 @@ private static CodeMethod CreateBuildCommandMethod(CodeProperty navProperty, Cod { IsAsync = false, Name = $"Build{navProperty.Name.ToFirstCharacterUpperCase()}Command", - MethodKind = CodeMethodKind.CommandBuilder + Kind = CodeMethodKind.CommandBuilder }; codeMethod.ReturnType = CreateCommandType(); codeMethod.AccessedProperty = navProperty; diff --git a/src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs b/src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs index 3fb24e70e0..bc038d15d9 100644 --- a/src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs @@ -186,7 +186,7 @@ private List WriteExecutableCommandOptions(LanguageWriter writer, List classMethods) { - if (codeElement.OriginalMethod?.MethodKind == CodeMethodKind.ClientConstructor) + if (codeElement.OriginalMethod?.Kind == CodeMethodKind.ClientConstructor) { - var commandBuilderMethods = classMethods.Where(m => m.MethodKind == CodeMethodKind.CommandBuilder && m != codeElement).OrderBy(m => m.Name); + var commandBuilderMethods = classMethods.Where(m => m.Kind == CodeMethodKind.CommandBuilder && m != codeElement).OrderBy(m => m.Name); writer.WriteLine($"var command = new RootCommand();"); WriteCommandDescription(codeElement, writer); foreach (var method in commandBuilderMethods) diff --git a/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs index b9cfa4dead..7059c9ba9d 100644 --- a/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs @@ -11,12 +11,12 @@ public class ShellRefinerTests { public void AddsUsingsForCommandTypesUsedInCommandBuilder() { var requestBuilder = root.AddClass(new CodeClass { Name = "somerequestbuilder", - ClassKind = CodeClassKind.RequestBuilder, + Kind = CodeClassKind.RequestBuilder, }).First(); var subNS = root.AddNamespace($"{root.Name}.subns"); // otherwise the import gets trimmed var commandBuilder = requestBuilder.AddMethod(new CodeMethod { Name = "GetCommand", - MethodKind = CodeMethodKind.CommandBuilder, + Kind = CodeMethodKind.CommandBuilder, ReturnType = new CodeType { Name = "Command", IsExternal = true @@ -33,13 +33,13 @@ public void AddsUsingsForCommandTypesUsedInCommandBuilder() { public void CreatesCommandBuilders() { var requestBuilder = root.AddClass(new CodeClass { Name = "somerequestbuilder", - ClassKind = CodeClassKind.RequestBuilder, + Kind = CodeClassKind.RequestBuilder, }).First(); var subNS = root.AddNamespace($"{root.Name}.subns"); // otherwise the import gets trimmed // Add nav props requestBuilder.AddProperty(new CodeProperty { Name = "User", - PropertyKind = CodePropertyKind.RequestBuilder + Kind = CodePropertyKind.RequestBuilder }); // Add indexer @@ -56,14 +56,14 @@ public void CreatesCommandBuilders() { ReturnType = new CodeType { Name = "User" }, - MethodKind = CodeMethodKind.RequestExecutor, + Kind = CodeMethodKind.RequestExecutor, HttpMethod = HttpMethod.Get }); // Add client constructor requestBuilder.AddMethod(new CodeMethod { Name = "constructor", - MethodKind = CodeMethodKind.ClientConstructor, + Kind = CodeMethodKind.ClientConstructor, ReturnType = new CodeType { Name = "void" }, diff --git a/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs index 3c3d19b003..67520bc184 100644 --- a/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs @@ -55,15 +55,15 @@ public void Dispose() private void AddRequestProperties() { parentClass.AddProperty(new CodeProperty { Name = "RequestAdapter", - PropertyKind = CodePropertyKind.RequestAdapter, + Kind = CodePropertyKind.RequestAdapter, }); parentClass.AddProperty(new CodeProperty { Name = "pathParameters", - PropertyKind = CodePropertyKind.PathParameters, + Kind = CodePropertyKind.PathParameters, }); parentClass.AddProperty(new CodeProperty { Name = "urlTemplate", - PropertyKind = CodePropertyKind.UrlTemplate, + Kind = CodePropertyKind.UrlTemplate, }); } @@ -73,33 +73,33 @@ private static void AddRequestBodyParameters(CodeMethod method) { }; method.AddParameter(new CodeParameter { Name = "h", - ParameterKind = CodeParameterKind.Headers, + Kind = CodeParameterKind.Headers, Type = stringType, }); method.AddParameter(new CodeParameter{ Name = "q", - ParameterKind = CodeParameterKind.QueryParameter, + Kind = CodeParameterKind.QueryParameter, Type = stringType, }); method.AddParameter(new CodeParameter{ Name = "b", - ParameterKind = CodeParameterKind.RequestBody, + Kind = CodeParameterKind.RequestBody, Type = stringType, }); method.AddParameter(new CodeParameter{ Name = "r", - ParameterKind = CodeParameterKind.ResponseHandler, + Kind = CodeParameterKind.ResponseHandler, Type = stringType, }); method.AddParameter(new CodeParameter { Name = "o", - ParameterKind = CodeParameterKind.Options, + Kind = CodeParameterKind.Options, Type = stringType, }); method.AddParameter(new CodeParameter { Name = "c", - ParameterKind = CodeParameterKind.Cancellation, + Kind = CodeParameterKind.Cancellation, Type = stringType, }); } @@ -110,7 +110,7 @@ private static void AddPathAndQueryParameters(CodeMethod method) { }; method.AddPathOrQueryParameter(new CodeParameter{ Name = "q", - ParameterKind = CodeParameterKind.QueryParameter, + Kind = CodeParameterKind.QueryParameter, Type = stringType, DefaultValue = "test", Description = "The q option", @@ -118,7 +118,7 @@ private static void AddPathAndQueryParameters(CodeMethod method) { }); method.AddPathOrQueryParameter(new CodeParameter { Name = "p", - ParameterKind = CodeParameterKind.Path, + Kind = CodeParameterKind.Path, Type = stringType }); } @@ -126,10 +126,10 @@ private static void AddPathAndQueryParameters(CodeMethod method) { [Fact] public void WritesRootCommand() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.ClientConstructor + Kind = CodeMethodKind.ClientConstructor }; writer.Write(method); @@ -144,14 +144,14 @@ public void WritesRootCommand() [Fact] public void WritesRootCommandWithCommandBuilderMethods() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.ClientConstructor + Kind = CodeMethodKind.ClientConstructor }; parentClass.AddMethod(new CodeMethod { Name = "BuildUserCommand", - MethodKind = CodeMethodKind.CommandBuilder + Kind = CodeMethodKind.CommandBuilder }); writer.Write(method); @@ -165,10 +165,10 @@ public void WritesRootCommandWithCommandBuilderMethods() [Fact] public void WritesIndexerCommands() { - method.MethodKind = CodeMethodKind.CommandBuilder; - var type = new CodeClass { Name = "TestClass", ClassKind = CodeClassKind.RequestBuilder }; - type.AddMethod(new CodeMethod { MethodKind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod1", ReturnType = new CodeType() }); - type.AddMethod(new CodeMethod { MethodKind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod2", ReturnType = new CodeType {CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array} }); + method.Kind = CodeMethodKind.CommandBuilder; + var type = new CodeClass { Name = "TestClass", Kind = CodeClassKind.RequestBuilder }; + type.AddMethod(new CodeMethod { Kind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod1", ReturnType = new CodeType() }); + type.AddMethod(new CodeMethod { Kind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod2", ReturnType = new CodeType {CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array} }); method.OriginalIndexer = new CodeIndexer { ReturnType = new CodeType { Name = "TestRequestBuilder", @@ -190,11 +190,11 @@ public void WritesIndexerCommands() { [Fact] public void WritesContainerCommands() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.SimpleName = "User"; - var type = new CodeClass { Name = "TestClass", ClassKind = CodeClassKind.RequestBuilder }; - type.AddMethod(new CodeMethod { MethodKind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod1", ReturnType = new CodeType() }); - type.AddMethod(new CodeMethod { MethodKind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod2", ReturnType = new CodeType {CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array} }); + var type = new CodeClass { Name = "TestClass", Kind = CodeClassKind.RequestBuilder }; + type.AddMethod(new CodeMethod { Kind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod1", ReturnType = new CodeType() }); + type.AddMethod(new CodeMethod { Kind = CodeMethodKind.CommandBuilder, Name = "BuildTestMethod2", ReturnType = new CodeType {CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array} }); type.Parent = new CodeType { Name = "Test.Name" }; @@ -221,19 +221,19 @@ public void WritesContainerCommands() { [Fact] public void WritesExecutableCommandForGetRequest() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.SimpleName = "User"; method.HttpMethod = HttpMethod.Get; var stringType = new CodeType { Name = "string", }; var generatorMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestGenerator, + Kind = CodeMethodKind.RequestGenerator, Name = "CreateGetRequestInformation", HttpMethod = method.HttpMethod }; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestExecutor, + Kind = CodeMethodKind.RequestExecutor, HttpMethod = method.HttpMethod, ReturnType = stringType, Parent = method.Parent @@ -261,26 +261,26 @@ public void WritesExecutableCommandForGetRequest() { [Fact] public void WritesExecutableCommandForPostRequest() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.SimpleName = "User"; method.HttpMethod = HttpMethod.Post; var stringType = new CodeType { Name = "string", }; var generatorMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestGenerator, + Kind = CodeMethodKind.RequestGenerator, Name = "CreatePostRequestInformation", HttpMethod = method.HttpMethod }; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestExecutor, + Kind = CodeMethodKind.RequestExecutor, HttpMethod = method.HttpMethod, ReturnType = stringType, Parent = method.Parent }; method.OriginalMethod.AddParameter(new CodeParameter{ Name = "body", - ParameterKind = CodeParameterKind.RequestBody, + Kind = CodeParameterKind.RequestBody, Type = stringType, }); var codeClass = method.Parent as CodeClass; @@ -309,7 +309,7 @@ public void WritesExecutableCommandForPostRequest() { public void WritesExecutableCommandForGetStreamRequest() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.SimpleName = "User"; method.HttpMethod = HttpMethod.Get; var streamType = new CodeType @@ -318,13 +318,13 @@ public void WritesExecutableCommandForGetStreamRequest() }; var generatorMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestGenerator, + Kind = CodeMethodKind.RequestGenerator, Name = "CreateGetRequestInformation", HttpMethod = method.HttpMethod }; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestExecutor, + Kind = CodeMethodKind.RequestExecutor, HttpMethod = method.HttpMethod, ReturnType = streamType, Parent = method.Parent @@ -354,7 +354,7 @@ public void WritesExecutableCommandForGetStreamRequest() [Fact] public void WritesExecutableCommandForPostVoidRequest() { - method.MethodKind = CodeMethodKind.CommandBuilder; + method.Kind = CodeMethodKind.CommandBuilder; method.SimpleName = "User"; method.HttpMethod = HttpMethod.Post; var stringType = new CodeType { @@ -364,19 +364,19 @@ public void WritesExecutableCommandForPostVoidRequest() { Name = "void", }; var generatorMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestGenerator, + Kind = CodeMethodKind.RequestGenerator, Name = "CreatePostRequestInformation", HttpMethod = method.HttpMethod }; method.OriginalMethod = new CodeMethod { - MethodKind = CodeMethodKind.RequestExecutor, + Kind = CodeMethodKind.RequestExecutor, HttpMethod = method.HttpMethod, ReturnType = voidType, Parent = method.Parent }; method.OriginalMethod.AddParameter(new CodeParameter{ Name = "body", - ParameterKind = CodeParameterKind.RequestBody, + Kind = CodeParameterKind.RequestBody, Type = stringType, }); var codeClass = method.Parent as CodeClass;