Code Monkey home page Code Monkey logo

Comments (13)

pleerock avatar pleerock commented on May 18, 2024

wouldn't @NotEmpty decorator work?

from class-validator.

DominicBoettger avatar DominicBoettger commented on May 18, 2024

I am using skipmissingproperties and want to ensure that if a attribute is set, but not required will be validated and some attributes should be required and for example type of string.
I realized that if skipmissingproperties is set the validators are not executed at all. So also a NotEmpty will not work.... Do you have a solution for this kind of issue?

I need this to ensure that only validated data is saved in my database.

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

I realized that if skipmissingproperties is set the validators are not executed at all.

if skipmissingproperties is set then validation are not being executed only on missing properties

So, you want to use skipmissingproperties, but at same time if some property is missing, but its totally required, you want skipmissingproperties to be ignore that that property. Do I get you right?

from class-validator.

DominicBoettger avatar DominicBoettger commented on May 18, 2024

@pleerock Exactly. I know which fields have which type and i know which fields are required. Some fields i know the datatype are not required but i need to ensure their data type if they have data.

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

okay, got you. I'll think how do add option to decorators, so it will possible and let you know

from class-validator.

DominicBoettger avatar DominicBoettger commented on May 18, 2024

Okay, thank you very much. That sounds great!

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

I think I can do NotEmpty decorator the only decorator that will ignore skipmissingproperties option. I don't see any benefit of doing it for any other decorator, and I don't see any benifit of ignoring NotEmpty in the cases when skipmissingproperties is set to true

from class-validator.

DominicBoettger avatar DominicBoettger commented on May 18, 2024

That would be great!

I am implementing a ODM layer and i have fields which are required and some (most) fields are not required.

A typical constellation will for example be @isnotempty @ISINT.

To ensure that its not empty and if filled it should be a integer.

I am pretty sure it only makes sense for IsNotEmpty.

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

I changed my mind and decided to introduce a new decorator, as you originally suggested, but I named it @IsDefined(). This will be available in upcoming release soon d25ce59

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

added it in new version, you can try it by npm i class-validator@beta

from class-validator.

DominicBoettger avatar DominicBoettger commented on May 18, 2024

Wow. Thanks for this great new feature. Class-validator will be a huge part of my upcoming mongodb elasticsearch ORM - layer.

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

thats great!

from class-validator.

pleerock avatar pleerock commented on May 18, 2024

fixed in 0.4.0

from class-validator.

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.