Skip to content
Open
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: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions lib/resource.nunjucks
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,30 @@

{% if method.securedBy.length %}
<div class="alert alert-warning">
<span class="glyphicon glyphicon-lock" title="Authentication required"></span> Secured by {{ method.securedBy }}
<span class="glyphicon glyphicon-lock" title="Authentication required"></span> Secured by

{% 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 %}
<b>Grant types:</b> {{ securedByValue.authorizationGrants | join(',') | replace('credentials','client_credentials',1) | replace('code','authorization_code',1) | replace('token','implicit',1) }}.
{% endif %}
{% if securedByValue.scopes %}
<b>Scopes:</b> {{ securedByValue.scopes | join(',')}}.
{% endif %}
{% endif %}
{% endfor %}
{% set i=i+1 %}
{% endfor %}
{% else %}
{{ method.securedBy }}
{% endif %}
</div>
{% endif %}

<!-- Nav tabs -->
<ul class="nav nav-tabs">
{% if method.allUriParameters.length or method.queryParameters or method.headers or method.body %}
Expand Down