Api Platform conference
Register now
v2.5 JSON Schema Support
API Platform Conference
September 19-20, 2024 | Lille & online

The international conference on the API Platform Framework

API Platform Conference 2024: meet the best PHP, JavaScript and API experts

Learn more about the event, register for the conference, and get ready for two days of inspiration, ideas, and knowledge-sharing with our incredible lineup of renowned specialists and advocates.

Register now

# JSON Schema Support

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.

# Generating a JSON Schema

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

# Generating a JSON Schema Programmatically

To generate JSON Schemas programmatically, use the api_platform.json_schema.schema_factory service.

# Testing

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.

You can also help us improve the documentation of this page.

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

Copyright © 2023 Kévin Dunglas

Sponsored by Les-Tilleuls.coop