selfapi.js
function (basePath, anchors) {
    var fullPath = normalizePath(this.path, basePath) || '/';

    anchors = anchors || [];
    function getAnchor (title) {
      var anchor = String(title).toLowerCase()
        .replace(/[\s\-]+/g, ' ')
        .replace(/[^a-z0-9 ]/g, '')
        .trim()
        .replace(/ /g, '-');
      if (anchors.indexOf(anchor) > -1) {
        var i = 2;
        while (anchors.indexOf(anchor + '-' + i) > -1) {
          i++;
        }
        anchor += '-' + i;
      }
      anchors.push(anchor);
      return anchor;
    }

    var html = '';
    if (this.title) {
      html +=
        '<h1 id="' + getAnchor(this.title) + '">' + this.title + '</h1>\n';
    }
    if (this.description) {
      html += '<p>' + this.description.replace(/\n/g, '<br>') + '</p>\n';
    }

    // Export own request handlers.
    for (var method in this.handlers) {
      var handler = this.handlers[method];
      var title = handler.title || '(no title)';
      html += '<h2 id="' + getAnchor(title) + '">' + title + '</h2>\n';
      html += '<pre>' + method.toUpperCase() + ' ' + fullPath + '</pre>\n';
      if (handler.description) {
        html += '<p>' + handler.description.replace(/\n/g, '<br>') + '</p>\n';
      }

      if (handler.examples && handler.examples.length > 0) {
        var example = handler.examples[0];

        var request = example.request || {};
        if (request.urlParameters || request.headers || request.body) {
          html += '<h3>Input</h3>\n<pre>';
          var exampleURL = method.toUpperCase() + ' ' + fullPath;
          if (request.urlParameters) {
            exampleURL = replaceUrlParameters(exampleURL,
              request.urlParameters);
          }
          html += exampleURL + '\n';
          var requestHeaders = request.headers || {};
          for (var header in requestHeaders) {
            html += header + ': ' + requestHeaders[header] + '\n';
          }
          if (request.body) {
            html += '\n' + jsonStringifyIfObject(request.body).trim() + '\n';
          }
          html += '</pre>\n';
        }

        var response = example.response || {};
        var hasResponseStatus = isExplicitExample(response.status);
        var hasResponseBody = isExplicitExample(response.body);
        if (hasResponseStatus || response.headers || hasResponseBody) {
          html += '<h3>Response</h3>\n<pre>';
          if (hasResponseStatus) {
            var message = http.STATUS_CODES[response.status];
            html += 'Status: ' + response.status + ' ' + message + '\n';
          }
          var responseHeaders = response.headers || {};
          for (var header in responseHeaders) {
            var headerValue = responseHeaders[header];
            if (isExplicitExample(headerValue)) {
              html += header + ': ' + headerValue + '\n';
            }
          }
          if (hasResponseBody) {
            if (hasResponseStatus || Object.keys(responseHeaders).length > 0) {
              html += '\n';
            }
            html += jsonStringifyIfObject(response.body).trim() + '\n';
          }
          html += '</pre>\n';
        }
        // TODO Document all unique possible status codes?
        // TODO Document all request parameters?
      }
    }

    // Export children's request handlers recursively.
    for (var path in this.children) {
      var child = this.children[path];
      html += child.toHTML(fullPath, anchors);
    }

    return html;
  }
function (basePath, anchors) {
    var fullPath = normalizePath(this.path, basePath) || '/';

    anchors = anchors || [];
    function getAnchor (title) {
      var anchor = String(title).toLowerCase()
        .replace(/[\s\-]+/g, ' ')
        .replace(/[^a-z0-9 ]/g, '')
        .trim()
        .replace(/ /g, '-');
      if (anchors.indexOf(anchor) > -1) {
        var i = 2;
        while (anchors.indexOf(anchor + '-' + i) > -1) {
          i++;
        }
        anchor += '-' + i;
      }
      anchors.push(anchor);
      return anchor;
    }

    var html = '';
    if (this.title) {
      html +=
        '<h1 id="' + getAnchor(this.title) + '">' + this.title + '</h1>\n';
    }
    if (this.description) {
      html += '<p>' + this.description.replace(/\n/g, '<br>') + '</p>\n';
    }

    // Export own request handlers.
    for (var method in this.handlers) {
      var handler = this.handlers[method];
      var title = handler.title || '(no title)';
      html += '<h2 id="' + getAnchor(title) + '">' + title + '</h2>\n';
      html += '<pre>' + method.toUpperCase() + ' ' + fullPath + '</pre>\n';
      if (handler.description) {
        html += '<p>' + handler.description.replace(/\n/g, '<br>') + '</p>\n';
      }

      if (handler.examples && handler.examples.length > 0) {
        var example = handler.examples[0];

        var request = example.request || {};
        if (request.urlParameters || request.headers || request.body) {
          html += '<h3>Input</h3>\n<pre>';
          var exampleURL = method.toUpperCase() + ' ' + fullPath;
          if (request.urlParameters) {
            exampleURL = replaceUrlParameters(exampleURL,
              request.urlParameters);
          }
          html += exampleURL + '\n';
          var requestHeaders = request.headers || {};
          for (var header in requestHeaders) {
            html += header + ': ' + requestHeaders[header] + '\n';
          }
          if (request.body) {
            html += '\n' + jsonStringifyIfObject(request.body).trim() + '\n';
          }
          html += '</pre>\n';
        }

        var response = example.response || {};
        var hasResponseStatus = isExplicitExample(response.status);
        var hasResponseBody = isExplicitExample(response.body);
        if (hasResponseStatus || response.headers || hasResponseBody) {
          html += '<h3>Response</h3>\n<pre>';
          if (hasResponseStatus) {
            var message = http.STATUS_CODES[response.status];
            html += 'Status: ' + response.status + ' ' + message + '\n';
          }
          var responseHeaders = response.headers || {};
          for (var header in responseHeaders) {
            var headerValue = responseHeaders[header];
            if (isExplicitExample(headerValue)) {
              html += header + ': ' + headerValue + '\n';
            }
          }
          if (hasResponseBody) {
            if (hasResponseStatus || Object.keys(responseHeaders).length > 0) {
              html += '\n';
            }
            html += jsonStringifyIfObject(response.body).trim() + '\n';
          }
          html += '</pre>\n';
        }
        // TODO Document all unique possible status codes?
        // TODO Document all request parameters?
      }
    }

    // Export children's request handlers recursively.
    for (var path in this.children) {
      var child = this.children[path];
      html += child.toHTML(fullPath, anchors);
    }

    return html;
  }
