Skip to content

Commit

Permalink
Add annotation validation
Browse files Browse the repository at this point in the history
  • Loading branch information
corentin703 committed Jun 3, 2023
1 parent ddba58d commit 9cee8e9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Infrastructure/Services/IntrospectionService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Text.RegularExpressions;
using System.Net;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Sqliste.Core.Contracts;
using Sqliste.Core.Contracts.Services;
using Sqliste.Core.Exceptions.Procedures;
using Sqliste.Core.Models.Http;
Expand Down Expand Up @@ -134,14 +136,33 @@ private async Task RunProcedureIntrospectionAsync(
CancellationToken cancellationToken = default
)
{
procedure.Annotations = SqlAnnotationParser.ParseSqlString(procedure.Content);
SetupAnnotations(procedure);
procedure.Arguments = await _databaseGateway.QueryProceduresParamsAsync(procedure.Name, cancellationToken);
SetupRoutePattern(procedure);
SetupQueryParams(procedure);
SetupHttpMethod(procedure);
SetupContentType(procedure);
}

private void SetupAnnotations(ProcedureModel procedure)
{
List<ISqlAnnotation> annotations = SqlAnnotationParser.ParseSqlString(procedure.Content);
List<ISqlAnnotation> validatedAnnotations = new();

annotations.ForEach(annotation =>
{
if (!annotation.IsValid())
{
_logger.LogWarning("Annotation {AnnotationType} isn't valid", annotation.GetType());
return;
}

validatedAnnotations.Add(annotation);
});

procedure.Annotations = validatedAnnotations;
}

private void SetupQueryParams(ProcedureModel procedure)
{
foreach (ProcedureArgumentModel argument in procedure.Arguments)
Expand Down

0 comments on commit 9cee8e9

Please sign in to comment.