Skip to content

No way to remove a top-level security declaration with an empty array on an operation #521

Closed
@jez9999

Description

@jez9999

In OpenApiOperation.cs, the documentation for Security states that "To remove a top-level security declaration, an empty array can be used.". Great - this is exactly what I want. To declare top-level security and then remove it for a few operations that allow anonymous access.

The problem is, I can't actually see any way to get OpenAPI.NET to write out an empty array. Both the SerializeAsV2 and SerializeAsV3 methods write out the security section using writer.WriteOptionalCollection(...), which only writes out if (elements != null && elements.Any()). That means that whether you set Security to null or an empty list, the security section will be skipped altogether instead of serialized to an empty JSON array.

I need to serialize it to an empty JSON array, so what should I do? Does there need to be an update to OpenAPI.NET to allow this? Seems to me that there does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions