Skip to content

Commit

Permalink
Add testcases for allOf cases
Browse files Browse the repository at this point in the history
  • Loading branch information
papegaaij authored and baywet committed Sep 27, 2023
1 parent 8e8ceae commit 88a6306
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6849,4 +6849,116 @@ public async Task SupportsMultiPartFormAsRequestBody()
var addressClass = codeModel.FindChildByName<CodeClass>("Address");
Assert.NotNull(addressClass);
}
[Fact]
public async Task InheritanceWithAllOfInBaseType()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStream(@"openapi: 3.0.1
info:
title: OData Service for namespace microsoft.graph
description: This OData service is located at https://graph.microsoft.com/v1.0
version: 1.0.1
servers:
- url: https://graph.microsoft.com/v1.0
paths:
/directoryObject:
get:
responses:
'200':
description: Example response
content:
application/json:
schema:
$ref: '#/components/schemas/microsoft.graph.directoryObject'
components:
schemas:
microsoft.graph.directoryObject:
allOf:
- title: 'directoryObject'
required: ['@odata.type']
type: 'object'
properties:
'@odata.type':
type: 'string'
default: '#microsoft.graph.directoryObject'
discriminator:
propertyName: '@odata.type'
mapping:
'#microsoft.graph.user': '#/components/schemas/microsoft.graph.user'
'#microsoft.graph.group': '#/components/schemas/microsoft.graph.group'
microsoft.graph.group:
allOf:
- '$ref': '#/components/schemas/microsoft.graph.directoryObject'
- title: 'group'
type: 'object'
properties:
groupprop:
type: 'string'");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
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<CodeClass>("Group"));
}
[Fact]
public async Task InheritanceWithAllOfWith3Parts()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStream(@"openapi: 3.0.1
info:
title: OData Service for namespace microsoft.graph
description: This OData service is located at https://graph.microsoft.com/v1.0
version: 1.0.1
servers:
- url: https://graph.microsoft.com/v1.0
paths:
/directoryObject:
get:
responses:
'200':
description: Example response
content:
application/json:
schema:
$ref: '#/components/schemas/microsoft.graph.directoryObject'
components:
schemas:
microsoft.graph.directoryObject:
title: 'directoryObject'
required: ['@odata.type']
type: 'object'
properties:
'@odata.type':
type: 'string'
default: '#microsoft.graph.directoryObject'
discriminator:
propertyName: '@odata.type'
mapping:
'#microsoft.graph.user': '#/components/schemas/microsoft.graph.user'
'#microsoft.graph.group': '#/components/schemas/microsoft.graph.group'
microsoft.graph.group:
allOf:
- '$ref': '#/components/schemas/microsoft.graph.directoryObject'
- title: 'group part 1'
type: 'object'
properties:
groupprop1:
type: 'string'
- title: 'group part 2'
type: 'object'
properties:
groupprop2:
type: 'string'");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
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);
var resultClass = codeModel.FindChildByName<CodeClass>("Group");
Assert.NotNull(resultClass);
Assert.Equal(2, resultClass.Properties.Count());
Assert.Single(resultClass.Properties.Where(x => x.Name.Equals("groupprop1", StringComparison.OrdinalIgnoreCase)));
Assert.Single(resultClass.Properties.Where(x => x.Name.Equals("groupprop2", StringComparison.OrdinalIgnoreCase)));
}
}

0 comments on commit 88a6306

Please sign in to comment.