一句话:提出 JSON 子模式检查,通过规范化简化与类型特定检查器,在具体数据出现前发现数据兼容性缺陷。
JSON 广泛用于 Web API、云计算、NoSQL 数据库和机器学习流水线,但传统的模式验证只能在具体数据出现后检查,可能过晚甚至漏检模式演化或组件间期望不一致导致的数据兼容性缺陷。本文提出 JSON 子模式检查,在具体 JSON 数据可用之前判断一个模式是否为另一个的子模式,从而覆盖模式规定的所有可能数据。由于 JSON Schema 表达力强、子模式判定困难,作者先将模式规范化并简化,再在简化片段上使用类型特定检查器进行推理。作者在来自不同领域的数千个真实模式上评估:方法在给出答案时保持 100% 精度与正确性,召回率达 93.5%,明显优于当前最佳工具,并揭示 43 个此前未知的流行软件缺陷,多数已被修复。
JSON is a data format used pervasively in web APIs, cloud computing, NoSQL databases, and increasingly also machine learning. To ensure that JSON data is compatible with an application, one can define a JSON schema and use a validator to check data against the schema. However, because validation can happen only once concrete data occurs during an execution, it may detect data compatibility bugs too late or not at all. Examples include evolving the schema for a web API, which may unexpectedly break client applications, or accidentally running a machine learning pipeline on incorrect data. This paper presents a novel way of detecting a class of data compatibility bugs via JSON subschema checking. Subschema checks find bugs before concrete JSON data is available and across all possible data specified by a schema. For example, one can check if evolving a schema would break API clients or if two components of a machine learning pipeline have incompatible expectations about data. Deciding whether one JSON schema is a subschema of another is non-trivial because the JSON Schema specification language is rich. Our key insight to address this challenge is to first reduce the richness of schemas by canonicalizing and simplifying them, and to then reason about the subschema question on simpler schema fragments using type-specific checkers. We apply our subschema checker to thousands of real-world schemas from different domains. In all experiments, the approach is correct whenever it gives an answer (100% precision and correctness), which is the case for most schema pairs (93.5% recall), clearly outperforming the state-of-the-art tool. Moreover, the approach reveals 43 previously unknown bugs in popular software, most of which have already been fixed, showing that JSON subschema checking helps finding data compatibility bugs early.