Changeset 2624


Ignore:
Timestamp:
Apr 17, 2020, 8:27:38 PM (4 months ago)
Author:
Bruno Cornec
Message:

More tests around OpenAPI - back to a working server with v3

Location:
devel/pb-server
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-server/README

    r2293 r2624  
    44The whole Project-builder.org project is provided under the GPL v2 as per the copying file.
    55Other licenses may be available in addition later on.
     6
     7Reference docs:
     8https://fr.slideshare.net/ssoriche/metacpan-mojolicious-and-openapi
     9https://mojolicious.io/blog/2017/12/22/day-22-how-to-build-a-public-rest-api/
     10
  • devel/pb-server/bin/pb-server

    r2512 r2624  
    44use warnings;
    55
    6 use lib 'lib';
    76use ProjectBuilder::Env;
    87use ProjectBuilder::Conf;
     
    109
    1110# Start command line interface for application
    12 require Mojolicious::Commands;
     11use Mojo::File qw(curfile);
     12use lib curfile->dirname->sibling('lib')->to_string;
     13use Mojolicious::Commands;
    1314
    1415# Force for now
    1516pb_env_init("pb",undef,"none",0);
     17
     18# Debug YAML validation
     19$ENV{'JSON_VALIDATOR_DEBUG'} = 1;
     20
    1621#print "CONF: ".Dumper(pb_conf_get_hash())."\n";
     22# Start command line interface for application
    1723Mojolicious::Commands->start_app('ProjectBuilder');
  • devel/pb-server/lib/ProjectBuilder.pm

    r2461 r2624  
    11package ProjectBuilder;
    22use Mojo::Base 'Mojolicious';
     3use ProjectBuilder::Model::Confs;
     4use Data::Dumper;
     5use ProjectBuilder::YAML;
     6use JSON;
    37
    4 use ProjectBuilder::Model::Confs;
    5 
     8# This method will run once at server start
    69sub startup {
    710  my $self = shift;
    811
    9   # Configuration
    10   #$self->secrets([split /:/, $ENV{'BLOG_SECRETS'} || 'super:s3cret']);
    11 
     12  print Dumper($self);
    1213  # Model
    13   #$self->helper(pg => sub { state $pg = Mojo::Pg->new($ENV{'BLOG_PG_URL'}) });
    1414  $self->helper(confs => sub { state $confs = ProjectBuilder::Model::Confs->new() });
    1515
    16   # Migrate to latest version if necessary
    17   #my $path = $self->home->rel_file('migrations/blog.sql');
    18   #$self->pg->migrations->name('blog')->from_file($path)->migrate;
     16  # Load configuration from hash returned by config file - doesn't work for now
     17  #my $config = $self->plugin('Config' => { file => 'etc/pb-server.json' });
    1918
    20   # Swagger API endpoints
     19  # Configure the application
     20  #$self->secrets([split /:/, $ENV{'BLOG_SECRETS'} || 'super:s3cret']);
     21  #$self->secrets($config->{secrets});
     22
     23  # Load Open API endpoins
    2124  # /api             *       api
    2225  #   +/confs        POST    "store"
     
    2528  #   +/confs/(:id)  DELETE  "remove"
    2629  #   +/confs/(:id)  GET     "show"
    27   $self->plugin(openapi => {url => $self->home->rel_file('api.yml')});
     30  my $c = {
     31        #schema => "v3",
     32        default_response_codes => [400, 401, 404, 500, 501],
     33        #default_response_name => 1,
     34        url => 'file:///usr/share/pb/api.yaml',
     35        };
     36  $self->plugin(OpenAPI => $c);
     37  print "After Plugin OpenAPI\n";
     38  #$self->plugin(OpenAPI => {schema_file => $self->home->rel_file('api.yaml'), schema => "v3"});
    2839
    2940  # Regular web pages
     
    3647  # /confs/:id       PUT     "update_conf"
    3748  # /confs/:id       DELETE  "remove_conf"
     49
     50  # Router
    3851  my $r = $self->routes;
     52
     53  # Normal route to controller
     54  $r->get('/w')->to('example#welcome');
    3955  $r->get('/' => sub { shift->redirect_to('confs') });
    4056  $r->get('/confs')->to('conf#list');
     
    4864  # Swagger2 module not maintained anymore
    4965  #require Swagger2::Editor;
    50   #my $editor = Swagger2::Editor->new(specification_file => $self->home->rel_file('api.yml'));
     66  #my $editor = Swagger2::Editor->new(specification_file => $self->home->rel_file('api.yaml'));
    5167  #$r->route('/editor')->detour(app => $editor);
    5268}
Note: See TracChangeset for help on using the changeset viewer.