From 440fd394fc16da8036b0af5e0af91c904a33f635 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Tue, 14 Jul 2015 14:04:52 +0200 Subject: [PATCH] Compliance with spec on parameter rendering. Fixes #58 --- Changelog.md | 1 + src/main.coffee | 17 ++++++++++++++++- templates/mixins.jade | 2 +- test/layout.coffee | 8 +++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2af1e524..817d46b1 100644 --- a/Changelog.md +++ b/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. diff --git a/src/main.coffee b/src/main.coffee index a83e6bf7..0655d04d 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -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. diff --git a/templates/mixins.jade b/templates/mixins.jade index cf9a7d85..1158890b 100644 --- a/templates/mixins.jade +++ b/templates/mixins.jade @@ -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) diff --git a/test/layout.coffee b/test/layout.coffee index 52f9546a..c2e0c7bb 100644 --- a/test/layout.coffee +++ b/test/layout.coffee @@ -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*' @@ -132,6 +136,8 @@ describe 'Layout', -> assert.include html, 'Test Action' assert.include html, 'Test description' assert.include html, 'GET' + assert.include html, 'idParam' + assert.include html, 'Id parameter description' assert.include html, 'paramName' assert.include html, 'Param description' assert.include html, 'bool'