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

    var markdown = '';
    if (this.title) {
      markdown += '# ' + this.title + '\n\n';
    }
    if (this.description) {
      markdown += this.description + '\n\n';
    }

    // Export own request handlers.
    for (var method in this.handlers) {
      var handler = this.handlers[method];
      markdown += '## ' + (handler.title || '(no title)') + '\n\n';
      markdown += '    ' + method.toUpperCase() + ' ' + fullPath + '\n\n';
      if (handler.description) {
        markdown += handler.description + '\n\n';
      }

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

        var request = example.request || {};
        if (request.urlParameters || request.headers || request.body) {
          markdown += '### Example input:\n\n';
          var exampleURL = '    ' + method.toUpperCase() + ' ' + fullPath;
          if (request.urlParameters) {
            exampleURL = replaceUrlParameters(exampleURL,
              request.urlParameters);
          }
          markdown += exampleURL + '\n';
          var requestHeaders = request.headers || {};
          for (var header in requestHeaders) {
            markdown += '    ' + header + ': ' + requestHeaders[header] + '\n';
          }
          if (request.body) {
            var requestBody = '    ' + jsonStringifyIfObject(request.body)
              .trim().replace(/\n/g, '\n    ');
            markdown += '    \n' + requestBody + '\n';
          }
          markdown += '\n';
        }

        var response = example.response || {};
        var hasResponseStatus = isExplicitExample(response.status);
        var hasResponseBody = isExplicitExample(response.body);
        if (hasResponseStatus || response.headers || hasResponseBody) {
          markdown += '### Example response:\n\n';
          if (hasResponseStatus) {
            var message = http.STATUS_CODES[response.status];
            markdown += '    Status: ' + response.status + ' ' + message + '\n';
          }
          var responseHeaders = response.headers || {};
          for (var header in responseHeaders) {
            var value = responseHeaders[header];
            if (isExplicitExample(value)) {
              markdown += '    ' + header + ': ' + value + '\n';
            }
          }
          if (hasResponseBody) {
            if (hasResponseStatus || Object.keys(responseHeaders).length > 0) {
              markdown += '    \n';
            }
            markdown += '    ' + jsonStringifyIfObject(response.body).trim()
              .replace(/\n/g, '\n    ') + '\n';
          }
          markdown += '\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];
      markdown += child.toMarkdown(fullPath);
    }

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

    var markdown = '';
    if (this.title) {
      markdown += '# ' + this.title + '\n\n';
    }
    if (this.description) {
      markdown += this.description + '\n\n';
    }

    // Export own request handlers.
    for (var method in this.handlers) {
      var handler = this.handlers[method];
      markdown += '## ' + (handler.title || '(no title)') + '\n\n';
      markdown += '    ' + method.toUpperCase() + ' ' + fullPath + '\n\n';
      if (handler.description) {
        markdown += handler.description + '\n\n';
      }

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

        var request = example.request || {};
        if (request.urlParameters || request.headers || request.body) {
          markdown += '### Example input:\n\n';
          var exampleURL = '    ' + method.toUpperCase() + ' ' + fullPath;
          if (request.urlParameters) {
            exampleURL = replaceUrlParameters(exampleURL,
              request.urlParameters);
          }
          markdown += exampleURL + '\n';
          var requestHeaders = request.headers || {};
          for (var header in requestHeaders) {
            markdown += '    ' + header + ': ' + requestHeaders[header] + '\n';
          }
          if (request.body) {
            var requestBody = '    ' + jsonStringifyIfObject(request.body)
              .trim().replace(/\n/g, '\n    ');
            markdown += '    \n' + requestBody + '\n';
          }
          markdown += '\n';
        }

        var response = example.response || {};
        var hasResponseStatus = isExplicitExample(response.status);
        var hasResponseBody = isExplicitExample(response.body);
        if (hasResponseStatus || response.headers || hasResponseBody) {
          markdown += '### Example response:\n\n';
          if (hasResponseStatus) {
            var message = http.STATUS_CODES[response.status];
            markdown += '    Status: ' + response.status + ' ' + message + '\n';
          }
          var responseHeaders = response.headers || {};
          for (var header in responseHeaders) {
            var value = responseHeaders[header];
            if (isExplicitExample(value)) {
              markdown += '    ' + header + ': ' + value + '\n';
            }
          }
          if (hasResponseBody) {
            if (hasResponseStatus || Object.keys(responseHeaders).length > 0) {
              markdown += '    \n';
            }
            markdown += '    ' + jsonStringifyIfObject(response.body).trim()
              .replace(/\n/g, '\n    ') + '\n';
          }
          markdown += '\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];
      markdown += child.toMarkdown(fullPath);
    }

    return markdown;
  }
function ( basePath ) { var fullPath = normalizePath ( this . path , basePath ) || '/' ; var markdown = '' ; if ( this . title ) { markdown += '# ' + this . title + '\n\n' ; } if ( this . description ) { markdown += this . description + '\n\n' ; } // Export own request handlers. for ( var method in this . handlers ) { var handler = this . handlers [ method ] ; markdown += '## ' + ( handler . title || '(no title)' ) + '\n\n' ; markdown += '    ' + method . toUpperCase ( ) + ' ' + fullPath + '\n\n' ; if ( handler . description ) { markdown += handler . description + '\n\n' ; } if ( handler . examples && handler . examples . length > 0 ) { var example = handler . examples [ 0 ] ; var request = example . request || { } ; if ( request . urlParameters || request . headers || request . body ) { markdown += '### Example input:\n\n' ; var exampleURL = '    ' + method . toUpperCase ( ) + ' ' + fullPath ; if ( request . urlParameters ) { exampleURL = replaceUrlParameters ( exampleURL , request . urlParameters ) ; } markdown += exampleURL + '\n' ; var requestHeaders = request . headers || { } ; for ( var header in requestHeaders ) { markdown += '    ' + header + ': ' + requestHeaders [ header ] + '\n' ; } if ( request . body ) { var requestBody = '    ' + jsonStringifyIfObject ( request . body ) . trim ( ) . replace ( / \n / g , '\n    ' ) ; markdown += '    \n' + requestBody + '\n' ; } markdown += '\n' ; } var response = example . response || { } ; var hasResponseStatus = isExplicitExample ( response . status ) ; var hasResponseBody = isExplicitExample ( response . body ) ; if ( hasResponseStatus || response . headers || hasResponseBody ) { markdown += '### Example response:\n\n' ; if ( hasResponseStatus ) { var message = http . STATUS_CODES [ response . status ] ; markdown += '    Status: ' + response . status + ' ' + message + '\n' ; } var responseHeaders = response . headers || { } ; for ( var header in responseHeaders ) { var value = responseHeaders [ header ] ; if ( isExplicitExample ( value ) ) { markdown += '    ' + header + ': ' + value + '\n' ; } } if ( hasResponseBody ) { if ( hasResponseStatus || Object . keys ( responseHeaders ) . length > 0 ) { markdown += '    \n' ; } markdown += '    ' + jsonStringifyIfObject ( response . body ) . trim ( ) . replace ( / \n / g , '\n    ' ) + '\n' ; } markdown += '\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 ] ; markdown += child . toMarkdown ( fullPath ) ; } return markdown ; }
Export API documentation as Markdown.
Export API documentation as Markdown .