From bc7650d4a81d19dadef657f1fb4c1d0af1135c79 Mon Sep 17 00:00:00 2001 From: Emond Papegaaij Date: Mon, 19 Jun 2023 09:39:39 +0200 Subject: [PATCH] Add testcase demonstrating broken inhertance chain This is described in #2781 --- .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 457127d7ac..bee5a4f265 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -6849,4 +6849,107 @@ public async Task SupportsMultiPartFormAsRequestBody() var addressClass = codeModel.FindChildByName("Address"); Assert.NotNull(addressClass); } + [Fact] + public async Task ComplexInheritanceStructures() + { + var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); + await using var fs = await GetDocumentStream(@"openapi: 3.0.1 +info: + title: Broken inheritance + version: '1' +servers: +- url: http://localhost +paths: + '/groupclassification': + get: + summary: Example + description: Example + responses: + '200': + description: default response + content: + application/vnd.topicus.keyhub+json;version=latest: + schema: + '$ref': '#/components/schemas/group.GroupClassification' +components: + schemas: + Linkable: + required: + - '$type' + type: object + properties: + '$type': + type: string + discriminator: + propertyName: '$type' + mapping: + group.GroupPrimer: '#/components/schemas/group.GroupPrimer' + group.GroupClassificationPrimer: '#/components/schemas/group.GroupClassificationPrimer' + group.GroupClassification: '#/components/schemas/group.GroupClassification' + group.GroupPrimer: + allOf: + - '$ref': '#/components/schemas/Linkable' + - type: object + properties: + markers: + '$ref': '#/components/schemas/mark.ItemMarkers' + NonLinkable: + required: + - '$type' + type: object + properties: + '$type': + type: string + discriminator: + propertyName: '$type' + mapping: + mark.ItemMarkers: '#/components/schemas/mark.ItemMarkers' + group.GroupsAuditStats: '#/components/schemas/group.GroupsAuditStats' + mark.ItemMarkers: + allOf: + - '$ref': '#/components/schemas/NonLinkable' + - type: object + group.GroupClassificationPrimer: + allOf: + - '$ref': '#/components/schemas/Linkable' + - required: + - '$type' + - name + type: object + properties: + '$type': + type: string + name: + type: string + discriminator: + propertyName: '$type' + mapping: + group.GroupClassification: '#/components/schemas/group.GroupClassification' + group.GroupClassification: + allOf: + - '$ref': '#/components/schemas/group.GroupClassificationPrimer' + - type: object + properties: + description: + type: string + group.GroupsAuditStats: + allOf: + - '$ref': '#/components/schemas/NonLinkable' + - type: object + properties: + classification: + '$ref': '#/components/schemas/group.GroupClassification'"); + var mockLogger = new Mock>(); + var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath }, _httpClient); + var document = await builder.CreateOpenApiDocumentAsync(fs); + var node = builder.CreateUriSpace(document); + var codeModel = builder.CreateSourceModel(node); + Assert.NotNull(codeModel.FindChildByName("Linkable")); + var classificationClass = codeModel.FindChildByName("GroupClassification"); + Assert.Single(classificationClass.Properties.Where(x => x.Name.Equals("description", StringComparison.OrdinalIgnoreCase))); + Assert.NotNull(classificationClass); + var classificationPrimerClass = codeModel.FindChildByName("GroupClassificationPrimer"); + Assert.NotNull(classificationPrimerClass); + Assert.Single(classificationPrimerClass.Properties.Where(x => x.Name.Equals("name", StringComparison.OrdinalIgnoreCase))); + } }