programster/json-schema-creator
Composer 安装命令:
composer require programster/json-schema-creator
包简介
A PHP package to make it easier create JSON schemas.
README 文档
README
JSON Schema Creator This is a simple PHP package to make it quick and easy to generate a JSON schema that can then be used for validation and documentation.
This tool was built primarily with the help of the documentation for JSON schemas at opis.io/json-schema.
Install
composer require programster/json-schema-creator
Example
<?php require_once(__DIR__ . '/../vendor/autoload.php'); $name = new \Programster\JsonSchema\Types\StringType(name: "product_name", minLength: 3); $barcode = new \Programster\JsonSchema\Types\StringType(name: "barcode", minLength: 12); $description = new \Programster\JsonSchema\Types\StringType(name: "description", minLength: 12); $requiredProperties = array( $name, $barcode, ); $nonRequiredProprties = array( $description ); $object = new Programster\JsonSchema\Types\ObjectType( "Product", new Programster\JsonSchema\PropertyCollection(...$requiredProperties, ...$nonRequiredProprties), new Programster\JsonSchema\RequiredPropertiesCollection(...$requiredProperties) ); $schema = new \Programster\JsonSchema\Schema($object, "Product Schema", "A product definition"); print($schema) . PHP_EOL;
That would generate the following schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "Product Schema",
"title": "A product definition",
"name": "Product",
"type": "object",
"properties": {
"product_name": {
"type": "string",
"minLength": 3
},
"barcode": {
"type": "string",
"minLength": 12
},
"description": {
"type": "string",
"minLength": 12
}
},
"required": [
"product_name",
"barcode"
]
}
Testing
You can check that your generated schema is valid by using jsonschemalint.com
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-21