sokil/php-json-schema-defaults

从 JSON Schema 提取默认值

0.1.0 2023-04-09 09:16 UTC

This package is auto-updated.

Last update: 2024-09-09 12:11:32 UTC


README

Coverage Status ci

从 JSON Schema 提取默认值。

支持 v.7 或其方言的草案。提取器假定传入的 schema 是有效的,因此请对其进行外部验证。

安装

composer req sokil/php-json-schema-defaults

用法

$schema = '{
    "$schema": "https://json-schema.fullstack.org.cn/draft-07/schema#",
    "type": "array", 
    "items": {"type": "string", "default": "hello"}
}';

$extractor = new Extractor();
$defaultValue = $extractor->extract($schema); // ["hello"]

控制台命令

要在控制台从 schema 获取默认值,请使用以下 bin

./vendor/bin/json-schema-defaults ~/path/to/schema.json