lib/index.js
function createMiddleware(router, validator) {
  /**
   * Checks request and response against a swagger spec
   * Uses the usual koa context attributes
   * Uses the koa-bodyparser context attribute
   * Sets a new context attribute: {object} parameter
   */
  return function* middleware(next) {
    // Routing matches
    try {
      var routeMatch = match.path(router, this.path);
    } catch(e) {
      // TODO: let an option before doing that, strict mode throws the error
      yield next;
      return false;
    }
    this.pathParam = routeMatch.param; // Add the path's params to the context
    var methodDef = match.method(routeMatch.def, this.method);


    // Parameters check & assign
    this.parameter = check.parameters(validator,
      methodDef.parameters || [], this);

    // Let the implementation happen
    yield next;

    // Response check
    var statusDef = match.status(methodDef.responses || {}, this.status);
    check.sentHeaders(validator, statusDef.headers || {}, this.sentHeaders);
    if(statusDef.schema) {
      check.body(validator, statusDef.schema, yield this.body);
    }
  };
}
function createMiddleware(router, validator) {
  /**
   * Checks request and response against a swagger spec
   * Uses the usual koa context attributes
   * Uses the koa-bodyparser context attribute
   * Sets a new context attribute: {object} parameter
   */
  return function* middleware(next) {
    // Routing matches
    try {
      var routeMatch = match.path(router, this.path);
    } catch(e) {
      // TODO: let an option before doing that, strict mode throws the error
      yield next;
      return false;
    }
    this.pathParam = routeMatch.param; // Add the path's params to the context
    var methodDef = match.method(routeMatch.def, this.method);


    // Parameters check & assign
    this.parameter = check.parameters(validator,
      methodDef.parameters || [], this);

    // Let the implementation happen
    yield next;

    // Response check
    var statusDef = match.status(methodDef.responses || {}, this.status);
    check.sentHeaders(validator, statusDef.headers || {}, this.sentHeaders);
    if(statusDef.schema) {
      check.body(validator, statusDef.schema, yield this.body);
    }
  };
}
function createMiddleware ( router , validator ) { /**
   * Checks request and response against a swagger spec
   * Uses the usual koa context attributes
   * Uses the koa-bodyparser context attribute
   * Sets a new context attribute: {object} parameter
   */ return function * middleware ( next ) { // Routing matches try { var routeMatch = match . path ( router , this . path ) ; } catch ( e ) { // TODO: let an option before doing that, strict mode throws the error yield next ; return false ; } this . pathParam = routeMatch . param ; // Add the path's params to the context var methodDef = match . method ( routeMatch . def , this . method ) ; // Parameters check & assign this . parameter = check . parameters ( validator , methodDef . parameters || [ ] , this ) ; // Let the implementation happen yield next ; // Response check var statusDef = match . status ( methodDef . responses || { } , this . status ) ; check . sentHeaders ( validator , statusDef . headers || { } , this . sentHeaders ) ; if ( statusDef . schema ) { check . body ( validator , statusDef . schema , yield this . body ) ; } } ; }
Creates the generator from the swagger router & validator
@param router {routington} A swagger definition
@param validator {function(object, Schema)} JSON-Schema validator function
@returns {function*} The created middleware
Creates the generator from the swagger router & validator