function ( basePath , anchors ) { var fullPath = normalizePath ( this . path , basePath ) || '/' ; anchors = anchors || [ ] ; function getAnchor ( title ) { var anchor = String ( title ) . toLowerCase ( ) . replace ( / [\s\-]+ / g , ' ' ) . replace ( / [^a-z0-9 ] / g , '' ) . trim ( ) . replace ( / / g , '-' ) ; if ( anchors . indexOf ( anchor ) > - 1 ) { var i = 2 ; while ( anchors . indexOf ( anchor + '-' + i ) > - 1 ) { i ++ ; } anchor += '-' + i ; } anchors . push ( anchor ) ; return anchor ; } var html = '' ; if ( this . title ) { html += '<h1 id="' + getAnchor ( this . title ) + '">' + this . title + '</h1>\n' ; } if ( this . description ) { html += '<p>' + this . description . replace ( / \n / g , '<br>' ) + '</p>\n' ; } // Export own request handlers. for ( var method in this . handlers ) { var handler = this . handlers [ method ] ; var title = handler . title || '(no title)' ; html += '<h2 id="' + getAnchor ( title ) + '">' + title + '</h2>\n' ; html += '<pre>' + method . toUpperCase ( ) + ' ' + fullPath + '</pre>\n' ; if ( handler . description ) { html += '<p>' + handler . description . replace ( / \n / g , '<br>' ) + '</p>\n' ; } if ( handler . examples && handler . examples . length > 0 ) { var example = handler . examples [ 0 ] ; var request = example . request || { } ; if ( request . urlParameters || request . headers || request . body ) { html += '<h3>Input</h3>\n<pre>' ; var exampleURL = method . toUpperCase ( ) + ' ' + fullPath ; if ( request . urlParameters ) { exampleURL = replaceUrlParameters ( exampleURL , request . urlParameters ) ; } html += exampleURL + '\n' ; var requestHeaders = request . headers || { } ; for ( var header in requestHeaders ) { html += header + ': ' + requestHeaders [ header ] + '\n' ; } if ( request . body ) { html += '\n' + jsonStringifyIfObject ( request . body ) . trim ( ) + '\n' ; } html += '</pre>\n' ; } var response = example . response || { } ; var hasResponseStatus = isExplicitExample ( response . status ) ; var hasResponseBody = isExplicitExample ( response . body ) ; if ( hasResponseStatus || response . headers || hasResponseBody ) { html += '<h3>Response</h3>\n<pre>' ; if ( hasResponseStatus ) { var message = http . STATUS_CODES [ response . status ] ; html += 'Status: ' + response . status + ' ' + message + '\n' ; } var responseHeaders = response . headers || { } ; for ( var header in responseHeaders ) { var headerValue = responseHeaders [ header ] ; if ( isExplicitExample ( headerValue ) ) { html += header + ': ' + headerValue + '\n' ; } } if ( hasResponseBody ) { if ( hasResponseStatus || Object . keys ( responseHeaders ) . length > 0 ) { html += '\n' ; } html += jsonStringifyIfObject ( response . body ) . trim ( ) + '\n' ; } html += '</pre>\n' ; } // TODO Document all unique possible status codes? // TODO Document all request parameters? } } // Export children's request handlers recursively. for ( var path in this . children ) { var child = this . children [ path ] ; html += child . toHTML ( fullPath , anchors ) ; } return html ; }
Export API documentation as HTML.
Export API documentation as HTML .