You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More than one validator was found for the request dto [Project.Request]. Specify the exact validator to register using the Validator() method in endpoint configuration.
#394
Closed
sandelirious7 opened this issue
Mar 1, 2023
· 1 comment
pls upgrade to 5.7.2.12-beta
and do validator inheritance like shown below:
publicclassUpdate:Endpoint<Request>{publicoverridevoidConfigure(){
Post("/streaming");
AllowAnonymous();
Description(x => x.ProducesProblemFE(400).ProducesProblemFE(404));Validator<UpdateRequestValidator>();}publicoverrideasync Task HandleAsync(Requestreq,CancellationTokenct){await SendAsync(req);}}publicclassCreateRequestValidator:Validator<Request>{publicCreateRequestValidator(){
RuleFor(req => req.Doc.Name).NotEmpty().WithMessage("Name is required");}}publicclassUpdateRequestValidator:Validator<Request>{publicUpdateRequestValidator(){
Include(new CreateRequestValidator());//this is how you inherit rules written in other validators
RuleFor(req => req.Doc.Uuid).NotEmpty().WithMessage("UUID is required");}}
Though I've explicitly mentioned the validator in my Endpoint, I still see this error in 5.7.0
CreateEndpoint.cs
public override void Configure() { Verbs(Http.POST); Routes("/streaming"); AllowAnonymous(); Description( req => req .Accepts<Request>("application/json") .Produces((int)HttpStatusCode.Accepted) .Produces<ErrorResponse>((int)HttpStatusCode.BadRequest, "application/json+problem") .Produces<ErrorResponse>((int)HttpStatusCode.NotFound, "application/json+problem"), clearDefaults: true ); Validator<CreateRequestValidator>(); }
UpdateEndpoint.cs
public override void Configure() { Verbs(Http.PATCH); Routes("/streaming"); AllowAnonymous(); Description( req => req .Accepts<Request>("application/json") .Produces((int)HttpStatusCode.Accepted) .Produces<ErrorResponse>((int)HttpStatusCode.BadRequest, "application/json+problem") .Produces<ErrorResponse>((int)HttpStatusCode.NotFound, "application/json+problem"), clearDefaults: true ); Validator<UpdateRequestValidator>(); }
`public class CreateStreamingDrupalAssetsRequestValidator : Validator
{
public CreateRequestValidator()
{
RuleFor(req => req.Doc.Name)
.NotNull()
.NotEmpty()
.WithMessage("Name is required");
}
}
public class UpdateRequestValidator : CreateRequestValidator
{
public UpdateStreamingDrupalAssetsRequestValidator() : base()
{
RuleFor(req => req.Doc.Uuid)
.NotNull()
.NotEmpty()
.WithMessage("UUID is required");
}
}`
The text was updated successfully, but these errors were encountered: