From 678ba2bb964bbf81b8116543a958e0ebd9c2a8df Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 26 Nov 2024 14:23:47 -0500 Subject: [PATCH] chore: adds unit test to prevent regression on discriminator infinite loop --- .../OpenApiSchemaExtensionsTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiSchemaExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiSchemaExtensionsTests.cs index d0c7a81f9f..620d11d79f 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiSchemaExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiSchemaExtensionsTests.cs @@ -847,4 +847,59 @@ public void IsOdataPrimitiveBackwardCompatible() }; Assert.True(schema.IsODataPrimitiveType()); } + [Fact] + public void ReturnsEmptyPropertyNameOnCircularReferences() + { + var entitySchema = new OpenApiSchema + { + Reference = new OpenApiReference + { + Id = "microsoft.graph.entity" + }, + Properties = new Dictionary + { + ["id"] = new OpenApiSchema + { + Reference = new OpenApiReference + { + Id = "microsoft.graph.entity" + } + } + } + }; + var userSchema = new OpenApiSchema + { + Reference = new OpenApiReference + { + Id = "microsoft.graph.user" + }, + OneOf = + [ + entitySchema, + new OpenApiSchema { + Type = "object", + Properties = new Dictionary { + ["firstName"] = new OpenApiSchema { + Reference = new OpenApiReference { + Id = "microsoft.graph.entity" + } + } + } + } + ], + Discriminator = new OpenApiDiscriminator + { + Mapping = new Dictionary + { + ["microsoft.graph.entity"] = "entity", + ["microsoft.graph.user"] = "user" + } + } + }; + entitySchema.AllOf = + [ + userSchema + ]; + Assert.Empty(userSchema.GetDiscriminatorPropertyName()); + } }