定制 wwwision/jsonschema 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

wwwision/jsonschema

Composer 安装命令:

composer require wwwision/jsonschema

包简介

PHP Classes to represent JSON schema, see https://json-schema.org/

README 文档

README

PHP Classes to represent JSON Schemas, see JSON Schema

Usage

This package can be installed via composer:

composer require wwwision/jsonschema

With that, you can define a JSON Schema in PHP:

$schema = new ObjectSchema(
    title: 'Product',
    description: 'A product in the catalog',
    properties: ObjectProperties::create(
        id: new StringSchema(
            title: 'ID',
            description: 'The unique identifier for a product',
            format: StringFormat::uuid,
        ),
        title: new StringSchema(
            title: 'Product title',
            description: 'The name of the product',
        ),
        available: new BooleanSchema(
            title: 'Whether the product is available',
        ),
        price: new NumberSchema(
            title: 'Price',
            description: 'The price of the product',
            default: 0.0,
            minimum: 0.0,
        )
    )
);

$expected = <<<JSON
{
    "type": "object",
    "title": "Product",
    "description": "A product in the catalog",
    "properties": {
        "id": {
            "type": "string",
            "title": "ID",
            "description": "The unique identifier for a product",
            "format": "uuid"
        },
        "title": {
            "type": "string",
            "title": "Product title",
            "description": "The name of the product"
        },
        "available": {
            "type": "boolean",
            "title": "Whether the product is available"
        },
        "price": {
            "type": "number",
            "title": "Price",
            "description": "The price of the product",
            "default": 0,
            "minimum": 0
        }
    }
}
JSON;

assert(json_encode($schema, JSON_PRETTY_PRINT) === $expected);

JSON Schema generator

See wwwision/types-jsonschema package for a JSON Schema generator that can generate JSON Schemas from PHP classes.

Contribution

Contributions in the form of issues or pull requests are highly appreciated

License

See LICENSE

统计信息

  • 总下载量: 7.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固