大摇大摆不显示 HttpGet 查询参数

swagger not showing HttpGet query parameters

我正在大摇大摆地开发 asp.net 核心 webapi(6.0)。当我 运行 应用程序 HttpGet 方法 Parameters 摘要在 swagger 中不可见。诸如 Id、StoreId、DateFrom、DateTo 摘要不会在 swagger 中显示。请指教

 /// <summary>
    /// Get product details.
    /// </summary>
    /// <remarks>Fetches product.</remarks>
    /// <param name="parameters"></param>
    /// <returns></returns>
    /// <response code="200">Successful Response</response>
    /// <response code="400">Bad Request</response>
    /// <response code="401">Unauthorized</response>
    /// <response code="424">Failed Dependency</response>
    /// <response code="500">Internal Server Error</response>
    public async Task<IActionResult> GetProduct([FromQuery] Parameter parameters)
        {
            var repo = await Repository.GetAllAsync(parameters);
            return Ok()
        }



public class Parameter
{
    /// <summary>
    /// Product Id
    /// </summary>
    public string? Id { get; set; }
    /// <summary>
    /// Optional Parameter. If supplied, result set will be restricted to the products from the supplied store alone
    /// </summary>
    public int? StoreId { get; set; }
    /// <summary>
    /// Optional Parameter.
    /// </summary>
    public DateTime? DateFrom { get; set; }
    /// <summary>
    /// Optional Parameter.
    /// </summary>
public DateTime? DateTo { get; set; }
}

请像下面这样修改您的 .csproj 文件。

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>

</Project>

请评论 builder.Services.AddSwaggerGen();,并 =使用下面的代码。

//builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(options =>
{
    // using System.Reflection;
    var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});

对我有用,请检查结果。