Skip to content

OpenAPI operations include parameters disallowed by OpenAPI 3.0 specification #57305

@martincostello

Description

@martincostello

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

According to OpenAPI Guide: Describing Parameters, certain HTTP headers are disallowed from being documented as parameters of operations:

Note: Header parameters named Accept, Content-Type and Authorization are not allowed.

Instead, they should be documented elsewhere (responses.<code>.content.<media-type>, requestBody.content.<media-type>/responses.<code>.content.<media-type> and securitySchemes/ security respectively).

Endpoints using [FromHeader(Name = "{name}")] to bind any parameters have these parameters included in the endpoint documentation, violating this requirement.

Expected Behavior

Header parameters for Accept, Content-Type and Authorization are not included in operations' parameters.

Steps To Reproduce

Define an HTTP endpoint similar to the following:

app.MapGet((
    [FromHeader(Name = "Accept")] string accept,
    [FromHeader(Name = "Authorization")] string authorization,
    [FromHeader(Name = "Content-Type")] string contentType) =>
{
    // ...
});

Exceptions (if any)

No response

.NET Version

9.0.100-rc.1.24413.1

Anything else?

Spotted after looking into domaindrivendev/Swashbuckle.AspNetCore#3024 (comment), which then reminded me that in an application of my own the Authorization parameter had re-appeared after migrating to OpenAPI from Swashbuckle.AspNetCore (OpenAPI document diff Swashbuckle.AspNetCore 6.7.0 to M.A.OpenApi 9.0-preview.7).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions