Skip to content

OpenApiFilterService.CreateFilteredDocument fails if the document is missing the "components" field #1732

Closed

Description

Describe the bug
Calling OpenApiFilterService.CreateFilteredDocument on a document that does not contain the optional field OpenApiDocument.Components produces a NullReferenceException.

OpenApi File To Reproduce
Not an OpenApi File, but the following is enough to trigger it.

var openApiDoc = new OpenApiDocument
{
    Info = new()
    {
        Title = "Test",
        Version = "1.0.0"
    },
    Paths = new()
    {
        ["/test"] = new OpenApiPathItem()
        {
            Operations = new Dictionary<OperationType, OpenApiOperation>
            {
                [OperationType.Get] = new OpenApiOperation()
            }
        }
    }
};

var requestUrls = new Dictionary<string, List<string>>()
{
    { "/test", ["GET"] }
};
var filterPredicate = OpenApiFilterService.CreatePredicate(null, null, requestUrls, openApiDoc);
var filteredDocument = OpenApiFilterService.CreateFilteredDocument(openApiDoc, filterPredicate); // Error!

Expected behavior
It should not fail, because the Components field is not mandatory. If it's necessary it should throw a more descriptive exception.

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions