forked from marcgibbons/django-rest-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for marcgibbons#434: remove inline scripts
- Loading branch information
1 parent
cb999b2
commit fcd8052
Showing
7 changed files
with
139 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
rest_framework_swagger/static/rest_framework_swagger/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
$(function () { | ||
window.swaggerUi = new SwaggerUi({ | ||
url: "http://petstore.swagger.wordnik.com/api/api-docs", | ||
dom_id: "swagger-ui-container", | ||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], | ||
onComplete: function(swaggerApi, swaggerUi){ | ||
log("Loaded SwaggerUI"); | ||
|
||
if(typeof initOAuth == "function") { | ||
/* | ||
initOAuth({ | ||
clientId: "your-client-id", | ||
realm: "your-realms", | ||
appName: "your-app-name" | ||
}); | ||
*/ | ||
} | ||
$('pre code').each(function(i, e) { | ||
hljs.highlightBlock(e) | ||
}); | ||
}, | ||
onFailure: function(data) { | ||
log("Unable to Load SwaggerUI"); | ||
}, | ||
docExpansion: "none" | ||
}); | ||
|
||
$('#input_apiKey').change(function() { | ||
var key = $('#input_apiKey')[0].value; | ||
log("key: " + key); | ||
if(key && key.trim() != "") { | ||
log("added key " + key); | ||
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query")); | ||
} | ||
}) | ||
window.swaggerUi.load(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$(function () { | ||
window.swaggerUi = new SwaggerUi({ | ||
url: '{{ swagger_settings.discovery_url }}', | ||
apiKey: '{{ swagger_settings.api_key }}', | ||
dom_id: 'swagger-ui-container', | ||
supportedSubmitMethods: {{ swagger_settings.enabled_methods }}, | ||
onComplete: function (swaggerApi, swaggerUi){ | ||
log('Loaded SwaggerUI') | ||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)}); | ||
}, | ||
onFailure: function (data) { | ||
log('Unable to Load SwaggerUI'); | ||
}, | ||
docExpansion: '{{ swagger_settings.doc_expansion }}', | ||
csrfCookieName: {{ django_settings.CSRF_COOKIE_NAME }} | ||
}); | ||
|
||
$('#input_apiKey').change(function () { | ||
var key = $('#input_apiKey')[0].value; | ||
log('key: ' + key); | ||
|
||
if (key && key.trim() != '') { | ||
console.log('added key ' + key); | ||
window.authorizations.add('key', new ApiKeyAuthorization('Authorization', '{{ swagger_settings.token_type }} ' + key, 'header')); | ||
} | ||
}); | ||
|
||
{% if swagger_settings.api_key %} | ||
window.authorizations.add('key', new ApiKeyAuthorization('Authorization', '{{ swagger_settings.token_type }} ' + '{{ swagger_settings.api_key }}', 'header')); | ||
{% endif %} | ||
|
||
{# Add version to Accept header, if AcceptHeaderVersioning is used. #} | ||
{% if swagger_settings.api_version and rest_framework_settings.DEFAULT_VERSIONING_CLASS == 'rest_framework.versioning.AcceptHeaderVersioning' %} | ||
window.authorizations.add('version', { | ||
apply: function(obj, authorizations) { | ||
$.each(obj.headers, function(k, v) { | ||
if (k.toLowerCase() === "accept") { | ||
if (v.indexOf('; version=') === -1) { | ||
obj.headers[k] += "; version={{ swagger_settings.api_version }}"; | ||
} | ||
return false; // break. | ||
} | ||
}); | ||
return true; | ||
} | ||
}); | ||
{% endif %} | ||
|
||
window.swaggerUi.load(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from django.conf.urls import url | ||
from rest_framework_swagger.views import SwaggerResourcesView, SwaggerApiView, SwaggerUIView | ||
from rest_framework_swagger.views import (SwaggerBaseJSView, | ||
SwaggerResourcesView, SwaggerApiView, | ||
SwaggerUIView) | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^$', SwaggerUIView.as_view(), name="django.swagger.base.view"), | ||
url(r'^api-docs/$', SwaggerResourcesView.as_view(), name="django.swagger.resources.view"), | ||
url(r'^api-docs/(?P<path>.*)/?$', SwaggerApiView.as_view(), name='django.swagger.api.view'), | ||
url(r'^base.js$', SwaggerBaseJSView.as_view(), name='django.swagger.basejs.view') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters