A Magento implementation for validating JSON Structures against a given Schema

Overview

Zepgram JsonSchema

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

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

You might also like...
Applies a patch from a local or remote file to any package that is part of a given composer project.

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level in package config or separate JSON file. Declaration-free mode (using embedded info within patch files) is available as well.

Tentative Extra Data Structures for php

Teds Introduction Teds is a another collection of data structures. (Tentative Extra Data Structures) Installation This extension requires php 8.0 or n

A collection of type-safe functional data structures

lamphpda A collection of type-safe functional data structures Aim The aim of this library is to provide a collection of functional data structures in

Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

Json-normalizer: Provides generic and vendor-specific normalizers for normalizing JSON documents

json-normalizer Provides generic and vendor-specific normalizers for normalizing JSON documents. Installation Run $ composer require ergebnis/json-nor

PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data
PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data

PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data PDF ENGINE VERSION: development: This is a prerelease version

The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

Snuffleupagus is a PHP 7+ and 8+ module designed to drastically raise the cost of attacks against websites, by killing entire bug classes
Snuffleupagus is a PHP 7+ and 8+ module designed to drastically raise the cost of attacks against websites, by killing entire bug classes

Snuffleupagus is a PHP 7+ and 8+ module designed to drastically raise the cost of attacks against websites, by killing entire bug classes

LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

Releases(v0.1.0)
Owner
Benjamin Calef
Adobe Certified Professional - Magento Commerce Developer
Benjamin Calef
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
Swaggest JSON-schema implementation for PHP

Swaggest JSON-schema implementation for PHP High definition PHP structures with JSON-schema based validation. Supported schemas: JSON Schema Draft 7 J

null 370 Dec 29, 2022
laminas-xml2json provides functionality for converting XML structures to JSON

laminas-xml2json This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Stee

Laminas Project 13 Dec 28, 2022
JSON schema models and generated code to validate and handle various data in PocketMine-MP

DataModels JSON schema models and generated code to validate and handle various data in PocketMine-MP This library uses php-json-schema-model-generato

PMMP 2 Nov 9, 2022
Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

LimeSoda Interactive Marketing GmbH 73 Apr 1, 2022
A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

Jan Schädlich 69 Dec 18, 2022
Tools for working with the SPDX license list and validating licenses.

composer/spdx-licenses SPDX (Software Package Data Exchange) licenses list and validation library. Originally written as part of composer/composer, no

Composer 1.4k Dec 26, 2022
Laravel-hours-helper - Creates a Collection of times with a given interval.

Laravel Hours Helper With laravel-hours-helper you can create a collection of dates and/of times with a specific interval (in minutes) for a specific

Label84 220 Dec 29, 2022
Enabling community-powered extension and improvements of the best time indications given.

Enabling community-powered extension and improvements of the best time indications given.

Digital Markethingz 2 Jun 29, 2022