I have defined a model where starttime and endtime are timespan fields. In swagger, by default it takes input in ticks as you see in below code but i want data to be taken in "hh:mm:ss" format.
{
"availableToCallExternalId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"startTime": {
"ticks": 0
},
"endTime": {
"ticks": 0
},
"availableDays": "string"
}
How can we fix this issue?
Solution is we need to tell swagger that for timespan datatype we need "hh:mm:ss" format data and we can provide sample data
public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.AddControllers() .AddFluentValidation(mvcConfig => mvcConfig.RegisterValidatorsFromAssemblyContaining<Startup>()) .AddNewtonsoftJson(options => { options.SerializerSettings.Converters.Add(new StringEnumConverter()); }); services.AddSwaggerGen(c => { c.SwaggerDoc(SwaggerConstants.Version, new OpenApiInfo { Title = SwaggerConstants.Title, Version = SwaggerConstants.Version, }); c.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.Http, Scheme = "bearer", BearerFormat = "JWT", In = ParameterLocation.Header, Description = "JWT Authorization header using the Bearer scheme.", }); c.MapType<TimeSpan>(() => new OpenApiSchema { Type = "string", Example = new OpenApiString("00:00:00"), });
No comments:
Post a Comment