Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApiWalker doesn't visit OpenApiSchema.Not schema #1438

Closed
dotjpg3141 opened this issue Oct 23, 2023 · 0 comments · Fixed by #1440
Closed

OpenApiWalker doesn't visit OpenApiSchema.Not schema #1438

dotjpg3141 opened this issue Oct 23, 2023 · 0 comments · Fixed by #1440
Assignees
Labels
bug-fix-vNext Bug fixes need to be merged into both master and vNext. Use this tag for vNext bug fix PR.

Comments

@dotjpg3141
Copy link

Describe the bug
OpenApiWalker doesn't visit OpenApiSchema.Not schema.

To Reproduce

using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;

namespace ConsoleApp3
{
    internal class Program
    {
        static void Main( string[] args )
        {
            var innerSchema = new OpenApiSchema()
            {
                Title = "Inner Schema",
                Type = "string",
            };

            var outerSchema = new OpenApiSchema()
            {
                Title = "Outer Schema",
                Not = innerSchema
            };

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

            var walker = new OpenApiWalker( new MyVisitor() );
            walker.Walk( document );
        }

        class MyVisitor : OpenApiVisitorBase
        {
            public override void Visit( IOpenApiReferenceable referenceable )
            {
                Console.WriteLine( referenceable );
            }

            public override void Visit( OpenApiSchema schema )
            {
                Console.WriteLine( schema + " | " + schema.Title );
            }
        }
    }
}

Actual output:

Microsoft.OpenApi.Models.OpenApiSchema | Outer Schema

Expected behavior
Expected output:

Microsoft.OpenApi.Models.OpenApiSchema | Outer Schema
Microsoft.OpenApi.Models.OpenApiSchema | Inner Schema

Additional context
Nuget Package Microsoft.OpenApi in version 1.6.9

This is missing in the corresponding Walk method:

if (schema.Items != null)
{
Walk("items", () => Walk(schema.Items));
}
if (schema.AllOf != null)
{
Walk("allOf", () => Walk(schema.AllOf));
}
if (schema.AnyOf != null)
{
Walk("anyOf", () => Walk(schema.AnyOf));
}
if (schema.OneOf != null)
{
Walk("oneOf", () => Walk(schema.OneOf));
}
if (schema.Properties != null)
{
Walk("properties", () =>
{
foreach (var item in schema.Properties)
{
Walk(item.Key, () => Walk(item.Value));
}
});
}
if (schema.AdditionalProperties != null)
{
Walk("additionalProperties", () => Walk(schema.AdditionalProperties));
}
Walk(OpenApiConstants.ExternalDocs, () => Walk(schema.ExternalDocs));
Walk(schema as IOpenApiExtensible);

@MaggieKimani1 MaggieKimani1 self-assigned this Oct 24, 2023
@MaggieKimani1 MaggieKimani1 added the bug-fix-vNext Bug fixes need to be merged into both master and vNext. Use this tag for vNext bug fix PR. label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix-vNext Bug fixes need to be merged into both master and vNext. Use this tag for vNext bug fix PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants