Deserializes perl structures, JSON or YML data, from strings or files
use strict;
use warnings;
use File::Basename;
use IO::All;
use Readonly;
use JSON qw(decode_json);
use YAML::XS;
use Syntax::
'yaml',
json => 'json',
);
Readonly::Scalar my $DEFAULT_DECODER => q{perl};
sub decoders() {
return (
yaml => sub {
Load(shift());
},
json => sub {
decode_json(shift());
d
=encoding UTF-8
=head1 NAME
Config::Structured::Deserializer - Deserializes perl structures, JSON or YML data, from strings or files
=head1 VERSION
version 2.004
=head1 AUTHOR
Mark Tyrrell <m
ge main 0.01;
use 5.020;
use experimental 'signatures';
use Getopt::Long;
use Mojo::Template;
use JSON::Pointer;
use YAML::PP;
use OpenAPI::PerlGenerator;
use OpenAPI::PerlGenerator::Utils 'update_fi
B< output > - name of the output directory
=item * B< api > - name of the OpenAPI file (YAML or JSON)
=item * B< tidy > - clean up the code using perltidy
=item * B< compile > - check that the gen
e //= 'openapi/openapi.yaml';
$output_directory //= '.';
my $schema = YAML::PP->new( boolean => 'JSON::PP' )->load_file( $api_file );
my %template = %OpenAPI::PerlGenerator::Template::Mojo::template
se JSON::Pointer;
use Markdown::Pod;
=head1 NAME
OpenAPI::PerlGenerator - create Perl client SDKs from OpenAPI specs
=head1 SYNOPSIS
my $api_file = slurp( 'petshop.json' );
my $schema = JSON::
ring => 'Str',
number => 'Num',
integer => 'Int',
boolean => '', # a conflict between JSON::PP::Boolean and Type::Tiny
object => 'Object',
);
=item * B<typemap>
Hashref with the map
{ %default_typemap } },
);
sub fixup_json_ref( $root, $curr=$root ) {
if( ref $curr eq 'ARRAY' ) {
for my $c ($curr->@*) {
$c = fixup_json_ref( $root, $c );
}
} e
oose;
use Modern::Perl;
use Carp;
use MARC::Moose::Formater::Iso2709;
use MARC::Moose::Formater::Json;
use MARC::Moose::Formater::Legacy;
use MARC::Moose::Formater::Marcxml;
use MARC::Moose::Formater
cxmlSax;
use MARC::Moose::Parser::Legacy;
use MARC::Moose::Parser::Yaml;
use MARC::Moose::Parser::Json;
with 'MARC::Moose::Lint::Checker';
has lint => (
is => 'rw',
);
has leader => (
is
iso2709 => MARC::Moose::Formater::Iso2709->new(),
json => MARC::Moose::Formater::Json->new(),
legacy => MARC::Moose::Formater::Legacy->
Stancer::Exceptions::InvalidSearchStart;
use Stancer::Exceptions::InvalidSearchUntilCreation;
use JSON;
use Scalar::Util qw(blessed);
use Try::Tiny;
use Moo;
use namespace::clean;
sub _create_eleme
$json = decode_json $response;
$more = $json->{range}->{has_more} == JSON::true;
@elements = @{$json->{$class->_element_key}};
$data->{start} += $json
r\n Foo::Bar=arg1,arg2\n\nSee also: `perl::modname`.\nA two-element array from (coercible from JSON string) is also allowed:\n\n [\"Foo::Bar\", \\\@args]\n\n",examples=>[{valid=>0,value=>""},{va
"]]},{summary=>"Too many elements",valid=>0,value=>["Foo",["arg1","arg2"],{}]}],of=>[["array_from_json",{description=>"\nThese are valid values for this schema:\n\n [\"Foo\"]
oo::Bar
Foo::Bar=arg1,arg2
See also: C<perl::modname>.
A two-element array from (coercible from JSON string) is also allowed:
["Foo::Bar", \@args]
=item * L<perl::modname_with_optional_ver|Sah::
sub _to_json {
my $obj = shift;
require Data::Visitor::Tiny;
require Data::Clone;
require Sca
{ $_[1] } );
${ $_[1] }
= defined( $object->can( 'TO_JSON' ) )
? $object->TO_JSON
: $object->isa( 'PDL' ) ? $object->dims == 0
?
{ TO_JSON => \&_to_json },
},
{
-as => '_return_iterate_results',
-class => 'PDL::Algorithm::Center::Iterate::Results',
-methods => { TO_JSON => \&_to_json },
pletion' => 'perl_modname',
examples => \@examples_str,
}];
our $schema_array = [array_from_json => {
summary => 'A 1- or 2-element array containing Perl module name (e.g. ["Foo::Bar"]) with
::Bar
Foo::Bar=arg1,arg2
See also: `perl::modname`.
A two-element array from (coercible from JSON string) is also allowed:
["Foo::Bar", \@args]
_
of => [
$schema_array,
with optional arguments (e.g. Foo::Bar=arg1,arg2)",
"of" => [
[
"array_from_json",
{
summary => "A 1- or 2-element array containing Perl module name (e.g.
;
use Stancer::Core::Request;
use List::MoreUtils qw(any first_index);
use Log::Any qw($log);
use JSON;
use Scalar::Util qw(blessed);
use Storable qw(dclone);
use Moo;
use namespace::clean;
around
has _integer => (
is => 'ro',
isa => ArrayRef[Str],
default => sub{ [] },
);
has _json_ignore => (
is => 'ro',
isa => ArrayRef[Str],
default => sub{ [qw(endpoint created po
$data = Stancer::Core::Request->new->del($this);
if ($data) {
$this->hydrate(decode_json $data);
}
my @parts = split m/::/sm, ref $this;
my $class = $parts[-1];
$log->i
_ro';
use Carp;
use Hash::Merge;
use Clone 'clone';
use List::AllUtils qw/ first any none /;
use JSON;
use Class::Load qw/ load_class /;
has route => ( handles => [ 'pattern' ] );
has tags => ( pre
", ref $serializer
if none { $serializer->isa($_) } qw/ Dancer2::Serializer::JSON Dancer2::Serializer::YAML /;
$r->{examples}{$serializer->content_type} = $example
definitions},
properties => { response => $schema },
};
my $result = load_class('JSON::Schema::AsType')->new( schema => $schema)->validate_explain({ response => $data });
return
\%plugin_config,
};
}
use Dancer2::Plugin::JobScheduler;
set serializer => 'JSON';
get q{/submit_job} => sub {
my %r = submit_job(
client => 'theschwartz
'My Name', age => 123 },
opts => {},
},
);
return to_json(\%r);
};
get q{/list_jobs} => sub {
my %r = list_jobs(
client => 'th
search_params => {
task => 'task1',
},
);
return to_json(\%r);
};
=head1 DESCRIPTION
Dancer2::Plugin::JobScheduler is an interface to access differe
ide send_error ?
# TODO: add 'validate_schema'
# TODO: add 'strict_schema'
# TODO: make /swagger.json configurable
package Dancer2::Plugin::OpenAPI;
our $AUTHORITY = 'cpan:YANICK';
# ABSTRACT: creat
/^qr/ ? eval $_ : $_ }
@{ $_[0]->config->{auto_discover_skip} || [
'/openapi.json', ( 'qr!' . $_[0]->ui_url . '!' ) x $_[0]->show_ui
] }
];
},
);
has validate_res
url configurable
$self->app->add_route(
method => 'get',
regexp => '/openapi.json',
code => sub { $self->doc },
);
if ( $self->show_ui ) {
my $base_url =
default => sub{ [qw(date_birth)] },
);
has '+endpoint' => (
default => 'sepa',
);
has '+_json_ignore' => (
default => sub{ [qw(check endpoint created populated country last4)] },
);
has
use Stancer::Config;
use Stancer::Core::Request::Call;
use Stancer::Exceptions::Http;
use JSON qw(decode_json);
use Log::Any qw($log);
use Try::Tiny;
use Moo;
use namespace::clean;
sub del {
m
;
my $request = HTTP::Request->new(PATCH => $object->uri);
$request->content($object->toJSON());
return $this->_request($request, $object);
}
sub post {
my $this = shift;
my $
t;
my $request = HTTP::Request->new(POST => $object->uri);
$request->content($object->toJSON());
return $this->_request($request, $object);
}
sub _clean_request {
my $this = shift;
re)] },
);
has '+_inner_objects' => (
default => sub{ [qw(card customer sepa)] },
);
has '+_json_ignore' => (
default => sub{ [qw(endpoint created populated method refunds)] },
);
has '+end
'0.003'; # VERSION
our $rschema = do{my$var={base=>"any",clsets_after_base=>[{of=>[["array_from_json",{elems=>[["str",{match=>"\\A(?:[A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*(?:=.*)?)\\z","x.completi
t => 'cards',
);
has '+_integer' => (
default => sub{ [qw(exp_month exp_year)] },
);
has '+_json_ignore' => (
default => sub{ [qw(endpoint created populated brand country last4)] },
);
has
'0.005'; # VERSION
our $rschema = do{my$var={base=>"any",clsets_after_base=>[{of=>[["array_from_json",{elems=>[["str",{match=>"\\A(?:[A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*(?:=.*)?)\\z","x.completi
> 1,
);
sub TO_JSON {
my $self = shift;
return {} unless defined $self->sepa;
return { id => $self->sepa->id } if defined $self->sepa->id;
return $self->sepa->TO_JSON();
}
1;
__END