Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2
Use FluentValidation instead ComponentModel in swagger for Asp.Net WebApi
License
micro-elements/MicroElements.Swashbuckle.FluentValidation.WebApi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Use FluentValidation rules instead ComponentModel attributes to define swagger schema.
Note: For AspNetCore see:https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation
- Swashbuckle
- FluentValidation
- FluentValidation.WebApi
- MicroElements.Swashbuckle.FluentValidation.WebApi
After you add Swashbuckle package you can find generated SwaggerConfig.cs
- Comment [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] (we need to register swagger after FluentValidation in WebApiConfig)
- Add registration c.AddFluentValidationRules();
// Commented because we need manual registration in right order//[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]publicclassSwaggerConfig{publicstaticvoidRegister(){varthisAssembly=typeof(SwaggerConfig).Assembly;GlobalConfiguration.Configuration.EnableSwagger(c=>{ ...// Adds FluentValidationRules to swaggerc.AddFluentValidationRules(); ...} ...
- Add
FluentValidationModelValidatorProvider.Configure(config);
- Add
SwaggerConfig.Register();
publicstaticclassWebApiConfig{publicstaticvoidRegister(HttpConfigurationconfig){// Web API configuration and services// Web API routesconfig.MapHttpAttributeRoutes();config.Routes.MapHttpRoute(name:"DefaultApi",routeTemplate:"api/{controller}/{id}",defaults:new{id=RouteParameter.Optional});// Adds Fluent validation to WebApiFluentValidationModelValidatorProvider.Configure(config);// Registers swagger for WebApiSwaggerConfig.Register();}}
See sample project:https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation.WebApi/tree/master/src/AspNetWebApiOld
Initial version of this project was based onMujahid Daud Khan answer on StackOwerflow:https://stackoverflow.com/questions/44638195/fluent-validation-with-swagger-in-asp-net-core/49477995#49477995
About
Use FluentValidation instead ComponentModel in swagger for Asp.Net WebApi
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.