Skip to content

Commit

Permalink
support arrays in swagger
Browse files Browse the repository at this point in the history
adapter from holidayextras/jsonapi-server#413

Signed-off-by: Arnav Gupta <[email protected]>
  • Loading branch information
gboston authored and championswimmer committed Aug 2, 2018
1 parent 44708d5 commit c946b2c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/swagger/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ swaggerPaths._getResourceDefinition = resourceConfig => {
swaggerScheme.type = 'string'
swaggerScheme.format = 'date'
}
if (swaggerScheme.type === 'array') {
const items = joiScheme._inner.items
swaggerScheme.items = {type: 'object'}
if (items.length > 0 && items[0]._inner.children) {
items[0]._inner.children.forEach(x => {
swaggerScheme.items.properties = { ...swaggerScheme.items.properties, [x.key]: {type: x.schema._type} }
})
}
}
attributeShortcut[attribute] = swaggerScheme

if ((joiScheme._flags || { }).presence === 'required') {
Expand Down

0 comments on commit c946b2c

Please sign in to comment.