awilinsk
awilinsk

Reputation: 2044

Web Api Swagger Parameter Example

Using ASP.NET 5 Web API with MVC Versioned API Explorer, is there a way to auto generate the example for a parameter like described in the Swagger docs: https://swagger.io/docs/specification/adding-examples/

I'm currently using XML Comments, but I don't see a way to provide the example for a parameter. The <remarks> XML Comment doesn't apply to parameters and only to the operation.

What I'd like to do is have the example auto-generated for the following model

public record GetSpecsCommand {
  /// <summary>filter results by already selected specs</summary>
  /// <remarks>
  ///     {
  ///       "selectedspecs.year": "2020"
  ///     }
  /// </remarks>
  public IDictionary<string, string> SelectedSpecs { get; set; }
}

Upvotes: 0

Views: 408

Answers (1)

awilinsk
awilinsk

Reputation: 2044

After I posted this, I searched through the github code and found that it supports the <example> XML comment. After changing <remarks> to <example> my example was magically added to the generated swagger doc.

Upvotes: 1

Related Questions