-
Notifications
You must be signed in to change notification settings - Fork 354
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
Custom error message inside JSON Schema. #444
Comments
v6.0.0 has already overhauled the error structure in a way that allows you to fully customise the error messages. This work was done several months ago by @shmax. There isn't an official 6.0.0 release yet, but for most purposes it works fairly well, so you're welcome to use the 6.0.0-dev branch for now until we get the release out. |
Note that if you are wanting to embed error messages inside the actual schema document, it can't do that. I'm not sure if that's what you're asking for though. |
That said, it does give you an error path, so it would be fairly straightforward to map embedded messages with a simple post-processor. |
Thanks for your answer. It's helped me a lot. |
Most welcome :-) |
Can you please give some example or something for adding custom error in the schema. |
@ravipxm. I can. Could you please clarify what you are trying to do and where you are stuck? That way I can provide an example that is as relevant as possible. |
@erayd Thanks for your reply. |
@ravipxm That is what the Each error has a unique name - these are defined in $customError = getCustomErrorFor($error['constraint']['name']);
$errorParams = $error['constraint']['params'];
$error['message'] = sprintf($customError, ...$errorParams); Note that you may also wish to consider the param types - they are provided to the user as-is, and some of them will not be scalar (the internal error messages handle this within the library, but the params presented to the user are not modified). |
@erayd is there any prediction for 6.0.0 release? |
@lfdubiela "at some point" is the best I can give you unfortunately. No ETA. This project has almost no manpower to get things done; it's mostly just me and @shmax, and we've both been rather busy with other things. If you have the time and skills to contribute, that would be greatly appreciated, and would help get the next release out the door sooner. |
@erayd do you think that this plan for 6.0.0 is current? I would like to get the project up to date to show the current status: https://github.com/justinrainbow/json-schema/projects/2 I think it will be easier for everyone to know the status and where they may help. As always, thank you for everything. |
@bighappyface Yes, I believe that is still current. Do you reckon it might be worth rolling a v6 dev release now, just to simplify things for composer users who want to use it now, even though it's not finished? We'd need to be really clear that breaking changes are still allowed though, because some stuff off the todo list is breaking. |
Btw, I'm available for some light chores. Let me know if you want me to follow up on any of those issues clogging up the queue, or anything. |
@shmax Honestly, anything you pick up is useful. I'm quite happy to code review, I just can't sink bulk hours into implementing stuff right now. |
Righto, then. I'll just take the one at the top of the list: #525 |
@ViktorKudlai time has passed a lot. Since all of the above comments we have released a V6.0.0. |
The problem is that it gives generic error messages that are not relevant to me. I want to send custom message to user.
Do we have any option like this:
Thanks.
The text was updated successfully, but these errors were encountered: