Skip to content

Commit cf87d3e

Browse files
OpenAPI schema validations
1 parent 9c9550b commit cf87d3e

23 files changed

+107
-24
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
7070
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
7171
[HttpGet("GetPagedProducts")]
7272
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(
73-
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
74-
[FromQuery][Attributes.SwaggerTopParameter] int? top,
73+
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
74+
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
7575
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
7676
{
7777
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

NorthwindCRUD/Helpers/Enums.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace NorthwindCRUD.Helpers
4+
{
5+
public class Enums
6+
{
7+
public enum Shipping
8+
{
9+
[EnumMember(Value = "SeaFreight")]
10+
SeaFreight,
11+
12+
[EnumMember(Value = "GroundTransport")]
13+
GroundTransport,
14+
15+
[EnumMember(Value = "AirCargo")]
16+
AirCargo,
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)