Skip to content

Commit

Permalink
allow pattern queries
Browse files Browse the repository at this point in the history
  • Loading branch information
antony committed May 14, 2021
1 parent df3df17 commit 73a0e9b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
6 changes: 5 additions & 1 deletion examples/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ const startServer = async () => {
id: Joi.string()
.required()
.description('The identifier of the customer to be retrieved.')
})
}),
query: Joi.object().pattern(
Joi.string().required().description('Ticket name'),
Joi.number().integer().required().min(1).description('Ticket quantity')
).min(1).required().description('Tickets requested')
},
plugins: {
'hapi-docs': {
Expand Down
46 changes: 32 additions & 14 deletions lib/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,40 @@ class Paths {
getParamsData(param) {
let paramsData = []

if (param.type === 'object' && param.keys) {
Object.entries(param.keys).forEach(([key, val]) => {
const data = {
name: key,
notes: this.processNotes(val.notes),
tags: val.tags,
type: val.type,
flags: val.flags && {
description: val.flags.description,
required: val.flags.presence === 'required',
default: val.flags.default
if (param.type === 'object') {
if (param.keys) {
Object.entries(param.keys).forEach(([key, val]) => {
const data = {
name: key,
notes: this.processNotes(val.notes),
tags: val.tags,
type: val.type,
flags: val.flags && {
description: val.flags.description,
required: val.flags.presence === 'required',
default: val.flags.default
}
}
}

paramsData.push(data)
})
paramsData.push(data)
})
}

if (param.patterns) {
param.patterns.forEach(({ schema, rule }) => {
const data = {
name: `<${schema.flags.description}>`,
type: rule.type,
flags: rule.flags && {
description: rule.flags.description,
required: rule.flags.presence === 'required',
default: rule.flags.default
}
}

paramsData.push(data)
})
}
}

return paramsData
Expand Down

0 comments on commit 73a0e9b

Please sign in to comment.