Skip to content

Commit

Permalink
Merge branch 'fix/issue-108'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharbonnier committed Jan 4, 2018
2 parents 0d337ab + 010ff38 commit e08f40c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ const register = async function (server, options, next) {

const spec = await Parser.validate(api);

spec.basePath = Utils.prefix(spec.basePath || '/', '/');

const basePath = Utils.unsuffix(spec.basePath, '/');
spec.basePath = Utils.unsuffix(Utils.prefix(spec.basePath || '/', '/'), '/');

//Expose plugin api
server.expose({
Expand Down Expand Up @@ -107,7 +105,7 @@ const register = async function (server, options, next) {
//API docs route
server.route({
method: 'GET',
path: basePath + docs.path,
path: spec.basePath + docs.path,
config: {
handler(request, h) {
return apiDocument;
Expand Down
2 changes: 1 addition & 1 deletion lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const create = function (options = {}) {
return this.parameter.type === 'file' ? result.value : result;
};

for (const parameter of operation.parameters) {
for (const parameter of operation.parameters || []) {
const validator = makeValidator(parameter, operation.consumes || options.api.consumes);

switch (validator.parameter.in) {
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/defs/minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test a very minimal schema (validating the specs)"
},
"paths": {
"/pets": {
"get": {
"responses": {
"200": {
"description": "default response"
}
}
}
}
}
}
27 changes: 27 additions & 0 deletions test/test-swaggerize-hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ Test('test plugin', function (t) {
}
});

t.test('minimal', async function (t) {
t.plan(1);

const server = new Hapi.Server();

try {
await server.register({
plugin: Swaggerize,
options: {
api: Path.join(__dirname, './fixtures/defs/minimal.json'),
handlers: Path.join(__dirname, './fixtures/handlers')
}
});

let response = await server.inject({
method: 'GET',
url: '/pets'
});

t.strictEqual(response.statusCode, 200, `${response.request.path} OK.`);

}
catch (error) {
t.fail(error.message);
}

});

t.test('routes', async function (t) {
t.plan(5);
Expand Down

0 comments on commit e08f40c

Please sign in to comment.