Skip to content

Add cookie support #1010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions dist/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@
width: 300px;
border: 1px solid #aaa;
}
.swagger-section .swagger-ui-wrap .cookies {
width: 100%;
display: block;
overflow: auto;
}
.swagger-section .swagger-ui-wrap .cookies input {
display: block;
float: left;
width: 75%;
}
.swagger-section .swagger-ui-wrap .cookies button {
display: block;
float: right;
width: 10%;
}
.swagger-section .swagger-ui-wrap h1 {
color: black;
font-size: 1.5em;
Expand Down
15 changes: 15 additions & 0 deletions dist/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@
width: 300px;
border: 1px solid #aaa;
}
.swagger-section .swagger-ui-wrap .cookies {
width: 100%;
display: block;
overflow: auto;
}
.swagger-section .swagger-ui-wrap .cookies input {
display: block;
float: left;
width: 75%;
}
.swagger-section .swagger-ui-wrap .cookies button {
display: block;
float: right;
width: 10%;
}
.swagger-section .swagger-ui-wrap h1 {
color: black;
font-size: 1.5em;
Expand Down
27 changes: 27 additions & 0 deletions dist/swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function
buffer += " <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.parameters : depth0), {"name":"if","hash":{},"fn":this.program(18, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
buffer += " <h4>Cookies</h4>\n <div class=\"cookies\">\n <input class=\"cookie-input\" type=\"text\">\n <button class=\"update-cookies\">Update</button>\n <button class=\"clear-cookies\">Clear All</button>\n </div>\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.responseMessages : depth0), {"name":"if","hash":{},"fn":this.program(20, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isReadOnly : depth0), {"name":"if","hash":{},"fn":this.program(22, data),"inverse":this.program(24, data),"data":data});
Expand Down Expand Up @@ -1324,6 +1325,8 @@ OperationView = (function(superClass) {
'click .submit': 'submitOperation',
'click .response_hider': 'hideResponse',
'click .toggleOperation': 'toggleOperationContent',
'click .update-cookies': 'updateCookies',
'click .clear-cookies': 'clearCookies',
'mouseenter .api-ic': 'mouseEnter',
'mouseout .api-ic': 'mouseExit'
};
Expand Down Expand Up @@ -1525,9 +1528,33 @@ OperationView = (function(superClass) {
statusCode = ref5[q];
this.addStatusCode(statusCode);
}
$('.cookie-input', this.el).val(document.cookie);
return this;
};

OperationView.prototype.updateCookies = function(event) {
var input;
input = $('.cookie-input', this.el);
document.cookie = input.val();
input.val(document.cookie);
return event.preventDefault();
};

OperationView.prototype.clearCookies = function(event) {
var cookie, l, len, len1, m, ref1, ref2, sp;
event.preventDefault();
ref1 = document.cookie.split(";");
for (l = 0, len = ref1.length; l < len; l++) {
cookie = ref1[l];
ref2 = cookie.split('=');
for (m = 0, len1 = ref2.length; m < len1; m++) {
sp = ref2[m];
document.cookie = sp + "=;expires=Thu, 21 Sep 1979 00:00:01 UTC;";
}
}
return $('.cookie-input', this.el).val(document.cookie);
};

OperationView.prototype.addParameter = function(param, consumes) {
var paramView;
param.consumes = consumes;
Expand Down
6 changes: 3 additions & 3 deletions dist/swagger-ui.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/main/coffeescript/view/OperationView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class OperationView extends Backbone.View
'click .submit' : 'submitOperation'
'click .response_hider' : 'hideResponse'
'click .toggleOperation' : 'toggleOperationContent'
'click .update-cookies' : 'updateCookies'
'click .clear-cookies' : 'clearCookies'
'mouseenter .api-ic' : 'mouseEnter'
'mouseout .api-ic' : 'mouseExit'
}
Expand Down Expand Up @@ -151,8 +153,22 @@ class OperationView extends Backbone.View
# Render each response code
@addStatusCode statusCode for statusCode in @model.responseMessages

$('.cookie-input', @el).val(document.cookie)
@

updateCookies: (event)->
input = $('.cookie-input', @el)
document.cookie = input.val()
input.val(document.cookie)
event.preventDefault()

clearCookies: (event)->
event.preventDefault()
for cookie in document.cookie.split(";")
for sp in cookie.split('=')
document.cookie = sp + "=;expires=Thu, 21 Sep 1979 00:00:01 UTC;";
$('.cookie-input', @el).val(document.cookie)

addParameter: (param, consumes) ->
# Render a parameter
param.consumes = consumes
Expand Down
15 changes: 15 additions & 0 deletions src/main/html/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@
width: 300px;
border: 1px solid #aaa;
}
.swagger-section .swagger-ui-wrap .cookies {
width: 100%;
display: block;
overflow: auto;
}
.swagger-section .swagger-ui-wrap .cookies input {
display: block;
float: left;
width: 75%;
}
.swagger-section .swagger-ui-wrap .cookies button {
display: block;
float: right;
width: 10%;
}
.swagger-section .swagger-ui-wrap h1 {
color: black;
font-size: 1.5em;
Expand Down
15 changes: 15 additions & 0 deletions src/main/html/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@
width: 300px;
border: 1px solid #aaa;
}
.swagger-section .swagger-ui-wrap .cookies {
width: 100%;
display: block;
overflow: auto;
}
.swagger-section .swagger-ui-wrap .cookies input {
display: block;
float: left;
width: 75%;
}
.swagger-section .swagger-ui-wrap .cookies button {
display: block;
float: right;
width: 10%;
}
.swagger-section .swagger-ui-wrap h1 {
color: black;
font-size: 1.5em;
Expand Down
17 changes: 17 additions & 0 deletions src/main/less/specs.less
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,23 @@
border: 1px solid #aaa;
}

.cookies {
width: 100%;
display: block;
overflow: auto;

input {
display: block;
float: left;
width: 75%;
}
button {
display: block;
float: right;
width: 10%;
}
}

h1 {
color: black;
font-size: 1.5em;
Expand Down
6 changes: 6 additions & 0 deletions src/main/template/operation.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
</tbody>
</table>
{{/if}}
<h4>Cookies</h4>
<div class="cookies">
<input class="cookie-input" type="text">
<button class="update-cookies">Update</button>
<button class="clear-cookies">Clear All</button>
</div>
{{#if responseMessages}}
<div style='margin:0;padding:0;display:inline'></div>
<h4>Response Messages</h4>
Expand Down