diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 9c64aa8cb9..9c51522222 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -1264,11 +1264,11 @@ codeType.TypeDefinition is CodeClass codeClass && executorMethod.AddErrorMapping(errorCode, errorType); } } - private CodeTypeBase? GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass) + private CodeTypeBase? GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass, OperationType operationType) { if (schema != null) { - return CreateModelDeclarations(currentNode, schema, operation, parentClass, "Response"); + return CreateModelDeclarations(currentNode, schema, operation, parentClass, $"{operationType}Response"); } else { @@ -1315,7 +1315,7 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, OperationTyp operation.Summary) .CleanupDescription(), }, - ReturnType = GetExecutorMethodReturnType(currentNode, schema, operation, parentClass) ?? throw new InvalidSchemaException(), + ReturnType = GetExecutorMethodReturnType(currentNode, schema, operation, parentClass, operationType) ?? throw new InvalidSchemaException(), Deprecation = deprecationInformation, }; diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 08857a7638..33d825bb5b 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -1047,7 +1047,7 @@ public void Object_Arrays_are_supported() var codeModel = builder.CreateSourceModel(node); var userClass = codeModel.FindNamespaceByName("ApiSdk.models").FindChildByName("user"); Assert.NotNull(userClass); - var userResponseClass = codeModel.FindNamespaceByName("ApiSdk.users.item").FindChildByName("UsersResponse", false); + var userResponseClass = codeModel.FindNamespaceByName("ApiSdk.users.item").FindChildByName("UsersGetResponse", false); Assert.NotNull(userResponseClass); var valueProp = userResponseClass.FindChildByName("value", false); Assert.NotNull(valueProp); @@ -1548,9 +1548,9 @@ public void Inline_Property_Inheritance_Is_Supported() var codeModel = builder.CreateSourceModel(node); var resourceClass = codeModel.FindNamespaceByName("ApiSdk.models").FindChildByName("resource"); var itemsNS = codeModel.FindNamespaceByName("ApiSdk.resource.item"); - var responseClass = itemsNS.FindChildByName("ResourceResponse"); - var derivedResourceClass = itemsNS.FindChildByName("ResourceResponse_derivedResource"); - var derivedResourceInfoClass = itemsNS.FindChildByName("ResourceResponse_derivedResource_info"); + var responseClass = itemsNS.FindChildByName("ResourceGetResponse"); + var derivedResourceClass = itemsNS.FindChildByName("ResourceGetResponse_derivedResource"); + var derivedResourceInfoClass = itemsNS.FindChildByName("ResourceGetResponse_derivedResource_info"); Assert.NotNull(resourceClass); @@ -3390,7 +3390,7 @@ public void UnionOfInlineSchemasWorks() Assert.Equal(2, executorReturnType.Types.Count()); var typeNames = executorReturnType.Types.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase); Assert.Contains("simpleObject", typeNames); - Assert.Contains("unionTypeResponseMember1", typeNames); + Assert.Contains("unionTypeGetResponseMember1", typeNames); } [Fact] public void IntersectionOfPrimitiveTypesWorks() @@ -3549,7 +3549,7 @@ public void IntersectionOfInlineSchemasWorks() Assert.Equal(2, executorReturnType.Types.Count()); var typeNames = executorReturnType.Types.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase); Assert.Contains("simpleObject", typeNames); - Assert.Contains("unionTypeResponseMember1", typeNames); + Assert.Contains("unionTypeGetResponseMember1", typeNames); } [Fact] public void InheritedTypeWithInlineSchemaWorks() @@ -6148,7 +6148,7 @@ await File.WriteAllTextAsync(tempFilePath, @$"openapi: 3.0.1 var codeModel = builder.CreateSourceModel(node); var rootNS = codeModel.FindNamespaceByName("ApiSdk"); Assert.NotNull(rootNS); - var inlineType = rootNS.FindChildByName($"enumerationResponse_{expected}", true); + var inlineType = rootNS.FindChildByName($"enumerationGetResponse_{expected}", true); Assert.NotNull(inlineType); } [Fact] @@ -6460,7 +6460,7 @@ public async Task MergesIntersectionTypes() var document = await builder.CreateOpenApiDocumentAsync(fs); var node = builder.CreateUriSpace(document); var codeModel = builder.CreateSourceModel(node); - var resultClass = codeModel.FindChildByName("DirectoryObjectResponse"); + var resultClass = codeModel.FindChildByName("DirectoryObjectGetResponse"); Assert.NotNull(resultClass); Assert.Equal(4, resultClass.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom)).Count()); } @@ -6500,7 +6500,7 @@ public async Task SkipsInvalidItemsProperties() var document = await builder.CreateOpenApiDocumentAsync(fs); var node = builder.CreateUriSpace(document); var codeModel = builder.CreateSourceModel(node); - var resultClass = codeModel.FindChildByName("DirectoryObjectResponse"); + var resultClass = codeModel.FindChildByName("DirectoryObjectGetResponse"); Assert.NotNull(resultClass); var keysToCheck = new HashSet(StringComparer.OrdinalIgnoreCase) { "datasets", "datakeys", "datainfo" }; Assert.Empty(resultClass.Properties.Where(x => x.IsOfKind(CodePropertyKind.Custom) && keysToCheck.Contains(x.Name)));