承接 programster/json-schema-creator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固