Skip to content

Commit 093fb69

Browse files
Merge pull request #61 from IgniteUI/validations-new
Validations new
2 parents 9c9550b + f0856c5 commit 093fb69

24 files changed

+165
-62
lines changed

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -50,8 +51,8 @@ public ActionResult<CategoryDto[]> GetAll()
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5152
[HttpGet("GetCategoriesWithSkip")]
5253
public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithSkip(
53-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
54+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5556
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5657
{
5758
try

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -50,8 +51,8 @@ public ActionResult<CustomerDto[]> GetAll()
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5152
[HttpGet("GetCustomersWithSkip")]
5253
public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithSkip(
53-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
54+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5556
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5657
{
5758
try

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -68,8 +69,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
6869
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
6970
[HttpGet("GetEmployeesWithSkip")]
7071
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployees(
71-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
72-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
72+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
73+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
7374
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
7475
{
7576
try

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -56,8 +57,8 @@ public ActionResult<OrderDto[]> GetAll()
5657
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5758
[HttpGet("GetPagedOrders")]
5859
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(
59-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
60-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
60+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
61+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
6162
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
6263
{
6364
try

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -70,8 +71,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
7071
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
7172
[HttpGet("GetPagedProducts")]
7273
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(
73-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
74-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
74+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
75+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
7576
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
7677
{
7778
try

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -50,8 +51,8 @@ public ActionResult<RegionDto[]> GetAll()
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5152
[HttpGet("GetPagedRegions")]
5253
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(
53-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
54+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5556
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5657
{
5758
try

NorthwindCRUD/Controllers/ShippersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -50,8 +51,8 @@ public ActionResult<ShipperDto[]> GetAll()
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5152
[HttpGet("GetPagedShippersWithSkip")]
5253
public ActionResult<PagedResultDto<ShipperDto>> GetPagedShippersWithSkip(
53-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
54+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5556
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5657
{
5758
try

NorthwindCRUD/Controllers/SuppliersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -50,8 +51,8 @@ public ActionResult<SupplierDto[]> GetAll()
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5152
[HttpGet("GetPagedSuppliers")]
5253
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(
53-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
54+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5556
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5657
{
5758
try

NorthwindCRUD/Controllers/TerritoriesController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.ComponentModel.DataAnnotations;
34
using AutoMapper;
45
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Mvc;
@@ -52,8 +53,8 @@ public ActionResult<TerritoryDto[]> GetAll()
5253
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5354
[HttpGet("GetPagedTerritories")]
5455
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(
55-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
56-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
56+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
57+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
5758
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5859
{
5960
try
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
using Microsoft.OpenApi.Any;
2-
using Microsoft.OpenApi.Models;
3-
using Swashbuckle.AspNetCore.SwaggerGen;
1+
using Microsoft.OpenApi.Any;
2+
using Microsoft.OpenApi.Models;
3+
using Swashbuckle.AspNetCore.SwaggerGen;
44

5-
namespace NorthwindCRUD.Filters
5+
namespace NorthwindCRUD.Filters
66
{
77
public class EnumSchemaFilter : ISchemaFilter
88
{
99
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
1010
{
1111
if (context.Type.IsEnum)
1212
{
13-
schema.Type = "string";
14-
schema.Enum = context.Type
15-
.GetEnumNames()
16-
.Select(name => new OpenApiString(name))
13+
var enumValues = Enum.GetValues(context.Type)
14+
.Cast<object>()
15+
.Select(e => new OpenApiString(e.ToString()))
1716
.ToList<IOpenApiAny>();
17+
18+
schema.Enum = enumValues;
1819
}
1920
}
2021
}
21-
}
22+
}

0 commit comments

Comments
 (0)