Skip to content

Commit

Permalink
Add test to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Oct 24, 2023
1 parent d183ad5 commit 7629765
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Writers;
using VerifyXunit;
using Xunit;
Expand Down Expand Up @@ -506,5 +509,56 @@ public void CloningSchemaExtensionsWorks()
};
Assert.NotEqual(schema.Extensions, schemaCopy.Extensions);
}

[Fact]
public void OpenApiWalkerVisitsOpenApiSchemaNot()
{
var outerSchema = new OpenApiSchema()
{
Title = "Outer Schema",
Not = new OpenApiSchema()
{
Title = "Inner Schema",
Type = "string",
}
};

var document = new OpenApiDocument()
{
Paths = new OpenApiPaths()
{
["/foo"] = new OpenApiPathItem()
{
Parameters = new[]
{
new OpenApiParameter()
{
Name = "foo",
In = ParameterLocation.Query,
Schema = outerSchema,
}
}
}
}
};

// Act
var visitor = new SchemaVisitor();
var walker = new OpenApiWalker(visitor);
walker.Walk(document);

// Assert
visitor.Titles.Count.Should().Be(2);
}
}

internal class SchemaVisitor : OpenApiVisitorBase
{
public List<string> Titles = new();

public override void Visit(OpenApiSchema schema)
{
Titles.Add(schema.Title);
}
}
}

0 comments on commit 7629765

Please sign in to comment.