Jakeuj's Notes master Help

ABP.IO Swagger Default Value

筆記下 Swagger Input 提供 預設值 的方法

參照

Get started with Swashbuckle and ASP.NET Core | Microsoft Learn

產生 xml

YourProject.Application.Contracts.csproj

<PropertyGroup> <GenerateDocumentationFile>true</GenerateDocumentationFile> </PropertyGroup>

設定 Swagger

YourProject.HttpApi.Host/YourProjectHttpApiHostModule.cs => ConfigureServices => ConfigureSwaggerServices

options => { // using System.Reflection; var xmlFilename = "YourProject.Application.Contracts.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); });

加上預設值

YourProject.Application.Contracts/YourDto.cs

[DefaultValue("HelloWorld")] public string Message { get; set; } [DefaultValue(new string[] { "a", "b" })] public List<string> Users { get; set; }

1669104103 png Jakeuj

PS5

  • Swagger

  • 回首頁

本文章從點部落遷移至 Writerside

14 October 2025