Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 8 additions & 2 deletions lib/generate-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ module.exports = function generateDocument (baseDocument, router, basePath) {
if (routeLayer && routeLayer.keys && routeLayer.keys.length) {
const keys = {}

const params = routeLayer.keys.map((k) => {
const params = routeLayer.keys.map((k, i) => {
const prev = i > 0 && routeLayer.keys[i - 1]
// do not count parameters without a name if they are next to a named parameter
if (typeof k.name === 'number' && prev && prev.offset + prev.name.length + 1 >= k.offset) {
return null
}
let param
if (schema.parameters) {
param = schema.parameters.find((p) => p.name === k.name && p.in === 'path')
Expand All @@ -45,6 +50,7 @@ module.exports = function generateDocument (baseDocument, router, basePath) {
schema: k.schema || { type: 'string' }
}, param || {})
})
.filter((e) => e)

if (schema.parameters) {
schema.parameters.forEach((p) => {
Expand All @@ -55,7 +61,7 @@ module.exports = function generateDocument (baseDocument, router, basePath) {
}

operation.parameters = params
path = pathToRegexp.compile(path)(keys, { encode: (value) => value })
path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'))(keys, { encode: (value) => value })
}

doc.paths[path] = doc.paths[path] || {}
Expand Down
Loading