| | | 1 | | using Microsoft.OpenApi.Any; |
| | | 2 | | using Microsoft.OpenApi.Models; |
| | | 3 | | using Swashbuckle.AspNetCore.SwaggerGen; |
| | | 4 | | |
| | | 5 | | namespace Syki.Back.Filters; |
| | | 6 | | |
| | | 7 | | public class IdParameterExamplesFilter : IOperationFilter |
| | | 8 | | { |
| | | 9 | | public void Apply(OpenApiOperation operation, OperationFilterContext context) |
| | | 10 | | { |
| | 0 | 11 | | var routeTemplate = context.ApiDescription.RelativePath?.ToLowerInvariant() ?? string.Empty; |
| | | 12 | | |
| | 0 | 13 | | foreach (var parameter in operation.Parameters) |
| | | 14 | | { |
| | 0 | 15 | | if (!parameter.In.IsIn(ParameterLocation.Path, ParameterLocation.Query)) |
| | | 16 | | continue; |
| | | 17 | | |
| | 0 | 18 | | if (parameter.Example != null) |
| | | 19 | | continue; |
| | | 20 | | |
| | 0 | 21 | | if (routeTemplate.Contains("academic/enrollment-periods") && parameter.Name.Equals("id", StringComparison.Or |
| | | 22 | | { |
| | 0 | 23 | | parameter.Example = new OpenApiString($"{DateTime.Now.Year}.1"); |
| | 0 | 24 | | continue; |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | if (parameter.Name.Contains("id", StringComparison.OrdinalIgnoreCase)) |
| | | 28 | | { |
| | 0 | 29 | | parameter.Example = new OpenApiString(Guid.CreateVersion7().ToString()); |
| | | 30 | | } |
| | | 31 | | } |
| | 0 | 32 | | } |
| | | 33 | | } |