From 8decf1e23be4b1ea3828be7085f6a7add4e9858f Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Thu, 15 Aug 2013 13:03:45 -0500 Subject: [PATCH 1/3] Edits to make API url's show up correctly in return structures. --- src/MGRAST/cgi/api2.cgi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/MGRAST/cgi/api2.cgi b/src/MGRAST/cgi/api2.cgi index 43dd13cd..124029a1 100644 --- a/src/MGRAST/cgi/api2.cgi +++ b/src/MGRAST/cgi/api2.cgi @@ -33,6 +33,13 @@ if ($abs !~ /\.cgi/) { } my $rest = $cgi->url(-path_info=>1); $rest =~ s/^.*$abs\/?//; +$rest =~ s/^\///; +$rest =~ s/^\d+//; +$rest =~ s/^beta//; +$rest =~ s/^\///; +$rest =~ s/^api2\.cgi//; +$rest =~ s/^\///; + my @rest_parameters = split m#/#, $rest; map {$rest[$_] =~ s#forwardslash#/#gi} (0 .. $#rest); @@ -177,11 +184,14 @@ if ($resource) { } # we are called without a resource, return API information else { - my @resource_objects = map { { 'name' => $_, 'url' => $cgi->url.'/'.$_ } } sort @$resources; + my $cgi_url = $cgi->url; + $cgi_url =~ s/^(.*)\/$/$1/; + $cgi_url =~ s/^(.*)\/api2.cgi$/$1/; + my @resource_objects = map { { 'name' => $_, 'url' => $cgi_url.'/'.$_ } } sort @$resources; my $content = { version => 1, service => 'MG-RAST', url => $cgi->url, - documentation => $cgi->url.'/api.html', + documentation => $cgi_url.'/api.html', description => "RESTful Metagenomics RAST object and resource API\nFor usage note that required parameters need to be passed as path parameters, optional parameters need to be query parameters. If an optional parameter has a list of option values, the first displayed will be used as default.", contact => 'mg-rast@mcs.anl.gov', resources => \@resource_objects }; From 18614d019059a69d9f3e964dfad493f587b965dc Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Thu, 15 Aug 2013 13:06:27 -0500 Subject: [PATCH 2/3] Edited documentation generator script to accept a site name as a command line option. --- src/WebApplication/scripts/api2html.pl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/WebApplication/scripts/api2html.pl b/src/WebApplication/scripts/api2html.pl index 2e2e71bf..30cae982 100755 --- a/src/WebApplication/scripts/api2html.pl +++ b/src/WebApplication/scripts/api2html.pl @@ -12,17 +12,19 @@ sub usage { print "api2html.pl >>> create an HTML API documentation file from a REST API\n"; - print "api2html.pl -url -outfile \n"; + print "api2html.pl -url -site_name -outfile \n"; } # read in parameters -my $url = ''; -my $outfile = ''; +my $url = ''; +my $site_name = ''; +my $outfile = ''; GetOptions ( 'url=s' => \$url, + 'site_name=s' => \$site_name, 'outfile=s' => \$outfile ); -unless ($url and $outfile) { +unless ($url and $site_name and $outfile) { &usage(); exit 0; } @@ -58,7 +60,7 @@ sub usage { $structure->{resources} = $resources; # start the template -my $html = template_start(); +my $html = template_start($site_name); # build the navigation $html .= '
  • overview
  • '; @@ -70,7 +72,7 @@ sub usage {
    ~; -$html .= "

    ".$structure->{service}->{name}." Overview

    ".$structure->{service}->{description}."


    "; +$html .= "

    ".$site_name." Overview

    ".$structure->{service}->{description}."


    "; my %param_types = ( body => "

    This parameter must be passed in the message body.

    ", options => "

    This is an optional parameter and may be passed in the query string.

    ", @@ -113,6 +115,10 @@ sub usage { } } $html .= ""; + if (exists $req->{example}) { + $html .= "

    Example

      "; + $html .= "
    • ".$req->{example}[0]."
    • ".$req->{example}[1]."
    "; + } $html .= "

    Return Attributes

      "; # iterate over attributes foreach my $param (sort keys(%{$req->{attributes}})) { @@ -188,11 +194,12 @@ sub usage { exit; sub template_start { + my $site_name = shift; return qq~ - MG-RAST API + $site_name API @@ -202,7 +209,7 @@ sub template_start { From d0b7a72437780f6959a5847b94bc149650fcfa7c Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Thu, 15 Aug 2013 13:08:12 -0500 Subject: [PATCH 3/3] Edited Makefile to produce api documentation for MG-RAST and KBase on every make. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e620a7db..87f0f3a4 100644 --- a/Makefile +++ b/Makefile @@ -51,8 +51,9 @@ OVERRIDES = \ .PHONY: lib clean purge # if you change all: make sure all: in standard.mk is consistent. +# api-doc target must be run last. -all: installdirs $(TOOL_HDR) lib +all: installdirs $(TOOL_HDR) lib api-doc # Use the PACKAGES macro to transform lib, bin, etc., targets # into package level dependencies, e.g., lib -> PkgA.lib, PkgB.lib @@ -67,7 +68,8 @@ purge: rm -rf $(TARGET) bin/*.r api-doc: - perl src/WebApplication/scripts/api2html.pl -url http://api.metagenomics.anl.gov -outfile site/CGI/Html/api.html + perl src/WebApplication/scripts/api2html.pl -url http://api.metagenomics.anl.gov/beta -site_name "MG-RAST" -outfile site/CGI/Html/api.html + perl src/WebApplication/scripts/api2html.pl -url http://kbase.us/services/communities/beta -site_name "Microbial Communities" -outfile site/CGI/Html/api.kbase.html ## # Targets to setup the expected directory structure for the