Skip to content

Commit

Permalink
Merge pull request #767 from hapi-swagger/fix-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcguinness committed Jun 12, 2022
2 parents 6427bc7 + c7512f8 commit df315ac
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 261 deletions.
4 changes: 2 additions & 2 deletions examples/assets/routes-complex.js
Expand Up @@ -471,7 +471,7 @@ module.exports = [
}
},
tags: ['api', 'reduced', 'three'],
validate: Joi.object({
validate: {
payload: Joi.object({
a: Joi.number().required().description('the first number'),
b: Joi.number().required().description('the second number'),
Expand All @@ -489,7 +489,7 @@ module.exports = [
.valid('application/json', 'application/vnd.api+json')
.default('application/vnd.api+json')
}).unknown()
})
}
}
},
{
Expand Down
33 changes: 1 addition & 32 deletions examples/custom.js
Expand Up @@ -6,38 +6,11 @@ const Blipp = require('blipp');
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const Good = require('@hapi/good');

const HapiSwagger = require('../');
const Pack = require('../package');
const Routes = require('./assets/routes-simple');

const goodOptions = {
ops: {
interval: 1000
},
reporters: {
myConsoleReporter: [
{
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [
{
log: '*',
response: {
exclude: ['no-logging']
}
}
]
},
{
module: 'good-console'
},
'stdout'
]
}
};

const swaggerOptions = {
documentationPage: false,
documentationRouteTags: 'no-logging',
Expand Down Expand Up @@ -93,15 +66,11 @@ const ser = async () => {
port: 3000
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Blipp,
{
plugin: Good,
options: goodOptions
},
{
plugin: HapiSwagger,
options: swaggerOptions
Expand Down
2 changes: 1 addition & 1 deletion examples/debug.js
Expand Up @@ -32,7 +32,7 @@ const ser = async () => {
port: 3000
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
2 changes: 1 addition & 1 deletion examples/extend.js
Expand Up @@ -25,7 +25,7 @@ const ser = async () => {
port: 3000
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
2 changes: 1 addition & 1 deletion examples/group-ordered.js
Expand Up @@ -126,7 +126,7 @@ const ser = async () => {
port: 3000
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
2 changes: 1 addition & 1 deletion examples/http2.js
Expand Up @@ -79,7 +79,7 @@ const ser = async () => {
tls
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
28 changes: 1 addition & 27 deletions examples/options.js
Expand Up @@ -12,32 +12,6 @@ const HapiSwagger = require('../');
const Pack = require('../package');
const Routes = require('./assets/routes-complex.js');

/*
const goodOptions = {
ops: {
interval: 1000
},
reporters: {
console: [
{
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [
{
log: '*',
response: '*'
}
]
},
{
module: 'good-console'
},
'stdout'
]
}
};
*/

const swaggerOptions = {
basePath: '/v1',
pathPrefixSize: 2,
Expand Down Expand Up @@ -121,7 +95,7 @@ const ser = async () => {
}
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
2 changes: 1 addition & 1 deletion examples/ssl.js
Expand Up @@ -66,7 +66,7 @@ const ser = async () => {
}
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
22 changes: 10 additions & 12 deletions examples/swagger-client.js
Expand Up @@ -52,11 +52,10 @@ const routes = [
}
},
validate: {
params: {
params: Joi.object({
a: Joi.number().required().description('the first number'),

b: Joi.number().required().description('the second number')
}
})
}
}
},
Expand All @@ -73,11 +72,10 @@ const routes = [
}
},
validate: {
params: {
params: Joi.object({
a: Joi.number().required().description('the first number'),

b: Joi.number().required().description('the second number')
}
})
}
}
},
Expand All @@ -89,11 +87,10 @@ const routes = [
description: 'Add',
tags: ['api'],
validate: {
params: {
params: Joi.object({
a: Joi.number().required().description('the first number'),

b: Joi.number().required().description('the second number')
}
})
}
}
}
Expand Down Expand Up @@ -155,9 +152,9 @@ ser()
console.error(error);
});

client
.execute({
operationId: 'add',
client.execute({
pathName: '/math/add/{a}/{b}',
method: 'put',
parameters: { a: 9, b: 9 }
})
.then((data) => {
Expand All @@ -166,6 +163,7 @@ ser()
.catch((error) => {
console.error(error);
});

});
})
.catch((err) => {
Expand Down
6 changes: 3 additions & 3 deletions examples/upload-file.js
Expand Up @@ -77,9 +77,9 @@ const routes = [
},
tags: ['api'],
validate: {
payload: {
payload: Joi.object({
file: Joi.any().meta({ swaggerType: 'file' }).description('json file')
}
})
},
payload: {
maxBytes: 1048576,
Expand All @@ -96,7 +96,7 @@ const ser = async () => {
port: 3000
});

// Blipp and Good - Needs updating for Hapi v17.x
// Blipp - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Expand Down
28 changes: 0 additions & 28 deletions examples/versions.js
Expand Up @@ -29,30 +29,6 @@ const options = {
defaultVersion: 2
};
const goodOptions = {
ops: {
interval: 1000
},
reporters: {
console: [
{
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [
{
log: '*',
response: '*'
}
]
},
{
module: 'good-console'
},
'stdout'
]
}
};
const versionOptions = {
basePath: options.basePath,
validVersions: options.validVersions,
Expand Down Expand Up @@ -83,10 +59,6 @@ server.register(
Inert,
Vision,
Blipp,
{
plugin: require('good'),
options: goodOptions
},
{
plugin: HapiSwagger,
options: swaggerOptions
Expand Down
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -62,8 +62,6 @@
"@hapi/basic": "^6.0.0",
"@hapi/code": "^8.0.7",
"@hapi/eslint-plugin": "^5.1.0",
"@hapi/good": "^9.0.1",
"@hapi/good-console": "^9.0.1",
"@hapi/h2o2": "^9.0.2",
"@hapi/hapi": "^20.2.2",
"@hapi/inert": "^6.0.1",
Expand All @@ -75,7 +73,6 @@
"coveralls": "^3.0.2",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"good-squeeze": "^5.0.2",
"hapi-api-version": "^2.1.0",
"hapi-auth-bearer-token": "^8.0.0",
"hapi-auth-jwt2": "^10.2.0",
Expand Down
4 changes: 2 additions & 2 deletions test/Integration/plugin-test.js
Expand Up @@ -89,12 +89,12 @@ lab.experiment('plugin', () => {
});

lab.test('plug-in register with validate option', async () => {
const goodOptions = {
const pluginOptions = {
validate: {
headers: true
}
};
const server = await Helper.createServer(goodOptions, routes);
const server = await Helper.createServer(pluginOptions, routes);
const response = await server.inject({ method: 'GET', url: '/swagger.json' });
expect(response.statusCode).to.equal(200);
expect(response.result.paths).to.have.length(1);
Expand Down
2 changes: 1 addition & 1 deletion usageguide.md
Expand Up @@ -604,7 +604,7 @@ be useful if your are using codegen tools against the JSON
## Debugging
The plugin can validate its output against the OpenAPI(Swagger) specification. You can to this by setting the plugin option `options.debug` to `true`.
The debug output is logged into the Hapi server object. You can view the logs by either install the `Good` plugin or by using `server.on`.
The debug output is logged into the Hapi server object. You can view the logs by either installing a [logging plugin](https://hapi.dev/plugins/#logging) or by using `server.on`.
There is a small example of the [`debug`](examples/debug.js) feature in the examples directory.
Expand Down

0 comments on commit df315ac

Please sign in to comment.