Merge pull request #16 from acasademont/master
Make swagger-ui compatible with non-GET requests
This commit is contained in:
@@ -189,7 +189,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
||||
return "{" + this.path_json + "| " + this.nickname + paramsString + ": " + this.summary + "}";
|
||||
},
|
||||
|
||||
invocationUrl: function(formValues) {
|
||||
invocationData: function(formValues) {
|
||||
var formValuesMap = new Object();
|
||||
for (var i = 0; i < formValues.length; i++) {
|
||||
var formValue = formValues[i];
|
||||
@@ -203,21 +203,23 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
||||
var url = $.tmpl(urlTemplate, formValuesMap)[0].data;
|
||||
// log("url with path params = " + url);
|
||||
|
||||
var queryParams = apiKeySuffix;
|
||||
var queryParams = {};
|
||||
if (apiKey) {
|
||||
apiKey = jQuery.trim(apiKey);
|
||||
if (apiKey.length > 0)
|
||||
queryParams['api_key'] = apiKey;
|
||||
}
|
||||
this.parameters.each(function(param) {
|
||||
var paramValue = jQuery.trim(formValuesMap[param.name]);
|
||||
if (param.paramType == "query" && paramValue.length > 0) {
|
||||
queryParams += queryParams.length > 0 ? "&": "?";
|
||||
queryParams += param.name;
|
||||
queryParams += "=";
|
||||
queryParams += formValuesMap[param.name];
|
||||
queryParams[param.name] = formValuesMap[param.name];
|
||||
}
|
||||
});
|
||||
|
||||
url = this.baseUrl + url + queryParams;
|
||||
url = this.baseUrl + url;
|
||||
// log("final url with query params and base url = " + url);
|
||||
|
||||
return url;
|
||||
return {url: url, queryParams: queryParams};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -284,8 +284,6 @@ jQuery(function($) {
|
||||
|
||||
for (var p = 0; p < this.operation.parameters.count(); p++) {
|
||||
var param = Param.init(this.operation.parameters.all()[p]);
|
||||
// Only GET operations display forms..
|
||||
param.readOnly = !this.isGetOperation;
|
||||
param.cleanup();
|
||||
|
||||
$(param.templateName()).tmpl(param).appendTo(operationParamsContainer);
|
||||
@@ -293,14 +291,7 @@ jQuery(function($) {
|
||||
}
|
||||
|
||||
var submitButtonId = this.elementScope + "_content_sandbox_response_button";
|
||||
if (this.isGetOperation) {
|
||||
$(submitButtonId).click(this.submitOperation);
|
||||
} else {
|
||||
$(submitButtonId).hide();
|
||||
|
||||
var valueHeader = this.elementScope + "_value_header";
|
||||
$(valueHeader).html("Default Value");
|
||||
}
|
||||
$(submitButtonId).click(this.submitOperation);
|
||||
|
||||
},
|
||||
|
||||
@@ -327,9 +318,15 @@ jQuery(function($) {
|
||||
});
|
||||
|
||||
if (error_free) {
|
||||
var invocationUrl = this.operation.invocationUrl(form.serializeArray());
|
||||
$(".request_url", this.elementScope + "_content_sandbox_response").html("<pre>" + invocationUrl + "</pre>");
|
||||
$.getJSON(invocationUrl, this.showResponse).complete(this.showCompleteStatus).error(this.showErrorStatus);
|
||||
var invocationData = this.operation.invocationData(form.serializeArray());
|
||||
$(".request_url", this.elementScope + "_content_sandbox_response").html("<pre>" + invocationData.url + "</pre>");
|
||||
$.ajax({
|
||||
url: invocationData.url,
|
||||
dataType: 'json',
|
||||
data: invocationData.queryParams,
|
||||
success: this.showResponse,
|
||||
type: this.operation.httpMethod.toUpperCase()
|
||||
}).complete(this.showCompleteStatus).error(this.showErrorStatus);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user