NAME

DBIx::Result::Convert::JSONSchema - Convert DBIx result schema to JSON schema

Build Status Coverage Status

VERSION

0.06

SYNOPSIS

use DBIx::Result::Convert::JSONSchema;

my $SchemaConvert = DBIx::Result::Convert::JSONSchema->new( schema => Schema );
my $json_schema = $SchemaConvert->get_json_schema( DBIx::Class::ResultSource );

DESCRIPTION

This module attempts basic conversion of DBIx::Class::ResultSource to equivalent of http://json-schema.org/. By default the conversion assumes that the DBIx::Class::ResultSource originated from MySQL database. Thus all the types and defaults are set based on MySQL field definitions. It is, however, possible to overwrite field type map and length map to support DBIx::Class::ResultSource from other database solutions.

Note, relations between tables are not taken in account!

get_json_schema

Returns somewhat equivalent JSON schema based on DBIx result source name.

my $json_schema = $converted->get_json_schema( 'TableSource', {
    schema_declaration              => 'http://json-schema.org/draft-04/schema#',
    decimals_to_pattern             => 1,
    has_schema_property_description => 1,
    allow_additional_properties     => 0,
    ignore_property_defaults        => 1,
    overwrite_schema_property_keys  => {
        name    => 'cat',
        address => 'dog',
    },
    add_schema_properties           => {
        address => { ... },
        bank_account => '#/definitions/bank_account',
    },
    overwrite_schema_properties     => {
        name => {
            _action  => 'merge', # one of - merge/overwrite
            minimum  => 10,
            maximum  => 20,
            type     => 'number',
        },
    },
    include_required   => [ qw/ street city / ],
    exclude_required   => [ qw/ name address / ],
    exclude_properties => [ qw/ mouse house / ],

    dependencies => {
        first_name => [ qw/ middle_name last_name / ],
    },
});

Optional arguments to change how JSON schema is generated:

SEE ALSO

DBIx::Class::ResultSource - Result source object

AUTHOR

malishew - malishew@cpan.org

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. If you would like to contribute documentation or file a bug report then please raise an issue / pull request:

https://github.com/Humanstate/p5-dbix-result-convert-jsonschema