JSON Schema is a popular vocabulary to describe the shape of JSON documents. A variant of JSON Schema is also used in OpenAPI specifications.
API Platform provides an infrastructure to generate JSON Schemas for any resource, represented in any format (including JSON-LD). The generated schema can be used with libraries such as react-json-schema-form to build forms for the documented resources, or to be used for validation.
To export the schema corresponding to an API Resource, run the following command:
$ docker-compose exec php bin/console api:json-schema:generate 'App\Entity\Book'
To see all options available, try:
$ docker-compose exec php bin/console help api:json-schema:generate
To generate JSON Schemas programmatically, use the api_platform.json_schema.schema_factory
service.
API Platform provides a PHPUnit assertion to test if a response is valid according to a given Schema: assertMatchesJsonSchema()
.
Refer to the testing documentation for more details.
Made with love by
Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.
Learn more