Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies to support hapi 19 #173

Merged
merged 9 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# hapi-openapi

[![Build Status](https://travis-ci.org/krakenjs/hapi-openapi.svg?branch=master)](https://travis-ci.org/krakenjs/hapi-openapi)
[![NPM version](https://badge.fury.io/js/hapi-openapi.png)](http://badge.fury.io/js/hapi-openapi)
[![Build Status](https://travis-ci.org/krakenjs/hapi-openapi.svg?branch=master)](https://travis-ci.org/krakenjs/hapi-openapi)
[![NPM version](https://badge.fury.io/js/hapi-openapi.png)](http://badge.fury.io/js/hapi-openapi)

### Note: this project was renamed from 'swaggerize-hapi' to 'hapi-openapi'.

Expand Down Expand Up @@ -49,7 +49,7 @@ You now have a working api and can use something like [SwaggerHub](https://swagg
### Manual Usage

```javascript
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');

const server = new Hapi.Server();

Expand Down Expand Up @@ -194,7 +194,7 @@ This will construct a `handlers` object from the given `x-hapi-handler` files.

### X-Hapi-Options

There is now support at the operations level for `x-hapi-options` which represent individual [Hapi Route Optijons](https://github.com/hapijs/hapi/blob/master/API.md#route-options).
There is now support at the operations level for `x-hapi-options` which represent individual [Hapi Route Optijons](https://github.com/hapijs/hapi/blob/master/API.md#route-options).

This support is limited to configuration supported by the JSON file type.

Expand Down Expand Up @@ -321,7 +321,7 @@ and
```javascript
//xauth-strategy.js

const Boom = require('boom');
const Boom = require('@hapi/boom');

const register = function (server, { name, scheme, where, lookup }) {
server.auth.strategy(name, /* the scheme to use this strategy with */ scheme, {
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const Package = require('../package.json');
const Joi = require('joi');
const Hoek = require('hoek');
const Joi = require('@hapi/joi');
const Hoek = require('@hapi/hoek');
const Caller = require('./caller');
const Path = require('path');
const Parser = require('swagger-parser');
Expand Down Expand Up @@ -164,7 +164,7 @@ const register = async function (server, options, next) {
},
vhost
});

const routes = await Routes.create(server, { api: spec, basedir, cors, vhost, handlers, extensions, outputvalidation });

for (const route of routes) {
Expand Down
7 changes: 1 addition & 6 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const ObjectFiles = require('merge-object-files');
const Validators = require('./validators');
const Hoek = require('hoek');
const Hoek = require('@hapi/hoek');
const Utils = require('./utils');
const Path = require('path');
const Props = require('dot-prop');
Expand Down Expand Up @@ -94,11 +94,6 @@ const create = async function (server, { api, basedir, cors, vhost, handlers, ex
const securitySchemes = Object.keys(secdef);

for (const securityDefinitionName of securitySchemes) {
if (!server.auth._strategies[securityDefinitionName]) {
server.log(['warn'], `${securityDefinitionName} strategy was not registered.`);
continue;
}

const securityDefinition = api.securityDefinitions[securityDefinitionName];

Hoek.assert(securityDefinition, 'Security scheme not defined.');
Expand Down
10 changes: 8 additions & 2 deletions lib/validators.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Enjoi = require('enjoi');
const Joi = require('joi');
const Joi = require('@hapi/joi');
const Util = require('util');

const types = {
Expand Down Expand Up @@ -140,7 +140,7 @@ const create = function (options = {}) {

const formValidator = async function (value) {
const result = await this.validate(value);

if (result.error) {
throw result.error;
}
Expand Down Expand Up @@ -193,6 +193,12 @@ const create = function (options = {}) {
}
}

for (const [key, value] of Object.entries(validate)) {
if (typeof value === 'object' && !value.isJoi) {
validate[key] = Joi.object(value);
}
}

return {
validate,
routeExt
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"node": ">=8"
},
"dependencies": {
"@hapi/hoek": "^9.0.4",
"@hapi/joi": "^14.5.0",
"dot-prop": "^4.2.0",
"enjoi": "^4.0.0",
"hoek": "^5.0.3",
"joi": "^13.6.0",
"enjoi": "^6.0.1",
"js-yaml": "^3.11.0",
"merge-object-files": "^2.0.0",
"swagger-parser": "^4.1.0"
"swagger-parser": "^9.0.1"
},
"devDependencies": {
"boom": "^7.2.0",
"@hapi/boom": "^9.1.0",
"@hapi/hapi": "^19.1.1",
"eslint": "^4.19.1",
"eslint-config-hapi": "^11.1.0",
"eslint-plugin-hapi": "^4.1.0",
"hapi": "^17.4.0",
"nyc": "^13.3.0",
"nyc": "^15.0.0",
"tape": "^4.9.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/lib/stub-auth-token-scheme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Boom = require('boom');
var Boom = require('@hapi/boom');

const register = function (server, options) {
server.auth.scheme('stub-auth-token', function (server, options) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/lib/xauth-scheme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Boom = require('boom');
var Boom = require('@hapi/boom');

const register = function (server, { name }) {
server.auth.scheme(name /*apiKey*/, (server, { validate }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/lib/xauth-strategy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Boom = require('boom');
const Boom = require('@hapi/boom');

const register = function (server, { name, scheme, where, lookup }) {
server.auth.strategy(name, scheme, {
Expand Down
10 changes: 9 additions & 1 deletion test/test-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Test = require('tape');
const Path = require('path');
const OpenAPI = require('../lib');
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');
const StubAuthTokenScheme = require('./fixtures/lib/stub-auth-token-scheme');

Test('authentication', function (t) {
Expand Down Expand Up @@ -80,6 +80,10 @@ Test('authentication', function (t) {
}
});

server.auth.strategy('api_key2', 'stub-auth-token', {
validateFunc: () => ({ isValid: true })
});

await server.register({
plugin: OpenAPI,
options: {
Expand Down Expand Up @@ -117,6 +121,10 @@ Test('authentication', function (t) {
}
});

server.auth.strategy('api_key2', 'stub-auth-token', {
validateFunc: () => ({ isValid: true })
});

await server.register({
plugin: OpenAPI,
options: {
Expand Down
2 changes: 1 addition & 1 deletion test/test-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Test = require('tape');
const Path = require('path');
const OpenAPI = require('../lib');
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');


Test('form data', function (t) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-hapi-openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Test = require('tape');
const Path = require('path');
const OpenAPI = require('../lib');
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');

Test('test plugin', function (t) {

Expand Down
2 changes: 1 addition & 1 deletion test/test-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Test('validator special types', function(t) {

const v = validator.makeAll(api.paths['/test/{foo*}'].get.parameters);

const keys = Object.keys(v.validate.params);
const keys = Object.keys(v.validate.params.describe().children);

if (keys.length === 1 && keys[0] === 'foo') {
return t.pass(`${keys.join(', ')} are valid.`);
Expand Down
2 changes: 1 addition & 1 deletion test/test_xoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Test = require('tape');
const Path = require('path');
const OpenAPI = require('../lib');
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');


Test('x-hapi-options', function (t) {
Expand Down