Skip to content

XML Doc comments on properties of an AsParameters class aren't included in the generated OpenAPI doc #61936

@mikekistler

Description

@mikekistler

I think there is a gap in how metadata for parameters defined in an AsParameters class is captured for OpenAPI document generation.

For example, the following code

app.MapGet("/bar", GetBar).WithName("GetBar");

partial class Program
{
    /// <summary>
    /// Get a bar
    /// </summary>
    /// <param name="barParams">Parameters for Bar</param>
    public static Ok<string> GetBar([AsParameters] BarBaz barParams)
    {
        return TypedResults.Ok(barParams.Bar);
    }
}

public class BarBaz
{
    /// <summary>This is a bar</summary>
    public string? Bar { get; set; }
    /// <summary>This is a baz</summary>
    public string? Baz { get; set; }
}

I would expect that the XML doc comments on Bar and Baz would be captured and would appear as the description for these parameters in the generated OpenAPI document. But this is not currently working.

  "summary": "Get a bar",
  "operationId": "GetBar",
  "parameters": [
    {
      "name": "Bar",
      "in": "query",
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "Baz",
      "in": "query",
      "schema": {
        "type": "string"
      }
    }
  ],

I looked into whether Swashbuckle handled this case in the way I expected, and discovered this issue, which references this PR in ASP.NET Core that purports to fix the problem for Swashbuckle.

I created a minimal repro for this in the xmldoc-for-asparameters directory of this repo:

https://github.com/mikekistler/dotnet10-issue-repros

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions