From 61a370b2f066a74ca616c05c47124299f560a7b6 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 4 Aug 2023 14:15:56 -0400 Subject: [PATCH 1/3] - refactoring to allow code indexer parameters to carry descriptions --- src/Kiota.Builder/CodeDOM/CodeClass.cs | 2 +- src/Kiota.Builder/CodeDOM/CodeIndexer.cs | 37 ++++++++---------- src/Kiota.Builder/CodeDOM/CodeMethod.cs | 18 +++------ src/Kiota.Builder/KiotaBuilder.cs | 11 ++++-- .../Refiners/CommonLanguageRefiner.cs | 14 +++---- .../Writers/CSharp/CodeIndexerWriter.cs | 4 +- .../Writers/Java/CodeMethodWriter.cs | 2 +- .../Writers/Php/CodeMethodWriter.cs | 2 +- .../Writers/Python/CodeMethodWriter.cs | 2 +- .../Writers/Ruby/CodeMethodWriter.cs | 2 +- .../Writers/TypeScript/CodeMethodWriter.cs | 2 +- .../CodeDOM/CodeClassTests.cs | 38 +++++++++++-------- .../CodeDOM/CodeElementComparerPythonTests.cs | 10 +++-- .../CodeDOM/CodeElementComparerTests.cs | 18 +++++---- .../CodeDOM/CodeIndexerTests.cs | 3 +- .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 10 ++--- .../Refiners/CSharpLanguageRefinerTests.cs | 26 ++++++++----- .../Refiners/GoLanguageRefinerTests.cs | 35 ++++++++++------- .../Refiners/JavaLanguageRefinerTests.cs | 11 ++++-- .../Refiners/ShellRefinerTests.cs | 20 ++++++---- .../Writers/CSharp/CodeIndexerWriterTests.cs | 15 +++++--- .../Writers/Go/CodeMethodWriterTests.cs | 17 +++++---- .../Writers/Java/CodeMethodWriterTests.cs | 15 +++++--- .../Writers/Php/CodeMethodWriterTests.cs | 15 +++++--- .../Writers/Python/CodeMethodWriterTests.cs | 17 +++++---- .../Writers/Ruby/CodeMethodWriterTests.cs | 17 +++++---- .../Shell/ShellCodeMethodWriterTests.cs | 35 ++++++++++------- .../TypeScript/CodeMethodWriterTests.cs | 17 +++++---- 28 files changed, 235 insertions(+), 180 deletions(-) diff --git a/src/Kiota.Builder/CodeDOM/CodeClass.cs b/src/Kiota.Builder/CodeDOM/CodeClass.cs index 7b6112ca9c..2b4fcdbe7b 100644 --- a/src/Kiota.Builder/CodeDOM/CodeClass.cs +++ b/src/Kiota.Builder/CodeDOM/CodeClass.cs @@ -56,7 +56,7 @@ public void AddIndexer(params CodeIndexer[] indexers) foreach (var value in indexers) { var existingIndexers = InnerChildElements.Values.OfType().ToArray(); - if (Array.Exists(existingIndexers, x => !x.IndexParameterName.Equals(value.IndexParameterName, StringComparison.OrdinalIgnoreCase)) || + if (Array.Exists(existingIndexers, x => !x.IndexParameter.Name.Equals(value.IndexParameter.Name, StringComparison.OrdinalIgnoreCase)) || InnerChildElements.Values.OfType().Any(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility))) { foreach (var existingIndexer in existingIndexers) diff --git a/src/Kiota.Builder/CodeDOM/CodeIndexer.cs b/src/Kiota.Builder/CodeDOM/CodeIndexer.cs index 07131a0e1d..6ad3d6e0c2 100644 --- a/src/Kiota.Builder/CodeDOM/CodeIndexer.cs +++ b/src/Kiota.Builder/CodeDOM/CodeIndexer.cs @@ -3,18 +3,6 @@ namespace Kiota.Builder.CodeDOM; public class CodeIndexer : CodeTerminal, IDocumentedElement, IDeprecableElement, ICloneable { -#nullable disable // exposing property is required - private CodeTypeBase indexType; -#nullable enable - public required CodeTypeBase IndexType - { - get => indexType; set - { - ArgumentNullException.ThrowIfNull(value); - EnsureElementsAreChildren(value); - indexType = value; - } - } #nullable disable // exposing property is required private CodeTypeBase returnType; #nullable enable @@ -27,14 +15,21 @@ public required CodeTypeBase ReturnType returnType = value; } } +#nullable disable // exposing property is required + private CodeParameter indexParameter; +#nullable enable /// - /// The name of the parameter to use for the indexer. + /// The parameter to use for the indexer. /// - public required string IndexParameterName + public CodeParameter IndexParameter { - get; set; + get => indexParameter; set + { + ArgumentNullException.ThrowIfNull(value); + EnsureElementsAreChildren(value); + indexParameter = value; + } } - public string SerializationName { get; set; } = string.Empty; public CodeDocumentation Documentation { get; set; } = new(); /// /// The Path segment to use for the method name when using back-compatible methods. @@ -50,13 +45,11 @@ public object Clone() { Name = Name, Parent = Parent, - IndexType = IndexType.Clone() as CodeTypeBase ?? throw new InvalidOperationException($"Cloning failed. Cloned type is invalid."), - ReturnType = ReturnType.Clone() as CodeTypeBase ?? throw new InvalidOperationException($"Cloning failed. Cloned type is invalid."), - IndexParameterName = IndexParameterName, - SerializationName = SerializationName, - Documentation = Documentation.Clone() as CodeDocumentation ?? throw new InvalidOperationException($"Cloning failed. Cloned type is invalid."), + ReturnType = (CodeTypeBase)ReturnType.Clone(), + Documentation = (CodeDocumentation)Documentation.Clone(), PathSegment = PathSegment, - Deprecation = Deprecation == null ? null : Deprecation with { } + Deprecation = Deprecation == null ? null : Deprecation with { }, + IndexParameter = (CodeParameter)IndexParameter.Clone(), }; } } diff --git a/src/Kiota.Builder/CodeDOM/CodeMethod.cs b/src/Kiota.Builder/CodeDOM/CodeMethod.cs index c34b4d1157..eeb316bf16 100644 --- a/src/Kiota.Builder/CodeDOM/CodeMethod.cs +++ b/src/Kiota.Builder/CodeDOM/CodeMethod.cs @@ -90,11 +90,8 @@ public static CodeMethod FromIndexer(CodeIndexer originalIndexer, Func IsIndexerTypeSpecificVersion = - (currentIndexerParameterName, existingIndexer) => currentIndexerParameterName.Equals(existingIndexer.IndexParameterName, StringComparison.OrdinalIgnoreCase) && !"string".Equals(existingIndexer.IndexType.Name, StringComparison.OrdinalIgnoreCase); + (currentIndexerParameterName, existingIndexer) => currentIndexerParameterName.Equals(existingIndexer.IndexParameter.Name, StringComparison.OrdinalIgnoreCase) && !"string".Equals(existingIndexer.IndexParameter.Type.Name, StringComparison.OrdinalIgnoreCase); protected static void ReplaceIndexersByMethodsWithParameter(CodeElement currentElement, bool parameterNullable, Func methodNameCallback, Func parameterNameCallback, GenerationLanguage language) { if (currentElement is CodeIndexer currentIndexer && @@ -699,18 +699,18 @@ protected static void ReplaceIndexersByMethodsWithParameter(CodeElement currentE if (indexerParentClass.ContainsMember(currentElement.Name)) // TODO remove condition for v2 necessary because of the second case of Go block indexerParentClass.RemoveChildElement(currentElement); //TODO remove who block except for last else if body for v2 - var isIndexerStringBackwardCompatible = "string".Equals(currentIndexer.IndexType.Name, StringComparison.OrdinalIgnoreCase) && + var isIndexerStringBackwardCompatible = "string".Equals(currentIndexer.IndexParameter.Type.Name, StringComparison.OrdinalIgnoreCase) && currentIndexer.Deprecation is not null && currentIndexer.Deprecation.IsDeprecated && - (indexerParentClass.Methods.Any(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.OriginalIndexer is not null && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameterName, x.OriginalIndexer)) || - (indexerParentClass.Indexer != null && indexerParentClass.Indexer != currentIndexer && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameterName, indexerParentClass.Indexer))); + (indexerParentClass.Methods.Any(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.OriginalIndexer is not null && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameter.Name, x.OriginalIndexer)) || + (indexerParentClass.Indexer != null && indexerParentClass.Indexer != currentIndexer && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameter.Name, indexerParentClass.Indexer))); if (isIndexerStringBackwardCompatible && language == GenerationLanguage.Go) { - if (indexerParentClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.OriginalIndexer is not null && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameterName, x.OriginalIndexer)) is CodeMethod typeSpecificCompatibleMethod && + if (indexerParentClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.OriginalIndexer is not null && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameter.Name, x.OriginalIndexer)) is CodeMethod typeSpecificCompatibleMethod && typeSpecificCompatibleMethod.OriginalIndexer is not null) { - indexerParentClass.RenameChildElement(typeSpecificCompatibleMethod.Name, typeSpecificCompatibleMethod.Name + typeSpecificCompatibleMethod.OriginalIndexer.IndexType.Name.ToFirstCharacterUpperCase()); + indexerParentClass.RenameChildElement(typeSpecificCompatibleMethod.Name, typeSpecificCompatibleMethod.Name + typeSpecificCompatibleMethod.OriginalIndexer.IndexParameter.Type.Name.ToFirstCharacterUpperCase()); } - else if (indexerParentClass.Indexer != null && indexerParentClass.Indexer != currentIndexer && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameterName, indexerParentClass.Indexer)) + else if (indexerParentClass.Indexer != null && indexerParentClass.Indexer != currentIndexer && IsIndexerTypeSpecificVersion(currentIndexer.IndexParameter.Name, indexerParentClass.Indexer)) { var specificIndexer = indexerParentClass.Indexer; indexerParentClass.RemoveChildElement(specificIndexer); diff --git a/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs index aefe8ae604..062e393e65 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs @@ -14,9 +14,9 @@ public override void WriteCodeElement(CodeIndexer codeElement, LanguageWriter wr var returnType = conventions.GetTypeString(codeElement.ReturnType, codeElement); conventions.WriteShortDescription(codeElement.Documentation.Description, writer); conventions.WriteDeprecationAttribute(codeElement, writer); - writer.StartBlock($"public {returnType} this[{conventions.GetTypeString(codeElement.IndexType, codeElement)} position] {{ get {{"); + writer.StartBlock($"public {returnType} this[{conventions.GetTypeString(codeElement.IndexParameter.Type, codeElement)} position] {{ get {{"); if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProp) - conventions.AddParametersAssignment(writer, pathParametersProp.Type, pathParametersProp.Name.ToFirstCharacterUpperCase(), string.Empty, (codeElement.IndexType, codeElement.SerializationName, "position")); + conventions.AddParametersAssignment(writer, pathParametersProp.Type, pathParametersProp.Name.ToFirstCharacterUpperCase(), string.Empty, (codeElement.IndexParameter.Type, codeElement.IndexParameter.SerializationName, "position")); conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName, "return "); writer.CloseBlock("} }"); } diff --git a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs index 0e5eb70874..13de9693a3 100644 --- a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs @@ -379,7 +379,7 @@ private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, Lan { if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProperty && codeElement.OriginalIndexer != null) conventions.AddParametersAssignment(writer, pathParametersProperty.Type, $"this.{pathParametersProperty.Name}", - parameters: (codeElement.OriginalIndexer.IndexType, codeElement.OriginalIndexer.SerializationName, codeElement.OriginalIndexer.IndexParameterName.ToFirstCharacterLowerCase())); + parameters: (codeElement.OriginalIndexer.IndexParameter.Type, codeElement.OriginalIndexer.IndexParameter.SerializationName, codeElement.OriginalIndexer.IndexParameter.Name.ToFirstCharacterLowerCase())); conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName); } private void WriteDeserializerBody(CodeMethod codeElement, CodeClass parentClass, LanguageWriter writer, bool inherits) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 283f8634d6..02d4a83423 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -675,7 +675,7 @@ private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, str if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProperty && codeElement.OriginalIndexer != null) conventions.AddParametersAssignment(writer, pathParametersProperty.Type, $"$this->{pathParametersProperty.Name}", - (codeElement.OriginalIndexer.IndexType, codeElement.OriginalIndexer.SerializationName, $"${codeElement.OriginalIndexer.IndexParameterName.ToFirstCharacterLowerCase()}")); + (codeElement.OriginalIndexer.IndexParameter.Type, codeElement.OriginalIndexer.IndexParameter.SerializationName, $"${codeElement.OriginalIndexer.IndexParameter.Name.ToFirstCharacterLowerCase()}")); conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName, pathParameters); } diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index 20641cf615..0c9bf13081 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -221,7 +221,7 @@ private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, str if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProperty && codeElement.OriginalIndexer != null) conventions.AddParametersAssignment(writer, pathParametersProperty.Type, $"self.{pathParametersProperty.Name}", - (codeElement.OriginalIndexer.IndexType, codeElement.OriginalIndexer.SerializationName, codeElement.OriginalIndexer.IndexParameterName.ToSnakeCase())); + (codeElement.OriginalIndexer.IndexParameter.Type, codeElement.OriginalIndexer.IndexParameter.SerializationName, codeElement.OriginalIndexer.IndexParameter.Name.ToSnakeCase())); conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName); } private void WriteRequestBuilderWithParametersBody(CodeMethod codeElement, CodeClass parentClass, string returnType, LanguageWriter writer) diff --git a/src/Kiota.Builder/Writers/Ruby/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Ruby/CodeMethodWriter.cs index 3648eb988c..bd33e10fb1 100644 --- a/src/Kiota.Builder/Writers/Ruby/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Ruby/CodeMethodWriter.cs @@ -204,7 +204,7 @@ private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, Lan if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProperty && codeElement.OriginalIndexer != null) writer.WriteLines($"{conventions.TempDictionaryVarName} = @{pathParametersProperty.NamePrefix}{pathParametersProperty.Name.ToSnakeCase()}.clone", - $"{conventions.TempDictionaryVarName}[\"{codeElement.OriginalIndexer.SerializationName}\"] = {codeElement.OriginalIndexer.IndexParameterName.ToSnakeCase()}"); + $"{conventions.TempDictionaryVarName}[\"{codeElement.OriginalIndexer.IndexParameter.SerializationName}\"] = {codeElement.OriginalIndexer.IndexParameter.Name.ToSnakeCase()}"); conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName, $"return {prefix}"); } private void WriteDeserializerBody(CodeClass parentClass, LanguageWriter writer) diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeMethodWriter.cs index 79b93e5f81..4382c5a6b3 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeMethodWriter.cs @@ -119,7 +119,7 @@ private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, str codeElement.OriginalIndexer != null) { localConventions.AddParametersAssignment(writer, pathParametersProperty.Type, $"this.{pathParametersProperty.Name}", - parameters: (codeElement.OriginalIndexer.IndexType, codeElement.OriginalIndexer.SerializationName, codeElement.OriginalIndexer.IndexParameterName.ToFirstCharacterLowerCase())); + parameters: (codeElement.OriginalIndexer.IndexParameter.Type, codeElement.OriginalIndexer.IndexParameter.SerializationName, codeElement.OriginalIndexer.IndexParameter.Name.ToFirstCharacterLowerCase())); } conventions.AddRequestBuilderBody(parentClass, returnType, writer, conventions.TempDictionaryVarName); } diff --git a/tests/Kiota.Builder.Tests/CodeDOM/CodeClassTests.cs b/tests/Kiota.Builder.Tests/CodeDOM/CodeClassTests.cs index 463485d360..de89de8fb5 100644 --- a/tests/Kiota.Builder.Tests/CodeDOM/CodeClassTests.cs +++ b/tests/Kiota.Builder.Tests/CodeDOM/CodeClassTests.cs @@ -53,20 +53,23 @@ public void SetsIndexer() codeClass.AddIndexer(new CodeIndexer { Name = "idx", - SerializationName = "idx_smth", - IndexType = new CodeType - { - Name = "string", - IsExternal = true, - IsNullable = true, - }, ReturnType = new CodeType { Name = "string", IsExternal = true, IsNullable = true, }, - IndexParameterName = "idxSmth", + IndexParameter = new() + { + Name = "idxSmth", + SerializationName = "idx_smth", + Type = new CodeType + { + Name = "string", + IsExternal = true, + IsNullable = true, + }, + } }); Assert.Single(codeClass.GetChildElements(true).OfType()); Assert.Throws(() => @@ -76,20 +79,23 @@ public void SetsIndexer() codeClass.AddIndexer(new CodeIndexer { Name = "idx2", - SerializationName = "idx-2", - IndexType = new CodeType - { - Name = "string", - IsExternal = true, - IsNullable = true, - }, ReturnType = new CodeType { Name = "string", IsExternal = true, IsNullable = true, }, - IndexParameterName = "idx2", + IndexParameter = new() + { + Name = "idx2", + SerializationName = "idx-2", + Type = new CodeType + { + Name = "string", + IsExternal = true, + IsNullable = true, + }, + } }); Assert.Empty(codeClass.GetChildElements(true).OfType()); var methods = codeClass.GetChildElements(true).OfType().Where(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility)).ToArray(); diff --git a/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerPythonTests.cs b/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerPythonTests.cs index e7549e91e8..717306bb37 100644 --- a/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerPythonTests.cs +++ b/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerPythonTests.cs @@ -48,10 +48,12 @@ public void OrdersWithMethodWithinClass() ReturnType = new CodeType { Name = "string" }, - IndexType = new CodeType { - Name = "string" - }, - IndexParameterName = "param" + IndexParameter = new() { + Name = "param", + Type = new CodeType { + Name = "string" + }, + } }, new CodeProperty() { Name = "prop", Type = new CodeType { diff --git a/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerTests.cs b/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerTests.cs index 0d9976293b..efac713cdf 100644 --- a/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerTests.cs +++ b/tests/Kiota.Builder.Tests/CodeDOM/CodeElementComparerTests.cs @@ -48,10 +48,12 @@ public void OrdersWithMethodWithinClass() ReturnType = new CodeType { Name = "string" }, - IndexType = new CodeType { + IndexParameter = new() { + Name = "param", + Type = new CodeType { Name = "string" - }, - IndexParameterName = "param" + }, + } }, new CodeProperty() { Name = "prop", Type = new CodeType { @@ -113,10 +115,12 @@ public void OrdersWithMethodsOutsideOfClass() ReturnType = new CodeType { Name = "string" }, - IndexType = new CodeType { - Name = "string" - }, - IndexParameterName = "param" + IndexParameter = new() { + Name = "param", + Type = new CodeType { + Name = "string" + }, + } }, new CodeProperty() { Name = "prop", Type = new CodeType { diff --git a/tests/Kiota.Builder.Tests/CodeDOM/CodeIndexerTests.cs b/tests/Kiota.Builder.Tests/CodeDOM/CodeIndexerTests.cs index 351073ba61..9828ae870a 100644 --- a/tests/Kiota.Builder.Tests/CodeDOM/CodeIndexerTests.cs +++ b/tests/Kiota.Builder.Tests/CodeDOM/CodeIndexerTests.cs @@ -14,9 +14,8 @@ public void IndexerInits() { Description = "some description", }, - IndexType = new CodeType(), ReturnType = new CodeType(), - IndexParameterName = "param", + IndexParameter = new() { Name = "param", Type = new CodeType(), } }; } } diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 7b4afffaba..167058e9ac 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -5711,7 +5711,7 @@ public async Task IndexerAndRequestBuilderNamesMatch() var collectionRequestBuilder = collectionRequestBuilderNamespace.FindChildByName("postsRequestBuilder"); var collectionIndexer = collectionRequestBuilder.Indexer; Assert.NotNull(collectionIndexer); - Assert.Equal("string", collectionIndexer.IndexType.Name); + Assert.Equal("string", collectionIndexer.IndexParameter.Type.Name); Assert.False(collectionIndexer.Deprecation.IsDeprecated); var itemRequestBuilderNamespace = codeModel.FindNamespaceByName("ApiSdk.me.posts.item"); Assert.NotNull(itemRequestBuilderNamespace); @@ -5764,13 +5764,13 @@ public async Task IndexerTypeIsAccurateAndBackwardCompatibleIndexersAreAdded() var collectionRequestBuilder = collectionRequestBuilderNamespace.FindChildByName("postsRequestBuilder"); var collectionIndexer = collectionRequestBuilder.Indexer; Assert.NotNull(collectionIndexer); - Assert.Equal("integer", collectionIndexer.IndexType.Name); - Assert.False(collectionIndexer.IndexType.IsNullable); + Assert.Equal("integer", collectionIndexer.IndexParameter.Type.Name); + Assert.False(collectionIndexer.IndexParameter.Type.IsNullable); Assert.False(collectionIndexer.Deprecation.IsDeprecated); var collectionStringIndexer = collectionRequestBuilder.FindChildByName($"{collectionIndexer.Name}-string"); Assert.NotNull(collectionStringIndexer); - Assert.Equal("string", collectionStringIndexer.IndexType.Name); - Assert.True(collectionStringIndexer.IndexType.IsNullable); + Assert.Equal("string", collectionStringIndexer.IndexParameter.Type.Name); + Assert.True(collectionStringIndexer.IndexParameter.Type.IsNullable); Assert.True(collectionStringIndexer.Deprecation.IsDeprecated); var itemRequestBuilderNamespace = codeModel.FindNamespaceByName("ApiSdk.me.posts.item"); Assert.NotNull(itemRequestBuilderNamespace); diff --git a/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs index 37a83c9349..d363612d99 100644 --- a/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs @@ -237,13 +237,16 @@ public async Task EscapesReservedKeywordsForReservedNamespaceNameSegments() var indexer = new CodeIndexer { Name = "idx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - }, ReturnType = indexerCodeType, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + SerializationName = "id", + Type = new CodeType + { + Name = "string", + }, + } }; requestBuilder.AddIndexer(indexer); @@ -309,11 +312,14 @@ public async Task ConvertsUnionTypesToWrapper() { Name = "idx", ReturnType = union.Clone() as CodeTypeBase, - IndexType = new CodeType + IndexParameter = new() { - Name = "string" - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string" + }, + } }; model.AddIndexer(indexer); method.AddParameter(parameter); diff --git a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs index 63e3528c71..29079667ff 100644 --- a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs @@ -340,11 +340,14 @@ public async Task ConvertsUnionTypesToWrapper() { Name = "idx", ReturnType = union.Clone() as CodeTypeBase, - IndexType = new CodeType + IndexParameter = new() { - Name = "string" - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string" + }, + } }; model.AddIndexer(indexer); method.AddParameter(parameter); @@ -397,11 +400,14 @@ public async Task SupportsTypeSpecificOverrideIndexers() { Name = "idx-string", ReturnType = union.Clone() as CodeTypeBase, - IndexType = new CodeType + IndexParameter = new() { - Name = "string" + Name = "id", + Type = new CodeType + { + Name = "string" + }, }, - IndexParameterName = "id", Deprecation = new("foo") }; var typeSpecificIndexer = new CodeIndexer @@ -412,19 +418,22 @@ public async Task SupportsTypeSpecificOverrideIndexers() Name = "type1", TypeDefinition = union.Types.First(), }, - IndexType = new CodeType + IndexParameter = new() { - Name = "integer" - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "integer" + }, + } }; model.AddIndexer(indexer, typeSpecificIndexer); Assert.NotNull(model.Indexer); method.AddParameter(parameter); await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go }, root); Assert.Null(model.Indexer); - Assert.NotNull(model.Methods.SingleOrDefault(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.Name.Equals("ByIdInteger") && x.OriginalIndexer != null && x.OriginalIndexer.IndexType.Name.Equals("Integer", StringComparison.OrdinalIgnoreCase))); - Assert.NotNull(model.Methods.SingleOrDefault(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.Name.Equals("ById") && x.OriginalIndexer != null && x.OriginalIndexer.IndexType.Name.Equals("string", StringComparison.OrdinalIgnoreCase))); + Assert.NotNull(model.Methods.SingleOrDefault(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.Name.Equals("ByIdInteger") && x.OriginalIndexer != null && x.OriginalIndexer.IndexParameter.Type.Name.Equals("Integer", StringComparison.OrdinalIgnoreCase))); + Assert.NotNull(model.Methods.SingleOrDefault(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.Name.Equals("ById") && x.OriginalIndexer != null && x.OriginalIndexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase))); } [Fact] public async Task AddsExceptionInheritanceOnErrorClasses() diff --git a/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs index 1f70409d70..0396fb8221 100644 --- a/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs @@ -342,11 +342,14 @@ public async Task ReplacesIndexersByMethodsWithParameter() Name = requestBuilder.Name, TypeDefinition = requestBuilder, }, - IndexType = new CodeType + IndexParameter = new() { - Name = "string", - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string", + }, + } }); var collectionRequestBuilder = collectionNS.AddClass(new CodeClass { diff --git a/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs index cda049a0c1..3fe9f02c14 100644 --- a/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/ShellRefinerTests.cs @@ -107,11 +107,14 @@ public async Task CreatesCommandBuilders() { Name = "Address" }, - IndexType = new CodeType + IndexParameter = new() { - Name = "string" - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string" + }, + } }); // Add request executor @@ -266,10 +269,13 @@ public async Task RenamesNavPropertiesInIndexersWithConflicts() var indexer = new CodeIndexer { Name = "test-idx", - IndexParameterName = "test-idx", - IndexType = new CodeType + IndexParameter = new() { - Name = "Test", + Name = "test-idx", + Type = new CodeType + { + Name = "Test", + }, }, ReturnType = new CodeType { diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs index a027b14b25..fcf7c14c16 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs @@ -29,16 +29,19 @@ public CodeIndexerWriterTests() indexer = new CodeIndexer { Name = "idx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - }, ReturnType = new CodeType { Name = "SomeRequestBuilder" }, - IndexParameterName = "position" + IndexParameter = new() + { + Name = "position", + Type = new CodeType + { + Name = "string", + }, + SerializationName = "id", + } }; parentClass.AddIndexer(indexer); parentClass.AddProperty(new() diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index 7dbb644e19..cc45fc1ae6 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -1577,17 +1577,20 @@ public void WritesIndexer() parentClass.AddIndexer(new CodeIndexer { Name = "indx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - IsNullable = true, - }, ReturnType = new CodeType { Name = "Somecustomtype", }, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + SerializationName = "id", + Type = new CodeType + { + Name = "string", + IsNullable = true, + }, + } }); if (parentClass.Indexer is null) throw new InvalidOperationException("Indexer is null"); diff --git a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs index cf043d8c89..a97e2d79c0 100644 --- a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs @@ -1595,16 +1595,19 @@ public void WritesIndexer() method.OriginalIndexer = new CodeIndexer { Name = "idx", - IndexType = new CodeType - { - Name = "int" - }, - SerializationName = "collectionId", ReturnType = new CodeType { Name = "string" }, - IndexParameterName = "id" + IndexParameter = new() + { + Name = "id", + SerializationName = "collectionId", + Type = new CodeType + { + Name = "int" + }, + } }; writer.Write(method); var result = tw.ToString(); diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs index 4dd748d0fa..79b29b18b1 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs @@ -716,16 +716,19 @@ public async Task WriteIndexerBody() OriginalIndexer = new CodeIndexer { Name = "messageById", - SerializationName = "message_id", - IndexType = new CodeType - { - Name = "MessageRequestBuilder" - }, ReturnType = new CodeType { Name = "MessageRequestBuilder" }, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + SerializationName = "message_id", + Type = new CodeType + { + Name = "MessageRequestBuilder" + }, + } }, OriginalMethod = new CodeMethod { diff --git a/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs index 0264a9d322..4b9e2a22d0 100644 --- a/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs @@ -1308,17 +1308,20 @@ public void WritesIndexer() method.OriginalIndexer = new() { Name = "indx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - IsNullable = true, - }, ReturnType = new CodeType { Name = "string", }, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + Type = new CodeType + { + Name = "string", + IsNullable = true, + }, + SerializationName = "id", + } }; writer.Write(method); var result = tw.ToString(); diff --git a/tests/Kiota.Builder.Tests/Writers/Ruby/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Ruby/CodeMethodWriterTests.cs index a279babe1a..c52b62cf94 100644 --- a/tests/Kiota.Builder.Tests/Writers/Ruby/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Ruby/CodeMethodWriterTests.cs @@ -728,17 +728,20 @@ public void WritesIndexer() method.OriginalIndexer = new() { Name = "indx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - IsNullable = true, - }, ReturnType = new CodeType { Name = "string", }, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + SerializationName = "id", + Type = new CodeType + { + Name = "string", + IsNullable = true, + }, + } }; writer.Write(method); var result = tw.ToString(); diff --git a/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs index 1f080c18ff..6cd6aaf1bd 100644 --- a/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Shell/ShellCodeMethodWriterTests.cs @@ -231,12 +231,15 @@ public void WritesIndexerCommands() Name = "TestItemRequestBuilder", TypeDefinition = type }, - IndexType = new CodeType + IndexParameter = new() { - Name = "string", - }, - SerializationName = "test", - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string", + }, + SerializationName = "test", + } }; AddRequestProperties(); @@ -312,11 +315,14 @@ public void WritesMatchingIndexerCommandsIntoExecutableCommand() { ReturnType = indexerReturn, Name = "testItem-idx", - IndexType = new CodeType + IndexParameter = new() { - Name = "string", - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string", + }, + } } }; @@ -402,11 +408,14 @@ public void WritesMatchingIndexerCommandsIntoContainerCommand() { ReturnType = indexerReturn, Name = "testItem-indexer", - IndexType = new CodeType + IndexParameter = new() { - Name = "string", - }, - IndexParameterName = "id", + Name = "id", + Type = new CodeType + { + Name = "string", + }, + } } }; diff --git a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeMethodWriterTests.cs index d0b62e1b80..0b44ff3a52 100644 --- a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeMethodWriterTests.cs @@ -476,17 +476,20 @@ public void WritesIndexer() method.OriginalIndexer = new() { Name = "indx", - SerializationName = "id", - IndexType = new CodeType - { - Name = "string", - IsNullable = true, - }, ReturnType = new CodeType { Name = "string", }, - IndexParameterName = "id", + IndexParameter = new() + { + Name = "id", + SerializationName = "id", + Type = new CodeType + { + Name = "string", + IsNullable = true, + }, + } }; writer.Write(method); var result = tw.ToString(); From c7ecd1d02f6f104e51c0c49fb6a34964a3708b91 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 4 Aug 2023 14:31:04 -0400 Subject: [PATCH 2/3] - adds support for indexer parameter description Signed-off-by: Vincent Biret --- CHANGELOG.md | 2 ++ src/Kiota.Builder/KiotaBuilder.cs | 25 +++++++++++-------- .../Writers/CSharp/CodeIndexerWriter.cs | 1 + .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 5 +++- .../Writers/CSharp/CodeIndexerWriterTests.cs | 5 ++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9f7440cb..d769f1fd89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added support for indexer parameter description. [#2978](https://github.com/microsoft/kiota/issues/2978) + ### Changed ## [1.5.0] - 2023-08-04 diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 3e0558e25a..e1574a21a6 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -971,7 +971,7 @@ private IEnumerable GetUnmappedTypeDefinitions(CodeElement codeElement }; } private static CodeType DefaultIndexerParameterType => new() { Name = "string", IsExternal = true }; - private CodeType GetIndexerParameterType(OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode parentNode) + private CodeParameter GetIndexerParameterType(OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode parentNode) { var parameterName = currentNode.Path[parentNode.Path.Length..].Trim('\\', ForwardSlash, '{', '}'); var parameter = currentNode.PathItems.TryGetValue(Constants.DefaultOpenApiLabel, out var pathItem) ? pathItem.Parameters @@ -987,9 +987,19 @@ private CodeType GetIndexerParameterType(OpenApiUrlTreeNode currentNode, OpenApi _ => GetPrimitiveType(parameter.Schema), } ?? DefaultIndexerParameterType; type.IsNullable = false; - return type; + var result = new CodeParameter + { + Type = type, + SerializationName = currentNode.Segment.SanitizeParameterNameForUrlTemplate(), + Name = currentNode.Segment.CleanupSymbolName(), + Documentation = new() + { + Description = parameter?.Description.CleanupDescription() is string description && !string.IsNullOrEmpty(description) ? description : "Unique identifier of the item", + }, + }; + return result; } - private CodeIndexer[] CreateIndexer(string childIdentifier, string childType, CodeType parameterType, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode parentNode) + private CodeIndexer[] CreateIndexer(string childIdentifier, string childType, CodeParameter parameter, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode parentNode) { logger.LogTrace("Creating indexer {Name}", childIdentifier); var result = new List { new CodeIndexer @@ -1002,15 +1012,10 @@ private CodeIndexer[] CreateIndexer(string childIdentifier, string childType, Co ReturnType = new CodeType { Name = childType }, PathSegment = parentNode.GetNodeNamespaceFromPath(string.Empty).Split('.').Last(), Deprecation = currentNode.GetDeprecationInformation(), - IndexParameter = new() { - Type = parameterType, - SerializationName = currentNode.Segment.SanitizeParameterNameForUrlTemplate(), - Name = currentNode.Segment.CleanupSymbolName(), - //TODO description - } + IndexParameter = parameter, }}; - if (!"string".Equals(parameterType.Name, StringComparison.OrdinalIgnoreCase)) + if (!"string".Equals(parameter.Type.Name, StringComparison.OrdinalIgnoreCase)) { // adding a second indexer for the string version of the parameter so we keep backward compatibility //TODO remove for v2 var backCompatibleValue = (CodeIndexer)result[0].Clone(); diff --git a/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs index 062e393e65..1fb64158b2 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeIndexerWriter.cs @@ -13,6 +13,7 @@ public override void WriteCodeElement(CodeIndexer codeElement, LanguageWriter wr if (codeElement.Parent is not CodeClass parentClass) throw new InvalidOperationException("The parent of a property should be a class"); var returnType = conventions.GetTypeString(codeElement.ReturnType, codeElement); conventions.WriteShortDescription(codeElement.Documentation.Description, writer); + writer.WriteLine($"{conventions.DocCommentPrefix}{codeElement.IndexParameter.Documentation.Description.CleanupXMLString()}"); conventions.WriteDeprecationAttribute(codeElement, writer); writer.StartBlock($"public {returnType} this[{conventions.GetTypeString(codeElement.IndexParameter.Type, codeElement)} position] {{ get {{"); if (parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters) is CodeProperty pathParametersProp) diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 167058e9ac..b29f9c0034 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -5711,7 +5711,8 @@ public async Task IndexerAndRequestBuilderNamesMatch() var collectionRequestBuilder = collectionRequestBuilderNamespace.FindChildByName("postsRequestBuilder"); var collectionIndexer = collectionRequestBuilder.Indexer; Assert.NotNull(collectionIndexer); - Assert.Equal("string", collectionIndexer.IndexParameter.Type.Name); + Assert.Equal("string", collectionIndexer.IndexParameter.Type.Name, StringComparer.OrdinalIgnoreCase); + Assert.Equal("Unique identifier of the item", collectionIndexer.IndexParameter.Documentation.Description, StringComparer.OrdinalIgnoreCase); Assert.False(collectionIndexer.Deprecation.IsDeprecated); var itemRequestBuilderNamespace = codeModel.FindNamespaceByName("ApiSdk.me.posts.item"); Assert.NotNull(itemRequestBuilderNamespace); @@ -5735,6 +5736,7 @@ public async Task IndexerTypeIsAccurateAndBackwardCompatibleIndexersAreAdded() - name: post-id in: path required: true + description: The id of the pet to retrieve schema: type: integer format: int32 @@ -5765,6 +5767,7 @@ public async Task IndexerTypeIsAccurateAndBackwardCompatibleIndexersAreAdded() var collectionIndexer = collectionRequestBuilder.Indexer; Assert.NotNull(collectionIndexer); Assert.Equal("integer", collectionIndexer.IndexParameter.Type.Name); + Assert.Equal("The id of the pet to retrieve", collectionIndexer.IndexParameter.Documentation.Description, StringComparer.OrdinalIgnoreCase); Assert.False(collectionIndexer.IndexParameter.Type.IsNullable); Assert.False(collectionIndexer.Deprecation.IsDeprecated); var collectionStringIndexer = collectionRequestBuilder.FindChildByName($"{collectionIndexer.Name}-string"); diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs index fcf7c14c16..568a87fe85 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeIndexerWriterTests.cs @@ -41,6 +41,10 @@ public CodeIndexerWriterTests() Name = "string", }, SerializationName = "id", + Documentation = new() + { + Description = "some description" + } } }; parentClass.AddIndexer(indexer); @@ -75,6 +79,7 @@ public void WritesIndexer() Assert.Contains("RequestAdapter", result); Assert.Contains("PathParameters", result); Assert.Contains("id\", position", result); + Assert.Contains("some description", result); Assert.Contains("public SomeRequestBuilder this[string position]", result); AssertExtensions.CurlyBracesAreClosed(result); } From 3796408c905ad432a0fde01e74b14a79c4b10c19 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 8 Aug 2023 08:37:04 -0400 Subject: [PATCH 3/3] Update src/Kiota.Builder/CodeDOM/CodeIndexer.cs Co-authored-by: Eastman --- src/Kiota.Builder/CodeDOM/CodeIndexer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/CodeDOM/CodeIndexer.cs b/src/Kiota.Builder/CodeDOM/CodeIndexer.cs index 6ad3d6e0c2..d9c801406b 100644 --- a/src/Kiota.Builder/CodeDOM/CodeIndexer.cs +++ b/src/Kiota.Builder/CodeDOM/CodeIndexer.cs @@ -21,7 +21,7 @@ public required CodeTypeBase ReturnType /// /// The parameter to use for the indexer. /// - public CodeParameter IndexParameter + public required CodeParameter IndexParameter { get => indexParameter; set {