Coder Social home page Coder Social logo

p5-dbix-result-convert-jsonschema's Introduction

NAME

DBIx::Result::Convert::JSONSchema - Convert DBIx result schema to JSON schema
Build Status Coverage Status

VERSION

0.04

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,
    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:

  • schema_declaration

    Declare which version of the JSON Schema standard that the schema was written against.

    https://json-schema.org/understanding-json-schema/reference/schema.html

    Default: "http://json-schema.org/schema#"

  • decimals_to_pattern

    1/0 - value to indicate if 'number' type field should be converted to 'string' type with RegExp pattern based on decimal place definition in database.

    Default: 0

  • has_schema_property_description

    Generate schema description for fields e.g. 'Optional numeric type value for field context e.g. 1'.

    Default: 0

  • allow_additional_properties

    Define if the schema accepts additional keys in given payload.

    Default: 0

  • overwrite_schema_property_keys

    HashRef representing mapping between old property name and new property name to overwrite existing schema keys, Properties from old key will be assigned to the new property.

    Note The key conversion is executed last, every other option e.g. exclude_properties will work only on original database column names.

  • overwrite_schema_properties

    HashRef of property name and new attributes which can be either overwritten or merged based on given _action key.

  • exclude_required

    ArrayRef of database column names which should always be EXCLUDED from REQUIRED schema properties.

  • include_required

    ArrayRef of database column names which should always be INCLUDED in REQUIRED schema properties

  • exclude_properties

    ArrayRef of database column names which should be excluded from JSON schema AT ALL

  • dependencies

    https://json-schema.org/understanding-json-schema/reference/object.html#property-dependencies

  • add_schema_properties

    HashRef of custom schema properties that must be included in final definition Note that custom properties will overwrite defaults

  • schema_overwrite

    HashRef of top level schema properties e.g. 'required', 'properties' etc. to overwrite

SEE ALSO

DBIx::Class::ResultSource - Result source object

AUTHOR

malishew - [email protected]

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

p5-dbix-result-convert-jsonschema's People

Contributors

manwar avatar vskrupskis avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.