Skip to content

Commit

Permalink
Compliance with spec on parameter rendering. Fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Jul 14, 2015
1 parent 74622cd commit 440fd39
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
@@ -1,5 +1,6 @@
# Unreleased

* Compliance with spec on parameter rendering. [#58](https://github.com/danielgtaylor/aglio/issues/58)
* Minor theme color tweaks.
* Make it possible to easily override padding and fonts.
* Fix minor styling issue on Internet Explorer 11.
Expand Down
17 changes: 16 additions & 1 deletion src/main.coffee
Expand Up @@ -227,9 +227,24 @@ decorate = (api, md, slugCache) ->
action.methodLower = action.method.toLowerCase()

# Parameters may be defined on the action or on the
# parent resource.
# parent resource. Resource parameters should be concatenated
# to the action-specific parameters if set.
if not action.parameters or not action.parameters.length
action.parameters = resource.parameters
else if resource.parameters
action.parameters = resource.parameters.concat(action.parameters)

# Remove any duplicates! This gives precedence to the parameters
# defined on the action.
knownParams = {}
newParams = []
reversed = (action.parameters or []).concat([]).reverse()
for param in reversed
if knownParams[param.name] then continue
knownParams[param.name] = true
newParams.push param

action.parameters = newParams.reverse()

# Examples have a content section only if they have a
# description, headers, body, or schema.
Expand Down
2 changes: 1 addition & 1 deletion templates/mixins.jade
Expand Up @@ -75,7 +75,7 @@ mixin Parameters(params)
dl.inner: each param in params || []
dt= self.urldec(param.name)
dd
code= param.type
code= param.type || 'string'
|  
if param.required
span.required (required)
Expand Down
8 changes: 7 additions & 1 deletion test/layout.coffee
Expand Up @@ -100,7 +100,11 @@ describe 'Layout', ->
name: 'TestGroup'
resources: [
name: 'TestResource'
parameters: []
parameters: [
name: 'idParam'
description: 'Id parameter description'
values: []
]
actions: [
name: 'Test Action',
description: 'Test *description*'
Expand Down Expand Up @@ -132,6 +136,8 @@ describe 'Layout', ->
assert.include html, 'Test Action'
assert.include html, 'Test <em>description</em>'
assert.include html, 'GET'
assert.include html, 'idParam'
assert.include html, 'Id parameter description'
assert.include html, 'paramName'
assert.include html, 'Param <em>description</em>'
assert.include html, 'bool'
Expand Down

0 comments on commit 440fd39

Please sign in to comment.