{"action":"opened","issue":{"url":"https://api.github.com/repos/glennjones/hapi-swagger/issues/322","repository_url":"https://api.github.com/repos/glennjones/hapi-swagger","labels_url":"https://api.github.com/repos/glennjones/hapi-swagger/issues/322/labels{/name}","comments_url":"https://api.github.com/repos/glennjones/hapi-swagger/issues/322/comments","events_url":"https://api.github.com/repos/glennjones/hapi-swagger/issues/322/events","html_url":"https://github.com/glennjones/hapi-swagger/issues/322","id":171881855,"number":322,"title":"Internal Server Error with Joi extension","user":{"login":"ns3777k","id":4613880,"avatar_url":"https://avatars.githubusercontent.com/u/4613880?v=3","gravatar_id":"","url":"https://api.github.com/users/ns3777k","html_url":"https://github.com/ns3777k","followers_url":"https://api.github.com/users/ns3777k/followers","following_url":"https://api.github.com/users/ns3777k/following{/other_user}","gists_url":"https://api.github.com/users/ns3777k/gists{/gist_id}","starred_url":"https://api.github.com/users/ns3777k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ns3777k/subscriptions","organizations_url":"https://api.github.com/users/ns3777k/orgs","repos_url":"https://api.github.com/users/ns3777k/repos","events_url":"https://api.github.com/users/ns3777k/events{/privacy}","received_events_url":"https://api.github.com/users/ns3777k/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-18T11:44:47Z","updated_at":"2016-08-18T11:44:47Z","closed_at":null,"body":"Hey.\r\n\r\nJoi allows you to develop an extension, so I made a simple one - https://github.com/Dalee/joi-extension-msisdn/blob/master/src/index.js.\r\n\r\nAs you can see, its type is `msisdn`. So I made use of it in `hapi route`:\r\n\r\n```js\r\n{\r\n        method: 'GET',\r\n        path: '/info',\r\n        handler: info,\r\n        config: {\r\n            validate: {\r\n                query: Joi.object({\r\n                    msisdn: Joi.extend(JoiMsisdnExt).msisdn().valid()\r\n                })\r\n            },\r\n            description: 'Msisdn info route',\r\n            tags: ['api']\r\n        }\r\n    }\r\n```\r\n\r\nEverything works fine except `hapi-swagger` :smile: \r\nIt goes down with the following error in console:\r\n\r\n```bash\r\nDebug: internal, implementation, error \r\n    TypeError: Uncaught error: Cannot read property 'type' of undefined\r\n    at Object.properties.parseProperty (/home/web/project/node_modules/hapi-swagger/lib/properties.js:149:24)\r\n    at joiObj.forEach (/home/web/project/node_modules/hapi-swagger/lib/properties.js:92:46)\r\n    at Array.forEach (native)\r\n    at Object.properties.parseProperties (/home/web/project/node_modules/hapi-swagger/lib/properties.js:81:16)\r\n    at Object.properties.toParameters (/home/web/project/node_modules/hapi-swagger/lib/properties.js:39:36)\r\n    at routes.forEach (/home/web/project/node_modules/hapi-swagger/lib/paths.js:272:24)\r\n    at Array.forEach (native)\r\n    at Object.paths.properties (/home/web/project/node_modules/hapi-swagger/lib/paths.js:158:12)\r\n    at Object.paths.build (/home/web/project/node_modules/hapi-swagger/lib/paths.js:139:18)\r\n    at Object.builder.getSwaggerJSON (/home/web/project/node_modules/hapi-swagger/lib/builder.js:104:26)\r\n    at plugin.route.config.handler (/home/web/project/node_modules/hapi-swagger/lib/index.js:129:29)\r\n    at Object.internals.handler (/home/web/project/node_modules/hapi/lib/handler.js:96:36)\r\n    at request._protect.run (/home/web/project/node_modules/hapi/lib/handler.js:30:23)\r\n    at internals.Protect.run (/home/web/project/node_modules/hapi/lib/protect.js:64:5)\r\n    at exports.execute (/home/web/project/node_modules/hapi/lib/handler.js:24:22)\r\n    at each (/home/web/project/node_modules/hapi/lib/request.js:383:16)\r\n160818/111643.128, [response] http://mnp:3000: get /swagger.json {} 500 (67ms)\r\n```\r\n\r\nThe problem seems to be in `lib/properties.js:145` when it tries to get the joi type and find it in the map:\r\n\r\n```js\r\nlet joiType = joiObj._type.toLowerCase();\r\n    let map = internals.propertyMap[ joiType ];\r\n    property.type = map.type;\r\n    if ( map.format ){\r\n        property.format = map.format;\r\n    }\r\n```\r\n\r\nThe type is `msisdn` which is obviously not in the map.\r\n\r\nI think the very right way to fix this is to use `base type` when `type` is not in the map. But I didn't find a way to get `base type`. Probably I should create an issue in `Joi`.\r\n\r\nWhat you think?\r\n\r\nI use Joi 9 and Hapi 14."}}
{"actor":{"display_login":"ns3777k"}}