Code Monkey home page Code Monkey logo

Comments (5)

paw3lx avatar paw3lx commented on July 25, 2024

Yes, that kind of middleware would be great! I will be happy to help.

from valit.

GooRiOn avatar GooRiOn commented on July 25, 2024

@paw3lx great! We'll need to find out how to implement that :D

from valit.

GooRiOn avatar GooRiOn commented on July 25, 2024

As far as I understand we need to create our custom ModelValidatorProvider which can be later added using:

services.AddMvc(options => options.ModelValidatorProviders.Add(...));

I found internal implementation for the data annotations on GitHub:

https://github.com/aspnet/Mvc/blob/64ffcfaa89177683a1fd08d5407a09f897bf97e0/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsModelValidatorProvider.cs

This won't be a simple task, but we should nailed this anyway :D

from valit.

GooRiOn avatar GooRiOn commented on July 25, 2024

All right, after short break I finally got back to the project and I started doing this task localy. Surprisingly, I got first, working prototype done fairly quickly (about 30 minutes), so it's not that hard as I thought. However there are two issues that we need to overcome somehow:

  1. As far as I see #113 issue is required for this task since the whole validation is based on error messages. The rule is simple: any string message == model invalid. If there's no message returned then the model is valid. I checked that with Data Annotation and it uses default messages if it's not passed to the attribute. This basically means that we simply need default messages in Valit as well.

  2. One of the field returned in the validation result provided by ASP.NET Core is memberName which is then put into ModelState so the user knows which property is invalid. Currently we don't have this kind of the information in the IValitResult. This could be only guessed by messages but it's very unreliable solution since user could override it with the message not containing the name of the field. We need to come up with something more clever and ideally avoid another breaking change. But I'm afraid that it won't be that simple.

from valit.

GooRiOn avatar GooRiOn commented on July 25, 2024

Since the Valit.Examples repo was empty I put there my prototype with example integration. Of course it works just for specific type but at least we'll know the direction of this integration :D

from valit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.