Add FluentValidation for Question model validation

- Updated `AskEndpoints.cs` to include `MinimalHelpers.FluentValidation` and standardize endpoint descriptions.
- Integrated FluentValidation in `Program.cs` and registered validators.
- Modified `SqlDatabaseVectorSearch.csproj` to add necessary package references for FluentValidation.
- Created `QuestionValidator` class to enforce validation rules on the `Question` model.
This commit is contained in:
Marco Minerva
2025-05-05 15:06:22 +02:00
parent a2ae9c05af
commit 32fce98b63
4 changed files with 23 additions and 3 deletions
@@ -1,5 +1,5 @@
using System.ComponentModel;
using System.ComponentModel;
using MinimalHelpers.FluentValidation;
using SqlDatabaseVectorSearch.Models;
using SqlDatabaseVectorSearch.Services;
@@ -10,11 +10,12 @@ public class AskEndpoints : IEndpointRouteHandlerBuilder
public static void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapPost("/api/ask", async (Question question, VectorSearchService vectorSearchService, CancellationToken cancellationToken,
[Description("If true, the question will be reformulated taking into account the context of the chat identified by the given ConversationId.")] bool reformulate = true) =>
[Description("If true, the question will be reformulated taking into account the context of the chat identified by the given ConversationId.")] bool reformulate = true) =>
{
var response = await vectorSearchService.AskQuestionAsync(question, reformulate, cancellationToken);
return TypedResults.Ok(response);
})
.WithValidation<Question>()
.WithSummary("Asks a question")
.WithDescription("The question will be reformulated taking into account the context of the chat identified by the given ConversationId.")
.WithTags("Ask");
@@ -35,6 +36,7 @@ public class AskEndpoints : IEndpointRouteHandlerBuilder
return Stream();
})
.WithValidation<Question>()
.WithSummary("Asks a question and gets the response as streaming")
.WithDescription("The question will be reformulated taking into account the context of the chat identified by the given ConversationId.")
.WithTags("Ask");