From 3f4f661f0dc8e79efe649faef558d09dc2e64a58 Mon Sep 17 00:00:00 2001 From: zegotinha Date: Thu, 3 Sep 2015 16:16:15 +0200 Subject: [PATCH 1/3] added support for outputting OAuth 2.0 authorizationGrants and scopes. --- lib/resource.nunjucks | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/resource.nunjucks b/lib/resource.nunjucks index 10b4945d..f8b47e24 100644 --- a/lib/resource.nunjucks +++ b/lib/resource.nunjucks @@ -61,7 +61,24 @@ {% if method.securedBy.length %}
- Secured by {{ method.securedBy }} + Secured by + + {% if method.securedBy=='[object Object]' %} + {% for securedBy in method.securedBy %} + {% if securedBy.oauth_2_0 %} + OAuth 2.0. + {% if securedBy.oauth_2_0.scopes %} + Grant types: {{ securedBy.oauth_2_0.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}. + {% endif %} + {% if securedBy.oauth_2_0.scopes %} + Scopes: {{ securedBy.oauth_2_0.scopes | join(',')}}. + {% endif %} + {% endif %} + {% endfor %} + {% else %} + {{ method.securedBy }} + {% endif %} +
{% endif %} From ed54cf571a1431e9bab62ddd8de42310434caa56 Mon Sep 17 00:00:00 2001 From: zegotinha Date: Tue, 8 Sep 2015 15:39:06 +0200 Subject: [PATCH 2/3] bugfix securedBy with scopes but no authorizationGrants error --- lib/resource.nunjucks | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/resource.nunjucks b/lib/resource.nunjucks index f8b47e24..e643580c 100644 --- a/lib/resource.nunjucks +++ b/lib/resource.nunjucks @@ -67,11 +67,11 @@ {% for securedBy in method.securedBy %} {% if securedBy.oauth_2_0 %} OAuth 2.0. - {% if securedBy.oauth_2_0.scopes %} - Grant types: {{ securedBy.oauth_2_0.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}. + {% if securedBy.oauth_2_0.authorizationGrants %} + Grant types: {{ securedBy.oauth_2_0.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}. {% endif %} {% if securedBy.oauth_2_0.scopes %} - Scopes: {{ securedBy.oauth_2_0.scopes | join(',')}}. + Scopes: {{ securedBy.oauth_2_0.scopes | join(',')}}. {% endif %} {% endif %} {% endfor %} From 45c3c40cfd1dbb2e345456e77693fa3619b94286 Mon Sep 17 00:00:00 2001 From: taahefa2 Date: Tue, 8 Sep 2015 17:26:36 +0200 Subject: [PATCH 3/3] improved printing oauth 2.0 scopes and grant types --- index.js | 10 ++++++++++ lib/resource.nunjucks | 29 ++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index f67712e0..ac84d039 100644 --- a/index.js +++ b/index.js @@ -105,6 +105,16 @@ function getDefaultConfig(mainTemplate, templatesPath) { var env = nunjucks.configure(templatesPath, {watch: false}); markdown.register(env, marked); + // Add extra function for finding a security scheme by name + ramlObj.securitySchemeWithName = function(name) { + return ramlObj.securitySchemes[0][name]; + }; + + //typeof function + ramlObj.getTypeOf = function(v) { + return typeof v; + }; + _traverse(ramlObj); // Render the main template using the raml object and fix the double quotes diff --git a/lib/resource.nunjucks b/lib/resource.nunjucks index e643580c..0eb9ec94 100644 --- a/lib/resource.nunjucks +++ b/lib/resource.nunjucks @@ -63,25 +63,28 @@
Secured by - {% if method.securedBy=='[object Object]' %} - {% for securedBy in method.securedBy %} - {% if securedBy.oauth_2_0 %} - OAuth 2.0. - {% if securedBy.oauth_2_0.authorizationGrants %} - Grant types: {{ securedBy.oauth_2_0.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}. - {% endif %} - {% if securedBy.oauth_2_0.scopes %} - Scopes: {{ securedBy.oauth_2_0.scopes | join(',')}}. - {% endif %} + {% if getTypeOf(method.securedBy)=='object' %} + {% set i=0 %} + {% for securedByItem in method.securedBy %} + {% for secureByName, securedByValue in method.securedBy[i] %} + {% if securitySchemeWithName(secureByName).type == "OAuth 2.0" %} + OAuth 2.0. + {% if securedByValue.authorizationGrants %} + Grant types: {{ securedByValue.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}. + {% endif %} + {% if securedByValue.scopes %} + Scopes: {{ securedByValue.scopes | join(',')}}. + {% endif %} {% endif %} {% endfor %} + {% set i=i+1 %} + {% endfor %} {% else %} - {{ method.securedBy }} + {{ method.securedBy }} {% endif %} -
{% endif %} - +