【问题标题】:Show descriptions for model properties which are custom types using Swashbuckle使用 Swashbuckle 显示自定义类型的模型属性的描述
【发布时间】:2021-07-12 12:25:16
【问题描述】:

我有这个模型:

public class Order {

  /// <summary>
  /// The customer.
  /// </summary>
  public Customer Customer { get; set; }

}

public class Customer {

  /// <summary>
  /// This is not shown.                 <---
  /// </summary>
  public int Id { get; set; }

  /// <summary>
  /// This is not shown.                 <---
  /// </summary>
  public string Name { get; set; }

}

Customer 类在单独的程序集中定义。

swagger ui 不显示 Customer 模型的 IdName 属性的描述。

我试过theseoptions,但没有帮助:

options.UseAllOfToExtendReferenceSchemas();
options.UseAllOfForInheritance();

我该如何解决这个问题?

【问题讨论】:

标签: c# asp.net-core swagger swagger-ui swashbuckle


【解决方案1】:

必须包含所有 XML 文件,而不仅仅是条目程序集的那个。

var dir = AppContext.BaseDirectory;
var paths = Directory.GetFiles(dir, "*.xml", SearchOption.TopDirectoryOnly);
foreach (var path in paths) o.IncludeXmlComments(path);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多