Introduction
API introduction
- How do I install this library?
- How do I validate my data?
- How to load json schema documents?
- How can I add custom filters ($filters keyword)?
- How can I add custom formats (format keyword)?
- How can I add custom media types (contentMediaType keyword)?
- How can I extend the schema to add my own keywords?
- I cannot find the information I need on this site, what can I do?
This intro page is here to help you quickly find relevant information when using Opis JSON Schema. It is designed as a Q&A because we try to answer you to the expected (incipient) questions that appear when using this library.
How do I install this library?
Simple, through composer
composer require opis/json-schema
How do I validate my data?
Please see the validator object page.
How to load json schema documents?
Please see the loader object page.
How can I add custom filters ($filters keyword)?
Please see the custom filters page.
How can I add custom formats (format keyword)?
Please see the custom formats page.
How can I add custom media types (contentMediaType keyword)?
Please see the custom media types page.
How can I extend the schema to add my own keywords?
There is no easy way to add your own keywords, because this means that you’ll make schema documents that will deviate from the original intent of json schema, and you’ll end up spending more time to maintain your own version of json schema (containing custom keywords) than you’ll need to extend and improve your app. Another reason is that not all keywords from json schema are independent (for example, check out additionalProperties), which means that you might need data or information from another keyword. And the last reason is performance, the more keywords you have, the more unnecessary checks will be made, so the slower the validation process will be.
Of course, we know that the json schema draft isn’t suitable for every validation case, that’s why we added support for filters where you can add your desired PHP validation logic, variables which enables the URI template support, and mappers to allow hardcore schema reuse. Not to mention that you can create custom formats and media types.
In 99.9999% of custom validation cases, creating a filter is enough, but if you still think that a new keyword is needed please open a GitHub issue to get in touch.
I cannot find the information I need on this site, what can I do?
Well, you can always create a GitHub issue explaining your problem.