2017 © Pedro Peláez
 

symfony-bundle json-schema-bundle

Symfony bundle to validate json api request and responses with json-schema

image

bcastellano/json-schema-bundle

Symfony bundle to validate json api request and responses with json-schema

  • Tuesday, November 8, 2016
  • by bcastellano
  • Repository
  • 1 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status SensioLabsInsight License, (*1)

Json-Schema Bundle

Symfony bundle to validate json api requests and responses based on JSON Schema specification., (*2)

It auto validates Requests and Responses for an API with json-schema files that can be auto generated from json body., (*3)

JSON Schema is described in its specification as:, (*4)

JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema provides a contract for what JSON data is required for a given application and how to interact with it. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data., (*5)

Features

  • Json Schema service for validate jsons
  • Listener to auto validate request and responses
  • Json Schema file generation from json body (request and responses content)

Installation

Composer:, (*6)

composer require bcastellano/json-schema-bundle

Load the bundle:, (*7)

<?php
// app/AppKernel.php

use Bcastellano\JsonSchemaBundle\JsonSchemaBundle;

public function registerBundles()
{
    $bundles = array(
        // ...
        new JsonSchemaBundle(),
    );
}

Configuration

This is a complete example of configuration parameters:, (*8)

json_schema:
    # Validator
    validator:
        # Class to use in validation. Is an enum
        class: Bcastellano\JsonSchemaBundle\Validator\JsonSchemaValidator
        # To auto register request and response events to auto validate jsons 
        use_listener: true

    # Locator
    locator:
        # Class to locate schema files
        class: Bcastellano\JsonSchemaBundle\Locator\ControllerSchemaFileLocator
        # Directory for json schema files (also to save new ones)
        resources_dir: '%kernel.root_dir%/Resources/Schemas'

    # Configuration for schema generator
    generator:
        enabled: false
        # NOTE: these two configurations are incompatible, you can't configure both
        # this use any external command to generate schema from json
        command: '/path/to/command {{source_file}} --output {{target_file}}'
        # this use any custom service to generate schema from json
        service: 'some.custom.service'

License

This bundle is under the MIT License, (*9)

The Versions

08/11 2016