Compare commits

...
25 Commits
Author SHA1 Message Date
Tony Tam 356ae491aa fixed duplicate model, updated example name 2012-11-27 16:03:54 -08:00
Tony Tam 7bc8109e88 re-merged #96 2012-11-27 15:04:12 -08:00
Tony Tam 3fd37c3ef6 Merge pull request #102 from sequielo/patch-1
Update src/main/javascript/doc.js
2012-11-27 13:48:06 -08:00
Tony Tam 586c6d6292 Merge pull request #103 from pose/xml-pretty-print
Adding XML pretty printing to responses
2012-11-27 13:47:51 -08:00
Alberto Pose 12bdd38406 Adding fallback to XML when JSON response parsing fails. 2012-11-27 18:24:32 -03:00
sequielo 369b639329 Update src/main/javascript/doc.js
fixed #101: expand operations for resource when resource paramenter is an empty string.
2012-11-27 00:14:47 -02:00
Tony Tam 3f9ed33f7f added missing files per #100 2012-11-26 13:47:34 -08:00
Tony Tam d1bffc8fb4 manual merge of #97 2012-11-25 21:52:30 -08:00
Tony Tam 55f0c1a2f8 Merge pull request #95 from pose/json-response-pretty-print
Adding JSON sample UI to response
2012-11-25 21:10:52 -08:00
Tony Tam 03e21019d2 Merge pull request #94 from pose/titles-fix
Small change to signature titles
2012-11-25 21:10:16 -08:00
Tony Tam 75fd46ef21 Merge pull request #96 from pose/operation-nonce
Adding operation number to create a unique href for the <a/> tag.
2012-11-25 21:09:40 -08:00
Alberto Pose 75ff471425 Adding operation number to create a unique href for the <a/> tag. 2012-11-22 17:45:40 -03:00
Alberto Pose dd1b2219b8 Adding JSON sample UI to response 2012-11-21 13:20:09 -03:00
Alberto Pose f5cfee8296 Small improvements to some titles 2012-11-21 11:50:05 -03:00
Ayush Gupta a1337cf118 coffeescript compiled swagger.js for #91 2012-11-20 14:36:16 +05:30
Ayush Gupta 2bc67cbcae Merge pull request #91 from predicador37/master
Fixes Issue  #68 in a generic way for any param with any regex
2012-11-20 01:04:08 -08:00
predicador37 30886478d4 fixes https://github.com/wordnik/swagger-core/issues/68 in a generic way. Should work with all params. 2012-11-20 09:28:03 +01:00
Ayush Gupta fc320397e9 fix from https://github.com/wordnik/swagger-core/issues/68 2012-11-20 12:04:10 +05:30
Tony Tam 9b58ed5430 redo of PR #88, #89, #90 2012-11-19 19:51:28 -08:00
Tony Tam 2d62bddfb8 updated to 1.1.4 2012-11-19 19:30:42 -08:00
Ayush Gupta cfa2006042 closes #83 2012-11-16 12:11:47 +05:30
Ayush Gupta 3dca74c08f closes #84 2012-11-16 12:01:30 +05:30
Alberto Pose fd6379140d Adding syntax highlight to JSON snippets and responses. 2012-11-15 18:13:33 -03:00
Alberto Pose ab572e87be Removing console.log 2012-11-15 12:25:28 -03:00
Alberto Pose 9687a8084f Adding 'snippet' tab to parameter datatype signature UI
This new section displays how a complex datatype should look like providing some sample code for the developer using Swagger.
2012-11-14 17:33:51 -03:00
22 changed files with 544 additions and 51 deletions
+2
View File
@@ -10,6 +10,8 @@ sourceFiles = [
'view/OperationView'
'view/StatusCodeView'
'view/ParameterView'
'view/SignatureView'
'view/ContentTypeView'
]
File diff suppressed because one or more lines are too long
+51 -4
View File
@@ -53,6 +53,9 @@
this.progress('fetching resource list: ' + this.discoveryUrl);
return jQuery.getJSON(this.discoveryUrl, function(response) {
var res, resource, _i, _j, _len, _len1, _ref, _ref1;
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
_this.basePath = response.basePath;
if (_this.basePath.match(/^HTTP/i) == null) {
@@ -252,7 +255,7 @@
_results = [];
for (_i = 0, _len = ops.length; _i < _len; _i++) {
o = ops[_i];
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this);
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this, o.supportedContentTypes);
this.operations[op.nickname] = op;
_results.push(this.operationsArray.push(op));
}
@@ -334,6 +337,17 @@
return returnVal;
};
SwaggerModel.prototype.createJSONSample = function(modelToIgnore) {
var prop, result, _i, _len, _ref;
result = {};
_ref = this.properties;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
prop = _ref[_i];
result[prop.name] = prop.getSampleValue(modelToIgnore);
}
return result;
};
return SwaggerModel;
})();
@@ -363,6 +377,24 @@
}
}
SwaggerModelProperty.prototype.getSampleValue = function(modelToIgnore) {
var result;
if ((this.refModel != null) && (!(this.refModel === modelToIgnore))) {
result = this.refModel.createJSONSample(this.refModel);
} else {
if (this.isArray) {
result = this.refDataType;
} else {
result = this.dataType;
}
}
if (this.isArray) {
return [result];
} else {
return result;
}
};
SwaggerModelProperty.prototype.toString = function() {
var str;
str = this.name + ': ' + this.dataTypeWithRef;
@@ -381,7 +413,7 @@
SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource) {
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, supportedContentTypes) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
_this = this;
this.nickname = nickname;
@@ -393,6 +425,7 @@
this.responseClass = responseClass;
this.errorResponses = errorResponses;
this.resource = resource;
this.supportedContentTypes = supportedContentTypes;
this["do"] = __bind(this["do"], this);
if (this.nickname == null) {
@@ -413,6 +446,7 @@
}
if (this.responseClass != null) {
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
}
this.errorResponses = this.errorResponses || [];
_ref1 = this.parameters;
@@ -424,6 +458,7 @@
parameter.allowableValues.values = this.resource.api.booleanValues;
}
parameter.signature = this.getSignature(parameter.dataType, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models);
if (parameter.allowableValues != null) {
if (parameter.allowableValues.valueType === "RANGE") {
parameter.isRange = true;
@@ -478,6 +513,17 @@
}
};
SwaggerOperation.prototype.getSampleJSON = function(dataType, models) {
var isPrimitive, listType, val;
listType = this.isListType(dataType);
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample());
if (val) {
val = listType ? [val] : val;
return JSON.stringify(val, null, 2);
}
};
SwaggerOperation.prototype["do"] = function(args, callback, error) {
var body, headers;
if (args == null) {
@@ -518,7 +564,7 @@
};
SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
var param, queryParams, url, _i, _len, _ref;
var param, queryParams, reg, url, _i, _len, _ref;
if (includeApiKey == null) {
includeApiKey = true;
}
@@ -528,7 +574,8 @@
param = _ref[_i];
if (param.paramType === 'path') {
if (args[param.name]) {
url = url.replace("{" + param.name + "}", encodeURIComponent(args[param.name]));
reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
url = url.replace(reg, encodeURIComponent(args[param.name]));
delete args[param.name];
} else {
throw "" + param.name + " is a required path param.";
@@ -0,0 +1,19 @@
class ContentTypeView extends Backbone.View
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
@isParam = @model.isParam
if @isParam
$('label[for=contentType]', $(@el)).text('Parameter content type:')
else
$('label[for=contentType]', $(@el)).text('Response Content Type')
@
template: ->
Handlebars.templates.content_type
+1 -1
View File
@@ -13,7 +13,7 @@ class HeaderView extends Backbone.View
showPetStore: (e) ->
@trigger(
'update-swagger-ui'
{discoveryUrl:"http://petstore.swagger.wordnik.com/api/resources.json", apiKey:"special-key"}
{discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json", apiKey:"special-key"}
)
showWordnikDev: (e) ->
@@ -14,6 +14,24 @@ class OperationView extends Backbone.View
$(@el).html(Handlebars.templates.operation(@model))
if @model.responseClassSignature and @model.responseClassSignature != 'string'
signatureModel =
sampleJSON: @model.responseSampleJSON
isParam: false
signature: @model.responseClassSignature
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
$('.model-signature', $(@el)).html(@model.responseClass)
contentTypeModel =
isParam: false
supportedContentTypes: @model.supportedContentTypes
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
# Render each parameter
@addParameter param for param in @model.parameters
@@ -104,8 +122,17 @@ class OperationView extends Backbone.View
complete: (data) =>
@showCompleteStatus(data)
obj.contentType = "application/json" if (obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch")
obj.contentType = "application/json" if (obj.type.toLowerCase() == "post" or obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch")
obj.contentType = false if isFileUpload
paramContentTypeField = $("td select[name=contentType]", $(@el)).val()
if paramContentTypeField
obj.contentType = paramContentTypeField
responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(@el)).val()
if responseContentTypeField
obj.headers = if obj.headers? then obj.headers else {}
obj.headers.accept = responseContentTypeField
jQuery.ajax(obj)
false
# $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r)
@@ -120,7 +147,7 @@ class OperationView extends Backbone.View
# Show response from server
showResponse: (response) ->
prettyJson = JSON.stringify(response, null, "\t").replace(/\n/g, "<br>")
$(".response_body", $(@el)).html prettyJson
$(".response_body", $(@el)).html escape(prettyJson)
# Show error from server
@@ -131,19 +158,82 @@ class OperationView extends Backbone.View
showCompleteStatus: (data) ->
@showStatus data
# Adapted from http://stackoverflow.com/a/2893259/454004
formatXml: (xml) ->
reg = /(>)(<)(\/*)/g
wsexp = /[ ]*(.*)[ ]+\n/g
contexp = /(<.+>)(.+\n)/g
xml = xml.replace(reg, '$1\n$2$3').replace(wsexp, '$1\n').replace(contexp, '$1\n$2')
pad = 0
formatted = ''
lines = xml.split('\n')
indent = 0
lastType = 'other'
# 4 types of tags - single, closing, opening, other (text, doctype, comment) - 4*4 = 16 transitions
transitions =
'single->single': 0
'single->closing': -1
'single->opening': 0
'single->other': 0
'closing->single': 0
'closing->closing': -1
'closing->opening': 0
'closing->other': 0
'opening->single': 1
'opening->closing': 0
'opening->opening': 1
'opening->other': 1
'other->single': 0
'other->closing': -1
'other->opening': 0
'other->other': 0
for ln in lines
do (ln) ->
types =
# is this line a single tag? ex. <br />
single: Boolean(ln.match(/<.+\/>/))
# is this a closing tag? ex. </a>
closing: Boolean(ln.match(/<\/.+>/))
# is this even a tag (that's not <!something>)
opening: Boolean(ln.match(/<[^!?].*>/))
[type] = (key for key, value of types when value)
type = if type is undefined then 'other' else type
fromTo = lastType + '->' + type
lastType = type
padding = ''
indent += transitions[fromTo]
padding = (' ' for j in [0...(indent)]).join('')
if fromTo == 'opening->closing'
#substr removes line break (\n) from prev loop
formatted = formatted.substr(0, formatted.length - 1) + ln + '\n'
else
formatted += padding + ln + '\n'
formatted
# puts the response data in UI
showStatus: (data) ->
try
response_body = "<pre>" + JSON.stringify(JSON.parse(data.responseText), null, 2).replace(/\n/g, "<br>") + "</pre>"
code = $('<code />').text(JSON.stringify(JSON.parse(data.responseText), null, 2))
pre = $('<pre class="json" />').append(code)
catch error
response_body = "<span style='color:red'>&nbsp;&nbsp;&nbsp;[unable to parse as json; raw response below]</span><br><pre>" + data.responseText + "</pre>"
code = $('<code />').text(@formatXml(data.responseText))
pre = $('<pre class="xml" />').append(code)
response_body = pre
$(".response_code", $(@el)).html "<pre>" + data.status + "</pre>"
$(".response_body", $(@el)).html response_body
$(".response_headers", $(@el)).html "<pre>" + data.getAllResponseHeaders() + "</pre>"
$(".response", $(@el)).slideDown()
$(".response_hider", $(@el)).show()
$(".response_throbber", $(@el)).hide()
hljs.highlightBlock($('.response_body', $(@el))[0])
toggleOperationContent: ->
elem = $('#' + @model.resourceName + "_" + @model.nickname + "_" + @model.httpMethod + "_content");
elem = $('#' + @model.resourceName + "_" + @model.nickname + "_" + @model.httpMethod + "_" + @model.number + "_content")
if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem)
@@ -8,6 +8,24 @@ class ParameterView extends Backbone.View
template = @template()
$(@el).html(template(@model))
signatureModel =
sampleJSON: @model.sampleJSON
isParam: true
signature: @model.signature
if @model.sampleJSON
signatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append signatureView.render().el
else
$('.model-signature', $(@el)).html(@model.signature)
contentTypeModel =
isParam: true
supportedContentTypes: @model.supportedContentTypes
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
@
# Return an appropriate template based on if the parameter is a list, readonly, required
@@ -4,11 +4,18 @@ class ResourceView extends Backbone.View
render: ->
$(@el).html(Handlebars.templates.resource(@model))
@number = 0
# Render each operation
@addOperation operation for operation in @model.operationsArray
@
addOperation: (operation) ->
operation.number = @number
# Render an operation and add it to operations li
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint'})
$('.endpoints', $(@el)).append operationView.render().el
$('.endpoints', $(@el)).append operationView.render().el
@number++
@@ -0,0 +1,51 @@
class SignatureView extends Backbone.View
events: {
'click a.description-link' : 'switchToDescription'
'click a.snippet-link' : 'switchToSnippet'
'mousedown .snippet' : 'snippetToTextArea'
}
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
@switchToDescription()
@isParam = @model.isParam
if @isParam
$('.notice', $(@el)).text('Click to set as parameter value')
@
template: ->
Handlebars.templates.signature
# handler for show signature
switchToDescription: (e) ->
e?.preventDefault()
$(".snippet", $(@el)).hide()
$(".description", $(@el)).show()
$('.description-link', $(@el)).addClass('selected')
$('.snippet-link', $(@el)).removeClass('selected')
# handler for show sample
switchToSnippet: (e) ->
e?.preventDefault()
$(".description", $(@el)).hide()
$(".snippet", $(@el)).show()
$('.snippet-link', $(@el)).addClass('selected')
$('.description-link', $(@el)).removeClass('selected')
# handler for snippet to text area
snippetToTextArea: (e) ->
if @isParam
e?.preventDefault()
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
if $.trim(textArea.val()) == ''
textArea.val(@model.sampleJSON)
+135
View File
@@ -0,0 +1,135 @@
/*
Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
*/
pre code {
display: block; padding: 0.5em;
background: #F0F0F0;
}
pre code,
pre .subst,
pre .tag .title,
pre .lisp .title,
pre .clojure .built_in,
pre .nginx .title {
color: black;
}
pre .string,
pre .title,
pre .constant,
pre .parent,
pre .tag .value,
pre .rules .value,
pre .rules .value .number,
pre .preprocessor,
pre .ruby .symbol,
pre .ruby .symbol .string,
pre .aggregate,
pre .template_tag,
pre .django .variable,
pre .smalltalk .class,
pre .addition,
pre .flow,
pre .stream,
pre .bash .variable,
pre .apache .tag,
pre .apache .cbracket,
pre .tex .command,
pre .tex .special,
pre .erlang_repl .function_or_atom,
pre .markdown .header {
color: #800;
}
pre .comment,
pre .annotation,
pre .template_comment,
pre .diff .header,
pre .chunk,
pre .markdown .blockquote {
color: #888;
}
pre .number,
pre .date,
pre .regexp,
pre .literal,
pre .smalltalk .symbol,
pre .smalltalk .char,
pre .go .constant,
pre .change,
pre .markdown .bullet,
pre .markdown .link_url {
color: #080;
}
pre .label,
pre .javadoc,
pre .ruby .string,
pre .decorator,
pre .filter .argument,
pre .localvars,
pre .array,
pre .attr_selector,
pre .important,
pre .pseudo,
pre .pi,
pre .doctype,
pre .deletion,
pre .envvar,
pre .shebang,
pre .apache .sqbracket,
pre .nginx .built_in,
pre .tex .formula,
pre .erlang_repl .reserved,
pre .prompt,
pre .markdown .link_label,
pre .vhdl .attribute,
pre .clojure .attribute,
pre .coffeescript .property {
color: #88F
}
pre .keyword,
pre .id,
pre .phpdoc,
pre .title,
pre .built_in,
pre .aggregate,
pre .css .tag,
pre .javadoctag,
pre .phpdoc,
pre .yardoctag,
pre .smalltalk .class,
pre .winutils,
pre .bash .variable,
pre .apache .tag,
pre .go .typename,
pre .tex .command,
pre .markdown .strong,
pre .request,
pre .status {
font-weight: bold;
}
pre .markdown .emphasis {
font-style: italic;
}
pre .nginx .built_in {
font-weight: normal;
}
pre .coffeescript .javascript,
pre .javascript .xml,
pre .tex .formula,
pre .xml .javascript,
pre .xml .vbscript,
pre .xml .css,
pre .xml .cdata {
opacity: 0.5;
}
+83 -10
View File
@@ -1145,9 +1145,9 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
display: block;
margin: 0 0 0 0;
padding: 0;
background-color: #faebf2;
background-color: #FCE9E3;
border: 1px solid black;
border-color: #f0cecb;
border-color: #F5D5C3;
}
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 {
@@ -1168,7 +1168,7 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 span.http_method a {
text-transform: uppercase;
background-color: #993300;
background-color: #D38042;
text-decoration: none;
color: white;
display: inline-block;
@@ -1228,12 +1228,12 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li {
border-right-color: #f0cecb;
color: #993300;
color: #D38042;
font-size: 0.9em;
}
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li a {
color: #993300;
color: #D38042;
text-decoration: none;
}
@@ -1263,7 +1263,7 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
}
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content h4 {
color: #993300;
color: #D38042;
font-size: 1.1em;
margin: 0;
padding: 15px 0 5px 0px;
@@ -1271,7 +1271,7 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content form input[type='text'].error {
outline: 2px solid black;
outline-color: #cc0000;
outline-color: #F5D5C3;
}
body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content div.sandbox_header {
@@ -1509,9 +1509,82 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
font-size: 1em;
line-height: 1.5em;
}
.model-signature span {
.model-signature .description span {
font-size: 0.9em;
line-height: 1.5em;
}
.model-signature span:nth-child(odd) { color:#333; }
.model-signature span:nth-child(even) { color:#C5862B; }
.model-signature .description span:nth-child(odd) { color:#333; }
.model-signature .description span:nth-child(even) { color:#C5862B; }
.model-signature .signature-nav a {
text-decoration: none;
color: #AAA;
}
.model-signature pre {
font-size: .85em;
line-height: 1.2em;
overflow: auto;
max-height: 200px;
cursor: pointer;
}
.model-signature pre:hover {
background-color: #ffffdd;
}
.model-signature .snippet small {
font-size: 0.75em;
}
.model-signature .signature-container {
clear: both;
}
.model-signature .signature-nav a:hover {
text-decoration: underline;
color: black;
}
.model-signature .signature-nav .selected {
color: black;
text-decoration: none;
}
.model-signature ul.signature-nav {
float: none;
clear: both;
overflow: hidden;
margin: 0;
padding: 0;
display: block;
clear: none;
float: right;
margin-right: 5px;
margin-bottom: 5px;
}
.model-signature ul.signature-nav li {
float: left;
clear: none;
margin: 0;
padding: 2px 10px;
border-right: 1px solid #dddddd;
}
.model-signature ul.signature-nav li:last-child {
padding-right: 0;
border-right: none;
}
pre code {
background: none;
}
.content > .content-type > div > label {
clear: both;
display: block;
color: #0F6AB4;
font-size: 1.1em;
margin: 0;
padding: 15px 0 5px 0px;
}
+4 -1
View File
@@ -3,6 +3,7 @@
<head>
<title>Swagger UI</title>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
@@ -13,6 +14,7 @@
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<style type="text/css">
.swagger-ui-wrap {
@@ -43,7 +45,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/resources.json",
discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json",
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
@@ -54,6 +56,7 @@
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
+23 -9
View File
@@ -115,7 +115,7 @@ var Docs = {
},
toggleEndpointListForResource: function(resource) {
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
if (elem.is(':visible')) {
Docs.collapseEndpointListForResource(resource);
} else {
@@ -125,24 +125,37 @@ var Docs = {
// Expand resource
expandEndpointListForResource: function(resource) {
$('[id^=resource_' + resource + ']').addClass('active');
var resource = Docs.escapeResourceName(resource);
if (resource == '') {
$('.resource ul.endpoints').slideDown();
return;
}
$('li#resource_' + resource).addClass('active');
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
var elem = $('li#resource_' + resource + ' ul.endpoints');
elem.slideDown();
},
// Collapse resource and mark as explicitly closed
collapseEndpointListForResource: function(resource) {
$('[id^=resource_' + resource + ']').removeClass('active');
var resource = Docs.escapeResourceName(resource);
$('li#resource_' + resource).removeClass('active');
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
var elem = $('li#resource_' + resource + ' ul.endpoints');
elem.slideUp();
},
expandOperationsForResource: function(resource) {
// Make sure the resource container is open..
Docs.expandEndpointListForResource(resource);
$('li[id^=resource_' + Docs.escapeResourceName(resource) + '] li.operation div.content').each(function() {
if (resource == '') {
$('.resource ul.endpoints li.operation div.content').slideDown();
return;
}
$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
Docs.expandOperation($(this));
});
},
@@ -150,13 +163,14 @@ var Docs = {
collapseOperationsForResource: function(resource) {
// Make sure the resource container is open..
Docs.expandEndpointListForResource(resource);
$('li[id^=resource_' + Docs.escapeResourceName(resource) + '] li.operation div.content').each(function() {
$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
Docs.collapseOperation($(this));
});
},
escapeResourceName: function(resource) {
return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&")
return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&");
},
expandOperation: function(elem) {
@@ -167,4 +181,4 @@ var Docs = {
elem.slideUp();
}
};
};
@@ -0,0 +1,8 @@
{{#if supportedContentTypes}}
<label for="contentType"></label>
<select name="contentType">
{{#each supportedContentTypes}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
</select>
{{/if}}
+5 -2
View File
@@ -6,6 +6,9 @@
<div class="footer">
<br>
<br>
<h4 style="color: #999">[<span style="font-variant: small-caps">base url</span>: {{basePath}}]</h4>
<h4 style="color: #999">[ <span style="font-variant: small-caps">base url</span>: {{basePath}}
{{#if apiVersion}}
, <span style="font-variant: small-caps">api version</span>: {{apiVersion}}
{{/if}}]</h4>
</div>
</div>
</div>
+7 -7
View File
@@ -1,22 +1,22 @@
<ul class='operations' >
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}'>
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}'>
<div class='heading'>
<h3>
<span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{httpMethod}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{httpMethod}}</a>
</span>
<span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{path}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{path}}</a>
</span>
</h3>
<ul class='options'>
<li>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{{summary}}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
</li>
</ul>
</div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_content' style='display:none'>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}_content' style='display:none'>
{{#if notes}}
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
@@ -24,7 +24,7 @@
{{#if responseClass}}
<h4>Response Class</h4>
{{#if responseClassSignature}}
<p><span class="model-signature">{{{responseClassSignature}}}</span></p>
<p><span class="model-signature"></span></p>
{{else}}
<p>{{{responseClass}}}</p>
{{/if}}
@@ -81,4 +81,4 @@
</div>
</div>
</li>
</ul>
</ul>
+5 -3
View File
@@ -8,20 +8,22 @@
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' name='{{name}}'></textarea>
<textarea class='body-textarea' name='{{name}}'></textarea>
<br />
<div class="content-type" />
{{/if}}
{{/if}}
{{else}}
{{#if defaultValue}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
{{else}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
{{/if}}
{{/if}}
</td>
<td>{{{description}}}</td>
<td>
<span class="model-signature">{{{signature}}}</span>
<span class="model-signature"></span>
</td>
+1 -1
View File
@@ -18,4 +18,4 @@
</select>
</td>
<td>{{{description}}}</td>
<td><span class="model-signature">{{{signature}}}</span></td>
<td><span class="model-signature"></span></td>
+1 -1
View File
@@ -7,4 +7,4 @@
{{/if}}
</td>
<td>{{{description}}}</td>
<td><span class="model-signature">{{{signature}}}</span></td>
<td><span class="model-signature"></span></td>
@@ -7,4 +7,4 @@
{{/if}}
</td>
<td>{{{description}}}</td>
<td><span class="model-signature">{{{signature}}}</span></td>
<td><span class="model-signature"></span></td>
+7 -5
View File
@@ -7,7 +7,9 @@
{{#if defaultValue}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<br />
<div class="content-type" />
{{/if}}
{{/if}}
{{else}}
@@ -15,14 +17,14 @@
<input class='required' type='file' name='{{name}}'/>
{{else}}
{{#if defaultValue}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
{{else}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
{{/if}}
{{/if}}
{{/if}}
</td>
<td>
<strong>{{{description}}}</strong>
<strong>{{{description}}}</strong>
</td>
<td><span class="model-signature">{{{signature}}}</span></td>
<td><span class="model-signature"></span></td>
+18
View File
@@ -0,0 +1,18 @@
<div>
<ul class="signature-nav">
<li><a class="description-link" href="#">Model</a></li>
<li><a class="snippet-link" href="#">Model Schema</a></li>
</ul>
<div>
<div class="signature-container">
<div class="description">
{{{signature}}}
</div>
<div class="snippet">
<pre><code>{{sampleJSON}}</code></pre>
<small class="notice"></small>
</div>
</div>