Reputation: 69
We specify an input property with an example value as such
/// <summary>
/// Start date in format YYYY-MM-DD
/// </summary>
/// <example>2020-05-31</example>
[DataType(DataType.Date)]
public DateTime? From { get; set; }
And produces the following json
{
"name": "from",
"in": "query",
"description": "Start date in format YYYY-MM-DD",
"schema": {
"type": "string",
"description": "Start date in format YYYY-MM-DD",
"format": "date",
"nullable": true,
"example": "31/05/2020 12:00:00 AM"
}
}
it looks like the example is not respecting the swagger date format which is: full-date of format YYYY-MM-DD
The setup code I used:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(swaggerGenOption =>
{
swaggerGenOption.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
swaggerGenOption.IncludeXmlComments(XmlDocPath<Startup>());
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseSwagger();
app.UseSwaggerUI(config =>
{
config.RoutePrefix = string.Empty
config.SwaggerEndpoint("./swagger/v1/swagger.json", "TST");
});
app.UseEndpoints(endpoints => endpoints.MapControllers());
}
Upvotes: 1
Views: 812