Closed codeandcats closed 4 years ago
If/once we're happy for this to go in I'll follow it up with a new release.
:fire::fire::fire: Thank you @codeandcats
Just wondering, does it make sense for validation to pass when validating against a class that has no validation schema/metadata? To me, this suggests a bug, like someone forgot to define the validation schema.
That's a fair question @laurence-myers.
I think I prefer the idea of it passing validation as then it doesn't require the consumer to have an extra step to check if it has a schema or not.
But I don't have a strong opinion on it and happy to change it. So would you say you are leaning towards it throwing an error (like "No schema found for class" or something)?
I would rather get joiful's error and resolve it in the development process but getJoiSchema function is needed
@stepanzabelin Okay that makes sense. 👍
@laurence-myers if you’re happy I’ll make the necessary changes tomorrow night (bedtime now) and follow up with a publish.
Okay, I've changed the default behaviour of the validator functions (validate
, validateAsClass
, validateArrayAsClass
) so that they will error (with NoValidationSchemaForClassError
) when trying to validate against a class that has no schema associated with it. This will be a breaking change and will trigger a major version bump when releasing.
I've also added a new convenience function hasSchema(Class): boolean
CC: @stepanzabelin.
Can you please re-review @laurence-myers?
Hi there. I am looking forward to a new release 🔥
@stepanzabelin Sorry for the hold up. I've just merged and published version 2.0.0
. 😄
@codeandcats many thanks I've installed and tested. Everything is fine!
Summary
Added
getSchema
toJoiful
class and exported it from the default instance inindex.ts
getSchema
simply calls existing internalgetJoiSchema
functionChanged the default behaviour of
getJoiSchema
to returnundefined
rather than an empty object schema if there is no working schema for the given class or it's ancestors.Added
hasSchema
toJoiful
class and exported it from the default instance inindex.ts
Changed the default behaviour of the validator functions (
validate
,validateAsClass
,validateArrayAsClass
) so that they will error (withNoValidationSchemaForClassError
) when trying to validate against a class that has no schema associated with it. This will be a breaking change and will trigger a major version bump when releasing.Motivation
@stepanzabelin wanted a way to tell if a class has a schema associated with it (see #105). This PR addresses this issue by exporting a
hasSchema
function that returns whether a class has a schema or not.Ticket
Closes #105.