定制 zepgram/module-json-schema 二次开发

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

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

zepgram/module-json-schema

最新稳定版本:0.1.1

Composer 安装命令:

composer require zepgram/module-json-schema

包简介

Json Schema Validation for Magento 2

README 文档

README

A Magento implementation for validating JSON Structures against a given Schema with support for Schemas of Draft-3 or Draft-4.
Based on https://github.com/justinrainbow/json-schema json schema.
For more information about json schema: http://json-schema.org/

Installation

composer require zepgram/module-json-schema bin/magento module:enable Zepgram_JsonSchema bin/magento setup:upgrade 

Guideline

  1. Add the formatted json-schema in your module, where webservice will be implemented under /etc/schema directory.
  2. Create a Virtual Class of type Zepgram\JsonSchema\Model\Validator and adapt fileName and moduleName parameters.

Example

/etc/di.xml

<virtualType name="HelloWorldValidator" type="Zepgram\JsonSchema\Model\Validator"> <arguments> <argument name="fileName" xsi:type="string">schema/hello-world-service.json</argument> <argument name="moduleName" xsi:type="string">Zepgram_HelloWorld</argument> </arguments> </virtualType>

/etc/schema/hello-world-service.json

{ "type":"array", "items":{ "type":"object", "required":[ "helloId", "helloContact" ], "properties":{ "helloId":{ "type":"string", "description":"Hello Id" }, "helloContact":{ "type":"array", "items":{ "type":"object", "required":[ "age", "fullName" ], "properties":{ "age":{ "type":"integer", "format":"int32", "description":"contact age", "minimum":-2147483648, "maximum":2147483647 }, "fullName":{ "type":"object", "required":[ "firstname", "lastname" ], "properties":{ "firstname":{ "type":"string", "description":"contact firstname" }, "lastname":{ "type":"string", "description":"contact lastname" } } } } } } } }, "$schema":"http://json-schema.org/draft-04/schema#" }

Open API V3

If your architecture is using open API-V3 to describe web service usage you can convert it to json schema.

  1. Install the node utility: https://github.com/mikunn/openapi2schema
  2. Convert the open api yaml file into JSON:
    openapi2schema -i my-custom-service.yaml | python -m json.tool | jq '."%end_point%".post.body' > my-custom-service.json
    where %endpoint% must be replaced by your api endpoint described in yaml file (e.g.: /v1/customEndPoint)

Issues

If you encountered an issue during installation or with usage, please report it on this github repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固