2015-11-03 51 views
0

以下的NodeJS哈皮代码生成错误在http://localhost:3000/documentation扬鞭,高致病性禽流感:路径/模型产生错误

查询时如果我更改为/型号别的东西端点的路径,像/用户例如,一切运作良好。它看起来像保留了端点/模型

任何想法为什么任何其他端点的工作除了/模型?我该如何解决它?我无法更改网址,因为有太多人使用它。

var Hapi   = require('hapi'), 
    Inert   = require('inert'), 
    Vision   = require('vision'), 
    Joi    = require('joi'), 
    HapiSwagger  = require('hapi-swagger') 


var server = new Hapi.Server(); 
server.connection({ 
    host: 'localhost', 
    port: 3000 
}); 

var swaggerOptions = { 
    apiVersion: "1.0" 
}; 

server.register([ 
    Inert, 
    Vision, 
    { 
     register: HapiSwagger, 
     options: swaggerOptions 
    }], function (err) { 
    server.start(function(){ 
     // Add any server.route() config here 
     console.log('Server running at:', server.info.uri); 
    }); 
}); 

server.route(
    { 
     method: 'GET', 
     path: '/models', 
     config: { 
      handler: function (request, reply) { 
       reply("list of models") 
      }, 
      description: 'Get todo', 
      notes: 'Returns a todo item by the id passed in the path', 
      tags: ['api'], 
      validate: { 
       params: { 
        username: Joi.number() 
         .required() 
         .description('the id for the todo item') 
       } 
      } 
     } 
    } 
) 



server.start(function(){ 
    // Add any server.route() config here 
    console.log('Server running at:', server.info.uri); 
}); 

回答

2

models是招摇的内部结构的一部分,它看起来像使用模型作为URL为端点的部分终端处理时,有一个问题在swagger.js文件。

简单的解决方法是使用nickname。这会改变内部参考,但UI仍应该说models,它会正确地触发您的端点。

{ 
    method: 'GET', 
    path: '/models/{username}', 
    config: { 
     handler: function (request, reply) { 
      reply("list of models") 
     }, 
     description: 'Get todo', 
     notes: 'Returns a todo item by the id passed in the path', 
     tags: ['api'], 
     plugins: { 
      'hapi-swagger': { 
       nickname: 'modelsapi' 
      } 
      }, 
     validate: { 
      params: { 
       username: Joi.number() 
        .required() 
        .description('the id for the todo item') 
      } 
     } 
    } 
}