Skip to content

Commit

Permalink
Add operation-level security, refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRalphson committed Oct 20, 2017
1 parent 3df9d34 commit da76f49
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* ~~Finish parameter enums~~
* Rework tags-input
* ~~Editing of requestBody schemas / content-types~~
* ~~Operation-level security~~
* Scope editor for operation-level security
* Editing of requestBody examples
* Add validation on form fields
* License name is required if license url is filled in (thus the object is present)
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi3-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This document outlines this project's support for visualising the [OpenAPI V3][o
- [x] [servers](#servers-object)
- [ ] [paths](#paths-object)
- [ ] [components](#components-object)
- [ ] [security](#security-requirement-object)
- [x] [security](#security-requirement-object)
- [ ] [tags](#tag-object)
- [x] [externalDocs](#external-documentation-object)

Expand Down Expand Up @@ -77,7 +77,7 @@ This is supported by default as all `$ref` are dereferenced before the definitio
- [ ] [examples](#example-object)
- [x] [requestBodies](#request-body-object)
- [x] [headers](#header-object)
- [ ] [securitySchemes](#security-scheme-object)
- [x] [securitySchemes](#security-scheme-object)
- [ ] [links](#link-object)
- [x] [callbacks](#callback-object)

Expand Down
21 changes: 21 additions & 0 deletions src/method/method.html
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,27 @@

</div>

<div class="method-pane method-pane-security hidden container is-fluid">
<div class="level">
<label class="label" for="chkDefault">Use default security</label>
<input id="chkDefault" class="checkbox" type="checkbox" v-model="secDefault"/>
<label class="label" for="chkNone">Disable security</label>
<input id="chkNone" class="checkbox" type="checkbox" v-model="secNone"/>
<label class="label" for="chkCustom">Use custom security</label>
<input id="chkCustom" class="checkbox" type="checkbox" v-model="secCustom"/>
</div>
<div v-if="secCustom">
<h4 class="none"><strong>Selected security schemes</strong></h4>
<ul>
<li v-for="(scheme,index) in method.security">
<span class="icon" data-balloon="Remove security scheme from operation"><a v-on:click="removeSecScheme(index)"><i class="fa fa-trash"></i></a></span>
<span><strong>{{Object.keys(scheme)[0]}}</strong></span>
<span>{{Object.values(scheme)[0]}}</span>
</li>
</ul>
</div>
</div>

<div class="method-pane method-pane-links hidden container is-fluid">
<div class="card" v-if="!method.links || Object.keys(method.links).length == 0">
<div class="card-content">
Expand Down
64 changes: 64 additions & 0 deletions src/method/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ Vue.component('api-method', {
Vue.set(exp,'get',{parameters:[],responses:{default:{description:'Default response'}}});
}
},
removeSecScheme : function(index) {
this.method.security.splice(index,1);
Vue.set(this.method,'security',this.method.security);
},
tagSetup : function() {
var simpleTags = [];
for (var t in this.maintags) {
Expand Down Expand Up @@ -186,6 +190,66 @@ Vue.component('api-method', {
if (!this.method.requestBody.$ref) return this.method.requestBody;
return deref(this.method.requestBody, this.$root.container.openapi);
}
},
secDefault : {
get : function() {
return (!this.method.security);
},
set : function(newVal) {
if (newVal) {
Vue.delete(this.method, 'security');
}
else {
Vue.set(this.method, 'security', []); // disable, works like radio buttons
}
}
},
secNone : {
get : function() {
return (this.method.security && this.method.security.length === 0);
},
set : function(newVal) {
if (newVal) {
Vue.set(this.method, 'security', []);
}
else {
Vue.delete(this.method, 'security'); // default, works like radio buttons
}
}
},
secCustom : {
get : function() {
return (this.method.security && this.method.security.length > 0);
},
set : function(newVal) {
if (newVal) {
var newSec = clone(this.$root.container.openapi.security);
if (!newSec || newSec.length === 0) {
newSec = [];
for (s in this.$root.container.openapi.components.securitySchemes) {
var scheme = this.$root.container.openapi.components.securitySchemes[s];
var scopes = [];
if (scheme.type === 'oauth2') {
for (var f in scheme.flows) {
var flow = scheme.flows[f];
if (flow.scopes) {
for (sc in flow.scopes) {
if (scopes.indexOf(s) < 0) scopes.push(sc);
}
}
}
}
var entry = {};
entry[s] = scopes;
newSec.push(entry);
}
}
Vue.set(this.method, 'security', newSec);
}
else {
Vue.delete(this.method, 'security'); // default, works like radio buttons
}
}
}
},
beforeUpdate : function() {
Expand Down

0 comments on commit da76f49

Please sign in to comment.