base';
use Scalar::Util qw( blessed );
use Yancy::Util qw( is_type is_format );
use Mojo::JSON qw( encode_json );
has schema => sub { {} };
sub collections {
require Carp;
Carp::carp( '"colle
all backends, and may never be supported by
#pod some. Postgres has array columns and JSON fields. MySQL has JSON fields.
#pod The L<Yancy::Util/match> function matches against Perl data structures.
ise.
#pod
#pod Currently the values of the data cannot be references, only simple
#pod scalars or JSON booleans.
#pod
#pod =cut
sub set { ... }
#pod =head2 set_p
#pod
#pod my $promise = $be->set
logout_route => $self->logout_route->render,
);
$c->respond_to(
json => {},
html => {},
);
return undef;
};
}
around register => sub
!$self->isa( scalar caller ) ) {
return $self->{data};
}
return $self;
}
sub TO_JSON {
my ( $self ) = @_;
return $self->{data};
}
#pod =attr schema
#pod
#pod The L<Yancy::Mo
des::Model>, L<Yancy::Model>
#pod
#pod =cut
use Mojo::Base -base;
use Mojo::JSON qw( true false );
use Yancy::Util qw( json_validator is_type derp );
#pod =attr model
#pod
#pod The L<Yancy::Model> o
=> sub { die 'name is required' };
#pod =attr json_schema
#pod
#pod The JSON Schema for this schema.
#pod
#pod =cut
has json_schema => sub { die 'json_schema is required' };
sub _backend { shift->
sub new {
my ( $class, @args ) = @_;
my $self = $class->SUPER::new( @args );
$self->_check_json_schema;
return $self;
}
#pod =method id_field
#pod
#pod The ID field for this schema. Either a
mas are configured using L<JSON Schema|http://json-schema.org>.
The JSON Schema defines what fields (properties) an item has, and what
type of data those field have. The JSON Schema also can define
co
even an C<example> value. For more information on
what can be defined, see L<the docs on JSON Schema|http://json-schema.org>.
=head2 Yancy Generated Schema
By default, Yancy will read your database
ger C<id> and two
strings, C<name> (not nullable) and C<email> (nullable)), Yancy will
generate a JSON schema that looks like this:
schema => {
people => {
required => [ 'name
the error',
# Description of path field in OpenAPI error object
'OpenAPI error path' => 'JSON pointer to the input data where the error occur',
);
1;
__END__
=pod
=head1 NAME
Yancy::I18N
handlers also gives you a built-in JSON API for your
#pod website. Any user agent that requests JSON will get JSON instead of
#pod HTML. For full details on how JSON clients are detected, see
#pod L<M
ALSO
#pod
#pod L<Yancy>
#pod
#pod =cut
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON qw( to_json );
use Yancy::Util qw( derp is_type );
use POSIX qw( ceil );
#pod =method schema
#pod
#pod
words).
#pod
#pod =cut
sub clean_item {
my ( $self, $item ) = @_;
my $props = $self->schema->json_schema->{properties};
my @keep_props = grep { !$props->{$_} || ($props->{$_}{format}//'') ne 'p
form_for( 'people' );
#pod
#pod =head1 DESCRIPTION
#pod
#pod The Form plugins generate forms from JSON schemas. Plugin and
#pod application developers can use the form plugin API to make forms, and
#p
#pod
#pod =over
#pod
#pod =item type
#pod
#pod The type of the input field to create. One of the JSON schema types.
#pod See L<Yancy::Guides::Schema/Types> for details on the supported
#pod types.
#p
ormat
#pod
#pod For C<string> types, the format the string should take. One of the
#pod supported JSON schema formats, along with some additional ones. See
#pod L<Yancy::Guides::Schema/Types> for deta
en enhanced to support everything that
Yancy::Controller::Yancy::API could do (like searching and JSON in the
request body).
To get back to the old API, set C<editor.default_controller> to
'Yancy::Co
s );
use Scalar::Util qw( blessed );
use Mojo::JSON::Pointer;
use Mojo::JSON qw( to_json );
use Mojo::Util qw( xml_escape );
use Carp qw( carp );
use JSON::Validator;
our @EXPORT_OK = qw( load_backen
d curry currym copy_inline_refs match derp fill_brackets
is_type order_by is_format json_validator );
#pod =sub load_backend
#pod
#pod my $backend = load_backend( $backend_url, $schema );
#po
erence
#pod with a backend name and optional argument. The C<$schema> hash is
#pod the configured JSON schema for this backend.
#pod
#pod A backend URL should begin with a name followed by a colon. Th
=item Learning JSON Schema
Yancy uses L<JSON Schema|https://json-schema.org> to define and annotate
the database schema. You can read more L<from the JSON Schema tutorial|https://json-schema.org/lea
ncy/auth/unauthorized',
status => 401,
);
$c->respond_to(
json => {},
html => {},
);
return undef;
}
}
sub has_role {
my (
calar::Util qw( blessed );
use Mojo::JSON qw( true false );
use Mojo::Util qw( url_escape );
use Sys::Hostname qw( hostname );
use Yancy::Util qw( derp currym json_validator load_backend );
has monik
=> $spec,
default_response_name => '_Error',
validator => json_validator(),
} );
$_->to(format => 'json') for (@{$openapi->route->children});
$app->helper( 'yancy.openapi'
format => 'json',
};
}
else {
# per-schema - GET = "list"
return {
action => 'list',
format => 'json',
scans your database to determine what kind of data is inside, but
Yancy also accepts a L<JSON Schema|http://json-schema.org> to add more
information about your data. You can add descriptions, examples
L<Mojo::Pg>, L<Yancy>
#pod
#pod =cut
use Mojo::Base 'Yancy::Backend::MojoDB';
use Mojo::JSON qw( encode_json );
use Scalar::Util qw( blessed );
BEGIN {
eval { require Mojo::Pg; Mojo::Pg->VERSION
#pod
#pod =cut
use Mojo::Base '-role';
use List::Util qw( any );
use DBI ':sql_types';
use Mojo::JSON qw( true );
requires 'dbh', 'table_info';
# only specify non-string - code-ref called with colu
ojolicious::Controller>
#pod
#pod =cut
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON qw( to_json );
use Yancy::Util qw( derp );
#pod =method list
#pod
#pod List the items in a schema. The
-not_bool' } = $key;
}
else {
die "Sorry type '" .
to_json( $type ) .
"' is not handled yet, only string|number|integer|boolean is supported
tem is extracted from the OpenAPI input, under parameter name
#pod C<newItem>, and must be a hash/JSON "object". It will be filtered by
#pod filters conforming with L<Mojolicious::Plugin::Yancy/yancy.
oken', $token ) },
)
->then( sub {
my ( $tx ) = @_;
my $login = $tx->res->json( '/login' );
if ( !$login ) {
$c->render( text => 'Error getting Github login
r_id';
my $user_id = $c->stash( 'user_id' );
if ( eval { $c->req->json } ) {
$c->req->json->{ $user_id_field } = $user_id;
}
else {
$c->req->par
hen the user is not logged
#pod in.
#pod
#pod =head2 yancy/auth/unauthorized.json.ep
#pod
#pod This template renders a JSON object with an "errors" array explaining
#pod the error.
#pod
#pod =head2 la
ost-often appears when the user is not logged
in.
=head2 yancy/auth/unauthorized.json.ep
This template renders a JSON object with an "errors" array explaining
the error.
=head2 layouts/yancy/auth.h