Search code examples
c#asp.net-coreswaggerswagger-uiswashbuckle

Show descriptions for model properties which are custom types using Swashbuckle


I have this model:

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; }

}

The Customer class is defined in a separate assembly.

The swagger ui does not show descriptions for the Customer model's Id and Name properties.

I tried these options, which didn't help:

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

How can I fix this?


Solution

  • All XML files must be included, not just the one for the entry assembly.

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