Understanding JSON Schema
Nowadays, almost all REST APIs expose data in JSON format. It is crucial to define this data strictly to ensure that our contract, documented as an OpenAPI Specification file, remains unambiguous. Understanding how to use JSON Schema is essential for creating well-defined APIs. In this section, we will explore its purpose and how to create schema files effectively.
Open nature
Unlike XML schemas, which are closed by nature, JSON Schema is considered open. This means JSON Schema inherently allows for flexible definitions that can accommodate additional properties not explicitly defined in the schema. This openness promotes extensibility and interoperability, but it may also introduce ambiguity, requiring you to carefully define all necessary constraints. In contrast, closed schemas ensure that only the elements explicitly defined in your code are permitted.
Introduction to JSON Schema
JSON Schema is a descriptive language used...