Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a default message for schemas & rules #140

Open
aminnairi opened this issue Dec 13, 2023 · 0 comments
Open

Provide a default message for schemas & rules #140

aminnairi opened this issue Dec 13, 2023 · 0 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@aminnairi
Copy link
Owner

aminnairi commented Dec 13, 2023

Is your feature request related to a problem? Please describe.
It would be great to not have to write a message for each schema, especially when the error message is not used in the client side.

Describe the solution you'd like
Make every schema's message property optional, enabling the library to provide its own message (in english).

import * as Kryptonian from "kryptonian";

// This
Kryptonian.Kalel.string({
  rules: []
});

// Instead of this
Kryptonian.Kalel.string({
  message: "",
  rules: []
});
import * as Kryptonian from "kryptonian";

// This
Kryptonian.Kalel.string({
  rules: [
    Kryptonian.Kalel.String.email()
  ]
});

// Instead of this
Kryptonian.Kalel.string({
  rules: [
    Kryptonian.Kalel.String.email({
      message: "This should be a valid email"
    })
  ]
});

Describe alternatives you've considered
None.

Additional context
This does not prevent the library from being type safe! This only make the property optional, with a default message that can still be relevant for most purposes.

Also, the library will still check for the schema to be in accordance with the data, and if this is not the case, a BadRequestError will still be raised (and would still require to be accounted for).

@aminnairi aminnairi added the feature New feature or request label Dec 13, 2023
@aminnairi aminnairi added this to the 4.1.0 milestone Dec 13, 2023
@aminnairi aminnairi self-assigned this Dec 13, 2023
@aminnairi aminnairi changed the title Provide a default message for schemas Provide a default message for schemas & rules Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant