Compare commits

..
62 Commits
Author SHA1 Message Date
Tony Tam 348f1e109b updated swagger-js 2013-09-26 16:24:06 -07:00
Tony Tam abc3600994 Merge pull request #295 from tomrac87/hal_json
Proper formatting for "application/hal+json" Content-Type
2013-09-24 06:38:16 -07:00
Tony Tam 77882a0e3e Merge pull request #311 from aerotech/master
updating docs, change in sample and java required for build
2013-09-17 10:09:39 -07:00
Pavel Puchkarev 0e98639f45 updating docs, change in sample and java required for build 2013-09-17 13:04:08 -04:00
Tony Tam 3347d7e9fd merged pr for https://github.com/wordnik/swagger-js/pull/54 2013-09-16 14:54:36 -07:00
Tony Tam 929f8b61f2 Merge branch 'master' of github.com:wordnik/swagger-ui 2013-09-14 20:43:36 -07:00
Tony Tam 8158e9b25f fix for #310 2013-09-14 20:43:20 -07:00
Tony Tam a0db8582a1 fixed example 2013-09-14 09:36:14 -07:00
Tony Tam 1b662db2d2 fix for required fields showing optional 2013-09-12 11:00:27 -07:00
Tony Tam cd4fa99cc4 added resource description 2013-09-09 08:15:59 -07:00
Tony Tam bc93240199 fixed merge issue 2013-09-05 20:03:31 -07:00
Tony Tam 999367589d fix for #301, headers being URI encoded 2013-09-05 11:39:18 -07:00
Tony Tam 8a9eedfdf3 manual merge of #304 2013-09-05 10:16:10 -07:00
Tony Tam 046e534d03 manual merge of #303 2013-09-05 09:31:21 -07:00
Tony Tam 73c89ba3f6 fix for #297, enabled throbber 2013-09-03 12:41:26 -07:00
tomrac87 ff05f9113b Added proper formatting for hal+json Content-Type responses in coffeescript source file 2013-09-02 10:02:26 +02:00
Tony Tam 6c1de0b560 added enum support per #296 2013-08-29 17:27:49 -07:00
Tony Tam 4fb5b86db1 updated swagger-js to address sample schema issues 2013-08-29 17:15:50 -07:00
tomrac87 5f4eec1b8a Added proper formatting for hal+json Content-Type responses 2013-08-28 15:39:50 +02:00
Tony Tam f22efb66de fix for #279, empty boolean drop-downs 2013-08-20 12:48:14 -07:00
Tony Tam 9e25ec56c9 Merge branch 'master' of github.com:wordnik/swagger-ui 2013-08-19 11:40:19 -07:00
Tony Tam 085cc05cc7 fixed responseMessages issue per #267 2013-08-19 11:40:03 -07:00
Tony Tam 56a58143e7 Merge pull request #287 from rcrooks/master
fixing file name -- realized the typo in the link tag was replicating on...
2013-08-15 17:39:24 -07:00
Robert Crooks 7802c36646 fixing file name -- realized the typo in the link tag was replicating one in the css file name 2013-08-15 16:54:09 -04:00
Tony Tam fca0bdf12d Merge pull request #286 from bcls/master
fix for issue #285
2013-08-15 11:27:40 -07:00
Brightcove Learning Services 727d9e03e0 fix for issue #285 2013-08-15 14:07:45 -04:00
Tony Tam 888db09fd8 fixed enum, required flags 2013-08-14 16:49:08 -07:00
Tony Tam f29d53d5bc updated readme 2013-08-14 12:18:36 -07:00
Tony Tam b138359f5b updated readme 2013-08-14 11:50:58 -07:00
Tony Tam 9fccf1c3a6 updated swagger-client 2013-08-14 11:27:18 -07:00
Tony Tam 25805a4bc0 fixed petstore link 2013-08-14 10:53:31 -07:00
Tony Tam 6865ab5287 merged from develop branch 2013-08-14 10:51:15 -07:00
Tony Tam 085fc8dc7e updated handlebars 2013-08-14 10:48:48 -07:00
Tony Tam 205125cd9d fixes for content-type 2013-08-14 10:38:41 -07:00
Tony Tam 4b5e4e5d69 updated for 1.2 support 2013-08-12 08:28:40 -07:00
Tony Tam b2637fc4bc removed console log, updated swagger.js 2013-07-31 08:11:51 -07:00
Tony Tam 3c3e297949 Merge pull request #272 from thinkt4nk/master
fixed discrepancy between handlebars precompiler and runtime
2013-07-30 11:49:44 -07:00
Ryan Bales dd88dc1727 fixed discrepancy between handlebars precompiler and runtime 2013-07-30 09:43:57 -05:00
Tony Tam c6f2aada45 merged https://github.com/wordnik/swagger-js/issues/42 2013-07-18 11:40:47 -07:00
Tony Tam df20d2bd5e fix for #263 2013-07-17 16:02:47 -07:00
Tony Tam e72dbd6bc6 fix for #261 2013-07-16 20:59:46 -07:00
Tony Tam f4d77d7124 fix for #261 2013-07-16 20:57:26 -07:00
Tony Tam 390ee1c781 removed console logs 2013-07-11 16:56:03 -07:00
Tony Tam 627fd8b4d6 removed some logging 2013-07-11 16:52:48 -07:00
Tony Tam 078851ba6e fixed default URL 2013-07-11 07:59:11 -07:00
Tony Tam e980cca6b4 added api info 2013-07-11 00:26:05 -07:00
Tony Tam 187d245047 updated to use petstore instead of localhost 2013-07-09 11:54:06 -07:00
Tony Tam 58746157b3 added authorization support from swagger-js 2.0 2013-07-09 11:27:32 -07:00
Tony Tam 2a206b0a6b renamed discoveryUrl to url to match js change 2013-07-08 23:53:05 -07:00
Tony Tam 6a5dfdcedc fix for #174, #78 2013-07-08 22:03:15 -07:00
Tony Tam 8f7e8f9ee0 updated to latest swagger-js 2013-07-08 18:38:11 -07:00
Tony Tam 22e5f5ccc1 #199 2013-07-07 01:21:39 -07:00
Tony Tam 8fcaa608e0 removed swagger-client dep for now, it's copied manually 2013-07-07 01:16:48 -07:00
Tony Tam 8bac45d960 updated deps, version 2013-07-07 00:55:11 -07:00
Tony Tam 09be20c97d merged with swagger.js-2.0-develop 2013-07-07 00:53:30 -07:00
Tony Tam 7334079535 added shred library 2013-07-07 00:53:12 -07:00
Tony Tam cde29f0d9a added separate request and response templates 2013-07-07 00:52:46 -07:00
Tony Tam 7b9f8a2651 added separate request and response templates 2013-07-07 00:52:37 -07:00
Tony Tam 2dd2eb9e50 added shred library 2013-07-07 00:52:00 -07:00
Tony Tam 4a6fc1d3bd added shred library 2013-07-07 00:51:55 -07:00
Tony Tam 5794d1c0d5 Update index.html 2013-07-01 21:39:20 -07:00
Tony Tam 9efb0a798e added support for swagger-spec 1.2 2013-06-30 21:37:21 -07:00
41 changed files with 13839 additions and 5412 deletions
+1
View File
@@ -19,3 +19,4 @@ reports/*
swagger-ui.sublime-workspace
.idea
.project
node_modules/*
+2
View File
@@ -12,6 +12,8 @@ sourceFiles = [
'view/ParameterView'
'view/SignatureView'
'view/ContentTypeView'
'view/ResponseContentTypeView'
'view/ParameterContentTypeView'
]
+29 -29
View File
@@ -1,12 +1,10 @@
Swagger UI
==========
Swagger UI is part of [Swagger](http://swagger.wordnik.com/) project. The Swagger project allows you to produce, visualize and consume your OWN RESTful
services. No proxy or 3rd party services required. Do it your own way.
Swagger UI is part of [Swagger](http://swagger.wordnik.com/) project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way.
Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically
generate beautiful documentation and sandbox from a [Swagger-compliant](https://github.com/wordnik/swagger-core/wiki) API. Because Swagger UI has no
dependencies, you can host it in any server environment, or on your local machine.
generate beautiful documentation and sandbox from a [Swagger-compliant](https://github.com/wordnik/swagger-core/wiki) API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.
How to Use It
-------------
@@ -17,13 +15,14 @@ You can use the swagger-ui code AS-IS! No need to build or recompile--just clon
### Build
You can rebuild swagger-ui on your own to tweak it or just so you can say you did. To do so, follow these steps:
1. npm install
2. npm run-script build
3. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
1. install [handlebars](http://handlebarsjs.com/)
2. install java
3. npm install
4. npm run-script build
5. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
### Use
Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.wordnik.com/api/resources.json) service and show its APIs.
You can enter your own server url and click explore to view the API.
Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.wordnik.com/api/api-docs) service and show its APIs. You can enter your own server url and click explore to view the API.
### Customize
You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories:
@@ -40,19 +39,16 @@ You may choose to customize Swagger UI for your organization. Here is an overvie
### SwaggerUi
To use swagger-ui you should take a look at the [source of swagger-ui html page](https://github.com/wordnik/swagger-ui/tree/master/src/main/html) and customize it. This basically requires you to instantiate a SwaggerUi object and call load() on it as below:
```javascript
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/resources.json",
dom_id:"swagger-ui-container",
apiKey:"special-key",
supportHeaderParams: false,
headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" },
supportedSubmitMethods: ['get', 'post', 'put']
url:"http://petstore.swagger.wordnik.com/api/api-docs",
dom_id:"swagger-ui-container"
});
window.swaggerUi.load();
```
* *discoveryUrl* parameter should point to a resource listing url as per [Swagger Spec](https://github.com/wordnik/swagger-core/wiki)
* *url* parameter should point to a resource listing url as per [Swagger Spec](https://github.com/wordnik/swagger-core/wiki)
* *dom_id parameter* is the the id of a dom element inside which SwaggerUi will put the user interface for swagger
* *booleanValues* SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1)
* *docExpansion* controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details)
@@ -62,28 +58,32 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
### HTTP Methods and API Invocation
swagger-ui supports invocation of all HTTP methods APIs but only GET methods APIs are enabled by default. You can choose to enable other HTTP methods like POST, PUT and DELETE. This can be enabled by [setting the supportedSubmitMethods parameter when creating SwaggerUI instance](https://github.com/wordnik/swagger-ui/blob/f2e63c65a759421aad590b7275371cd0c06c74ea/src/main/html/index.html#L49).
swagger-ui supports invocation of all HTTP methods APIs including GET, PUT, POST, DELETE, PATCH, OPTIONS. These are handled in the [swagger-js](https://github.com/wordnik/swagger-js) project, please see there for specifics on their usage.
For example if you wanted to enable GET, POST and PUT but not for DELETE, you'd set this as:
supportedSubmitMethods: ['get', 'post', 'put']
_Note that for POST/PUT body, you'd need to paste in the request data in an appropriate format which your service can unmarshall_
### Header Parameters
header parameters are supported. However because of [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/) restrictions, swagger-ui, by default, does not send header parameters. This can be enabled by [setting the supportHeaderParams to true when creating SwaggerUI instance](https://github.com/wordnik/swagger-ui/blob/f2e63c65a759421aad590b7275371cd0c06c74ea/src/main/html/index.html#L48) as below:
Header params are supported through a pluggable mechanism in [swagger-js](https://github.com/wordnik/swagger-js). You can see the [index.html](https://github.com/wordnik/swagger-ui/blob/master/dist/index.html) for a sample of how to dynamically set headers:
supportHeaderParams: true
```js
// add a new ApiKeyAuthorization when the api-key changes in the ui.
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
if(key && key.trim() != "") {
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
}
})
```
This will add header `api_key` with value `key` on every call to the server. You can substitute `query` to send the values as a query param.
### Custom Header Parameters - (For Basic auth etc)
If you have some header parameters which you need to send with every request, use the headers as below:
headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" }
```js
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX", "header"));
```
### Api Key Parameter
If you enter an api key in swagger-ui, it sends a parameter named 'api\_key' as a query (or as a header param if you've enabled it as described above). You may not want to use the name 'api\_key' as the name of this parameter. You can change its name by setting the _apiKeyName_ parameter when you instantiate a SwaggerUI instance. For example to call it 'sessionId'
apiKeyName: "sessionId"
Note! You can pass multiple header params on a single request, just use unique names for them (`key` is used in the above example).
How to Improve It
-----------------
+23
View File
@@ -1756,4 +1756,27 @@ pre code {
.message-fail {
color: #cc0000;
}
.info_title {
padding-bottom: 10px;
font-weight: bold;
font-size: 25px;
}
.info_description {
padding-bottom: 10px;
font-size: 15px;
}
.info_tos {
padding-bottom: 5px;
}
.info_license {
padding-bottom: 5px;
}
.info_contact {
padding-bottom: 5px;
}
+61 -58
View File
@@ -1,74 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href='//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>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<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>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script type="text/javascript" src="lib/shred.bundle.js" /></script>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.0.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<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>
<script type="text/javascript">
$(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){
if(console) {
console.log("Loaded SwaggerUI")
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json",
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
console.log("added key " + key);
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.swaggerUi.load();
});
window.swaggerUi.load();
});
</script>
</script>
</head>
<body>
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl"
type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
&nbsp;
&nbsp;
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">
+2278
View File
File diff suppressed because it is too large Load Diff
-1920
View File
File diff suppressed because it is too large Load Diff
+2765
View File
File diff suppressed because it is too large Load Diff
+193
View File
@@ -0,0 +1,193 @@
// The purpose of the `Content` object is to abstract away the data conversions
// to and from raw content entities as strings. For example, you want to be able
// to pass in a Javascript object and have it be automatically converted into a
// JSON string if the `content-type` is set to a JSON-based media type.
// Conversely, you want to be able to transparently get back a Javascript object
// in the response if the `content-type` is a JSON-based media-type.
// One limitation of the current implementation is that it [assumes the `charset` is UTF-8](https://github.com/spire-io/shred/issues/5).
// The `Content` constructor takes an options object, which *must* have either a
// `body` or `data` property and *may* have a `type` property indicating the
// media type. If there is no `type` attribute, a default will be inferred.
var Content = function(options) {
this.body = options.body;
this.data = options.data;
this.type = options.type;
};
Content.prototype = {
// Treat `toString()` as asking for the `content.body`. That is, the raw content entity.
//
// toString: function() { return this.body; }
//
// Commented out, but I've forgotten why. :/
};
// `Content` objects have the following attributes:
Object.defineProperties(Content.prototype,{
// - **type**. Typically accessed as `content.type`, reflects the `content-type`
// header associated with the request or response. If not passed as an options
// to the constructor or set explicitly, it will infer the type the `data`
// attribute, if possible, and, failing that, will default to `text/plain`.
type: {
get: function() {
if (this._type) {
return this._type;
} else {
if (this._data) {
switch(typeof this._data) {
case "string": return "text/plain";
case "object": return "application/json";
}
}
}
return "text/plain";
},
set: function(value) {
this._type = value;
return this;
},
enumerable: true
},
// - **data**. Typically accessed as `content.data`, reflects the content entity
// converted into Javascript data. This can be a string, if the `type` is, say,
// `text/plain`, but can also be a Javascript object. The conversion applied is
// based on the `processor` attribute. The `data` attribute can also be set
// directly, in which case the conversion will be done the other way, to infer
// the `body` attribute.
data: {
get: function() {
if (this._body) {
return this.processor.parser(this._body);
} else {
return this._data;
}
},
set: function(data) {
if (this._body&&data) Errors.setDataWithBody(this);
this._data = data;
return this;
},
enumerable: true
},
// - **body**. Typically accessed as `content.body`, reflects the content entity
// as a UTF-8 string. It is the mirror of the `data` attribute. If you set the
// `data` attribute, the `body` attribute will be inferred and vice-versa. If
// you attempt to set both, an exception is raised.
body: {
get: function() {
if (this._data) {
return this.processor.stringify(this._data);
} else {
return this._body.toString();
}
},
set: function(body) {
if (this._data&&body) Errors.setBodyWithData(this);
this._body = body;
return this;
},
enumerable: true
},
// - **processor**. The functions that will be used to convert to/from `data` and
// `body` attributes. You can add processors. The two that are built-in are for
// `text/plain`, which is basically an identity transformation and
// `application/json` and other JSON-based media types (including custom media
// types with `+json`). You can add your own processors. See below.
processor: {
get: function() {
var processor = Content.processors[this.type];
if (processor) {
return processor;
} else {
// Return the first processor that matches any part of the
// content type. ex: application/vnd.foobar.baz+json will match json.
var main = this.type.split(";")[0];
var parts = main.split(/\+|\//);
for (var i=0, l=parts.length; i < l; i++) {
processor = Content.processors[parts[i]]
}
return processor || {parser:identity,stringify:toString};
}
},
enumerable: true
},
// - **length**. Typically accessed as `content.length`, returns the length in
// bytes of the raw content entity.
length: {
get: function() {
if (typeof Buffer !== 'undefined') {
return Buffer.byteLength(this.body);
}
return this.body.length;
}
}
});
Content.processors = {};
// The `registerProcessor` function allows you to add your own processors to
// convert content entities. Each processor consists of a Javascript object with
// two properties:
// - **parser**. The function used to parse a raw content entity and convert it
// into a Javascript data type.
// - **stringify**. The function used to convert a Javascript data type into a
// raw content entity.
Content.registerProcessor = function(types,processor) {
// You can pass an array of types that will trigger this processor, or just one.
// We determine the array via duck-typing here.
if (types.forEach) {
types.forEach(function(type) {
Content.processors[type] = processor;
});
} else {
// If you didn't pass an array, we just use what you pass in.
Content.processors[types] = processor;
}
};
// Register the identity processor, which is used for text-based media types.
var identity = function(x) { return x; }
, toString = function(x) { return x.toString(); }
Content.registerProcessor(
["text/html","text/plain","text"],
{ parser: identity, stringify: toString });
// Register the JSON processor, which is used for JSON-based media types.
Content.registerProcessor(
["application/json; charset=utf-8","application/json","json"],
{
parser: function(string) {
return JSON.parse(string);
},
stringify: function(data) {
return JSON.stringify(data); }});
var qs = require('querystring');
// Register the post processor, which is used for JSON-based media types.
Content.registerProcessor(
["application/x-www-form-urlencoded"],
{ parser : qs.parse, stringify : qs.stringify });
// Error functions are defined separately here in an attempt to make the code
// easier to read.
var Errors = {
setDataWithBody: function(object) {
throw new Error("Attempt to set data attribute of a content object " +
"when the body attributes was already set.");
},
setBodyWithData: function(object) {
throw new Error("Attempt to set body attribute of a content object " +
"when the data attributes was already set.");
}
}
module.exports = Content;
+709 -252
View File
File diff suppressed because it is too large Load Diff
+911 -902
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2765
View File
File diff suppressed because it is too large Load Diff
+193
View File
@@ -0,0 +1,193 @@
// The purpose of the `Content` object is to abstract away the data conversions
// to and from raw content entities as strings. For example, you want to be able
// to pass in a Javascript object and have it be automatically converted into a
// JSON string if the `content-type` is set to a JSON-based media type.
// Conversely, you want to be able to transparently get back a Javascript object
// in the response if the `content-type` is a JSON-based media-type.
// One limitation of the current implementation is that it [assumes the `charset` is UTF-8](https://github.com/spire-io/shred/issues/5).
// The `Content` constructor takes an options object, which *must* have either a
// `body` or `data` property and *may* have a `type` property indicating the
// media type. If there is no `type` attribute, a default will be inferred.
var Content = function(options) {
this.body = options.body;
this.data = options.data;
this.type = options.type;
};
Content.prototype = {
// Treat `toString()` as asking for the `content.body`. That is, the raw content entity.
//
// toString: function() { return this.body; }
//
// Commented out, but I've forgotten why. :/
};
// `Content` objects have the following attributes:
Object.defineProperties(Content.prototype,{
// - **type**. Typically accessed as `content.type`, reflects the `content-type`
// header associated with the request or response. If not passed as an options
// to the constructor or set explicitly, it will infer the type the `data`
// attribute, if possible, and, failing that, will default to `text/plain`.
type: {
get: function() {
if (this._type) {
return this._type;
} else {
if (this._data) {
switch(typeof this._data) {
case "string": return "text/plain";
case "object": return "application/json";
}
}
}
return "text/plain";
},
set: function(value) {
this._type = value;
return this;
},
enumerable: true
},
// - **data**. Typically accessed as `content.data`, reflects the content entity
// converted into Javascript data. This can be a string, if the `type` is, say,
// `text/plain`, but can also be a Javascript object. The conversion applied is
// based on the `processor` attribute. The `data` attribute can also be set
// directly, in which case the conversion will be done the other way, to infer
// the `body` attribute.
data: {
get: function() {
if (this._body) {
return this.processor.parser(this._body);
} else {
return this._data;
}
},
set: function(data) {
if (this._body&&data) Errors.setDataWithBody(this);
this._data = data;
return this;
},
enumerable: true
},
// - **body**. Typically accessed as `content.body`, reflects the content entity
// as a UTF-8 string. It is the mirror of the `data` attribute. If you set the
// `data` attribute, the `body` attribute will be inferred and vice-versa. If
// you attempt to set both, an exception is raised.
body: {
get: function() {
if (this._data) {
return this.processor.stringify(this._data);
} else {
return this._body.toString();
}
},
set: function(body) {
if (this._data&&body) Errors.setBodyWithData(this);
this._body = body;
return this;
},
enumerable: true
},
// - **processor**. The functions that will be used to convert to/from `data` and
// `body` attributes. You can add processors. The two that are built-in are for
// `text/plain`, which is basically an identity transformation and
// `application/json` and other JSON-based media types (including custom media
// types with `+json`). You can add your own processors. See below.
processor: {
get: function() {
var processor = Content.processors[this.type];
if (processor) {
return processor;
} else {
// Return the first processor that matches any part of the
// content type. ex: application/vnd.foobar.baz+json will match json.
var main = this.type.split(";")[0];
var parts = main.split(/\+|\//);
for (var i=0, l=parts.length; i < l; i++) {
processor = Content.processors[parts[i]]
}
return processor || {parser:identity,stringify:toString};
}
},
enumerable: true
},
// - **length**. Typically accessed as `content.length`, returns the length in
// bytes of the raw content entity.
length: {
get: function() {
if (typeof Buffer !== 'undefined') {
return Buffer.byteLength(this.body);
}
return this.body.length;
}
}
});
Content.processors = {};
// The `registerProcessor` function allows you to add your own processors to
// convert content entities. Each processor consists of a Javascript object with
// two properties:
// - **parser**. The function used to parse a raw content entity and convert it
// into a Javascript data type.
// - **stringify**. The function used to convert a Javascript data type into a
// raw content entity.
Content.registerProcessor = function(types,processor) {
// You can pass an array of types that will trigger this processor, or just one.
// We determine the array via duck-typing here.
if (types.forEach) {
types.forEach(function(type) {
Content.processors[type] = processor;
});
} else {
// If you didn't pass an array, we just use what you pass in.
Content.processors[types] = processor;
}
};
// Register the identity processor, which is used for text-based media types.
var identity = function(x) { return x; }
, toString = function(x) { return x.toString(); }
Content.registerProcessor(
["text/html","text/plain","text"],
{ parser: identity, stringify: toString });
// Register the JSON processor, which is used for JSON-based media types.
Content.registerProcessor(
["application/json; charset=utf-8","application/json","json"],
{
parser: function(string) {
return JSON.parse(string);
},
stringify: function(data) {
return JSON.stringify(data); }});
var qs = require('querystring');
// Register the post processor, which is used for JSON-based media types.
Content.registerProcessor(
["application/x-www-form-urlencoded"],
{ parser : qs.parse, stringify : qs.stringify });
// Error functions are defined separately here in an attempt to make the code
// easier to read.
var Errors = {
setDataWithBody: function(object) {
throw new Error("Attempt to set data attribute of a content object " +
"when the body attributes was already set.");
},
setBodyWithData: function(object) {
throw new Error("Attempt to set body attribute of a content object " +
"when the data attributes was already set.");
}
}
module.exports = Content;
+1239
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "swagger-ui",
"version": "1.1.15",
"version": "2.0.2",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"scripts": {
"build": "PATH=$PATH:./node_modules/.bin cake dist",
@@ -19,7 +19,6 @@
"readmeFilename": "README.md",
"dependencies": {
"coffee-script": "~1.5.0",
"swagger-client": "1.0.4",
"handlebars": "~1.0.10"
}
}
+21 -5
View File
@@ -34,16 +34,22 @@ class SwaggerUi extends Backbone.Router
# Event handler for when url/key is received from user
updateSwaggerUi: (data) ->
@options.discoveryUrl = data.discoveryUrl
@options.apiKey = data.apiKey
@options.url = data.url
@load()
# Create an api and render
load: ->
# Initialize the API object
@mainView?.clear()
@headerView.update(@options.discoveryUrl, @options.apiKey)
url = @options.url
if url.indexOf("http") isnt 0
url = @buildUrl(window.location.href.toString(), url)
@options.url = url
@headerView.update(url)
@api = new SwaggerApi(@options)
@api.build()
@api
# This is bound to success handler for SwaggerApi
# so it gets called when SwaggerApi completes loading
@@ -52,8 +58,8 @@ class SwaggerUi extends Backbone.Router
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
@showMessage()
switch @options.docExpansion
when "full" then Docs.expandOperationsForResource('')
when "list" then Docs.collapseOperationsForResource('')
when "full" then Docs.expandOperationsForResource('')
when "list" then Docs.collapseOperationsForResource('')
@options.onComplete(@api, @) if @options.onComplete
setTimeout(
=>
@@ -61,6 +67,16 @@ class SwaggerUi extends Backbone.Router
400
)
buildUrl: (base, url) ->
console.log "base is " + base
parts = base.split("/")
base = parts[0] + "//" + parts[2]
if url.indexOf("/") is 0
base + url
else
base + "/" + url
# Shows message on topbar of the ui
showMessage: (data = '') ->
$('#message-bar').removeClass 'message-fail'
@@ -5,12 +5,7 @@ class ContentTypeView extends Backbone.View
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')
$('label[for=contentType]', $(@el)).text('Response Content Type')
@
+5 -6
View File
@@ -9,17 +9,16 @@ class HeaderView extends Backbone.View
initialize: ->
showPetStore: (e) ->
@trigger(
'update-swagger-ui'
{discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json", apiKey:"special-key"}
{url:"http://petstore.swagger.wordnik.com/api/api-docs"}
)
showWordnikDev: (e) ->
@trigger(
'update-swagger-ui'
{discoveryUrl:"http://api.wordnik.com/v4/resources.json", apiKey:""}
{url:"http://api.wordnik.com/v4/resources.json"}
)
showCustomOnKeyup: (e) ->
@@ -29,10 +28,10 @@ class HeaderView extends Backbone.View
e?.preventDefault()
@trigger(
'update-swagger-ui'
{discoveryUrl: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
{url: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
)
update: (url, apiKey, trigger = false) ->
$('#input_baseUrl').val url
$('#input_apiKey').val apiKey
@trigger 'update-swagger-ui', {discoveryUrl:url, apiKey:apiKey} if trigger
#$('#input_apiKey').val apiKey
@trigger 'update-swagger-ui', {url:url} if trigger
+73 -111
View File
@@ -9,7 +9,7 @@ class OperationView extends Backbone.View
initialize: ->
render: ->
isMethodSubmissionSupported = jQuery.inArray(@model.httpMethod, @model.supportedSubmitMethods()) >= 0
isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0
@model.isReadOnly = true unless isMethodSubmissionSupported
$(@el).html(Handlebars.templates.operation(@model))
@@ -23,31 +23,35 @@ class OperationView extends Backbone.View
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
$('.model-signature', $(@el)).html(@model.responseClass)
$('.model-signature', $(@el)).html(@model.type)
contentTypeModel =
isParam: false
# support old syntax
if @model.supportedContentTypes
contentTypeModel.produces = @model.supportedContentTypes
contentTypeModel.consumes = @model.consumes
contentTypeModel.produces = @model.produces
if @model.produces
contentTypeModel.produces = @model.produces
for param in @model.parameters
type = param.type || param.dataType
if type.toLowerCase() == 'file'
if !contentTypeModel.consumes
console.log "set content type "
contentTypeModel.consumes = 'multipart/form-data'
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
# Render each parameter
@addParameter param for param in @model.parameters
@addParameter param, contentTypeModel.consumes for param in @model.parameters
# Render each response code
@addStatusCode statusCode for statusCode in @model.errorResponses
@addStatusCode statusCode for statusCode in @model.responseMessages
@
addParameter: (param) ->
addParameter: (param, consumes) ->
# Render a parameter
param.consumes = consumes
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly})
$('.operation-params', $(@el)).append paramView.render().el
@@ -72,103 +76,44 @@ class OperationView extends Backbone.View
# if error free submit it
if error_free
map = {}
for o in form.serializeArray()
opts = {parent: @}
#for o in form.serializeArray()
#if(o.value? && jQuery.trim(o.value).length > 0)
#map[o.name] = o.value
for o in form.find("input")
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = o.value
isFileUpload = form.children().find('input[type~="file"]').size() != 0
for o in form.find("textarea")
if(o.value? && jQuery.trim(o.value).length > 0)
map["body"] = o.value
isFormPost = false
consumes = "application/json"
if @model.consumes and @model.consumes.length > 0
# honor the consumes setting above everything else
consumes = @model.consumes[0]
else
for o in @model.parameters
if o.paramType == 'form'
isFormPost = true
consumes = false
for o in form.find("select")
val = this.getSelectedValue o
if(val? && jQuery.trim(val).length > 0)
map[o.name] = val
if isFileUpload
consumes = false
else if @model.httpMethod.toLowerCase() == "post" and isFormPost is false
consumes = "application/json"
opts.responseContentType = $("div select[name=responseContentType]", $(@el)).val()
opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val()
if isFileUpload
# requires HTML5 compatible browser
bodyParam = new FormData()
# add params except file
for param in @model.parameters
if (param.paramType is 'body' or 'form') and param.name isnt 'file' and param.name isnt 'File' and map[param.name]?
bodyParam.append(param.name, map[param.name])
# add files
$.each form.children().find('input[type~="file"]'), (i, el) ->
bodyParam.append($(el).attr('name'), el.files[0])
console.log(bodyParam)
else if isFormPost
bodyParam = new FormData()
for param in @model.parameters
if map[param.name]?
bodyParam.append(param.name, map[param.name])
else
bodyParam = null
for param in @model.parameters
if param.paramType is 'body'
bodyParam = map[param.name]
log "bodyParam = " + bodyParam
headerParams = null
invocationUrl =
if @model.supportHeaderParams()
headerParams = @model.getHeaderParams(map)
@model.urlify(map, false)
else
@model.urlify(map, true)
log 'submitting ' + invocationUrl
$(".request_url", $(@el)).html "<pre>" + invocationUrl + "</pre>"
$(".response_throbber", $(@el)).show()
obj =
type: @model.httpMethod
url: invocationUrl
headers: headerParams
data: bodyParam
contentType: consumes
dataType: 'json'
processData: false
error: (xhr, textStatus, error) =>
@showErrorStatus(xhr, textStatus, error)
success: (data) =>
@showResponse(data)
complete: (data) =>
@showCompleteStatus(data)
@model.do(map, opts, @showCompleteStatus, @showErrorStatus, @)
paramContentTypeField = $("td select[name=contentType]", $(@el)).val()
if paramContentTypeField
obj.contentType = paramContentTypeField
log 'content type = ' + obj.contentType
if not (obj.data or (obj.type is 'GET' or obj.type is 'DELETE')) and obj.contentType is not "application/x-www-form-urlencoded"
obj.contentType = false
log 'content type is now = ' + obj.contentType
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)
success: (response, parent) ->
parent.showCompleteStatus response
getSelectedValue: (select) ->
if !select.multiple
select.value
else
options = []
options.push opt.value for opt in select.options when opt.selected
if options.length > 0
options.join ","
else
null
# handler for hide response link
hideResponse: (e) ->
@@ -182,14 +127,13 @@ class OperationView extends Backbone.View
prettyJson = JSON.stringify(response, null, "\t").replace(/\n/g, "<br>")
$(".response_body", $(@el)).html escape(prettyJson)
# Show error from server
showErrorStatus: (data) ->
@showStatus data
showErrorStatus: (data, parent) ->
parent.showStatus data
# show the status codes
showCompleteStatus: (data) ->
@showStatus data
showCompleteStatus: (data, parent) ->
parent.showStatus data
# Adapted from http://stackoverflow.com/a/2893259/454004
formatXml: (xml) ->
@@ -252,21 +196,39 @@ class OperationView extends Backbone.View
# puts the response data in UI
showStatus: (data) ->
try
code = $('<code />').text(JSON.stringify(JSON.parse(data.responseText), null, 2))
content = data.content.data
headers = data.getHeaders()
# if server is nice, and sends content-type back, we can use it
contentType = headers["Content-Type"]
if content == undefined
code = $('<code />').text("no content")
pre = $('<pre class="json" />').append(code)
catch error
code = $('<code />').text(@formatXml(data.responseText))
else if contentType.indexOf("application/json") == 0 || contentType.indexOf("application/hal+json") == 0
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2))
pre = $('<pre class="json" />').append(code)
else if contentType.indexOf("application/xml") == 0
code = $('<code />').text(@formatXml(content))
pre = $('<pre class="xml" />').append(code)
else if contentType.indexOf("text/html") == 0
code = $('<code />').html(content)
pre = $('<pre class="xml" />').append(code)
else
# don't know what to render!
code = $('<code />').text(content)
pre = $('<pre class="json" />').append(code)
response_body = pre
$(".request_url").html "<pre>" + data.request.url + "</pre>"
$(".response_code", $(@el)).html "<pre>" + data.status + "</pre>"
$(".response_body", $(@el)).html response_body
$(".response_headers", $(@el)).html "<pre>" + data.getAllResponseHeaders() + "</pre>"
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(data.getHeaders()) + "</pre>"
$(".response", $(@el)).slideDown()
$(".response_hider", $(@el)).show()
$(".response_throbber", $(@el)).hide()
hljs.highlightBlock($('.response_body', $(@el))[0])
toggleOperationContent: ->
elem = $('#' + Docs.escapeResourceName(@model.resourceName) + "_" + @model.nickname + "_" + @model.httpMethod + "_" + @model.number + "_content")
elem = $('#' + Docs.escapeResourceName(@model.resourceName) + "_" + @model.nickname + "_" + @model.method + "_" + @model.number + "_content")
if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem)
@@ -0,0 +1,14 @@
class ParameterContentTypeView extends Backbone.View
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
$('label[for=parameterContentType]', $(@el)).text('Parameter content type:')
@
template: ->
Handlebars.templates.parameter_content_type
@@ -2,8 +2,9 @@ class ParameterView extends Backbone.View
initialize: ->
render: ->
type = @model.type || @model.dataType
@model.isBody = true if @model.paramType == 'body'
@model.isFile = true if @model.dataType == 'file'
@model.isFile = true if type.toLowerCase() == 'file'
template = @template()
$(@el).html(template(@model))
@@ -19,18 +20,23 @@ class ParameterView extends Backbone.View
else
$('.model-signature', $(@el)).html(@model.signature)
isParam = false
if @model.isBody
isParam = true
contentTypeModel =
isParam: false
isParam: isParam
# support old syntax
if @model.supportedContentTypes
contentTypeModel.produces = @model.supportedContentTypes
contentTypeModel.consumes = @model.consumes
if @model.produces
contentTypeModel.produces = @model.produces
if isParam
parameterContentTypeView = new ParameterContentTypeView({model: contentTypeModel})
$('.parameter-content-type', $(@el)).append parameterContentTypeView.render().el
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
else
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
@
@@ -2,6 +2,7 @@ class ResourceView extends Backbone.View
initialize: ->
render: ->
console.log @model.description
$(@el).html(Handlebars.templates.resource(@model))
@number = 0
@@ -0,0 +1,14 @@
class ResponseContentTypeView extends Backbone.View
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
$('label[for=responseContentType]', $(@el)).text('Response Content Type')
@
template: ->
Handlebars.templates.response_content_type
+23
View File
@@ -1756,4 +1756,27 @@ pre code {
.message-fail {
color: #cc0000;
}
.info_title {
padding-bottom: 10px;
font-weight: bold;
font-size: 25px;
}
.info_description {
padding-bottom: 10px;
font-size: 15px;
}
.info_tos {
padding-bottom: 5px;
}
.info_license {
padding-bottom: 5px;
}
.info_contact {
padding-bottom: 5px;
}
+61 -58
View File
@@ -1,74 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href='//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>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<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>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script type="text/javascript" src="lib/shred.bundle.js" /></script>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.0.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<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>
<script type="text/javascript">
$(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){
if(console) {
console.log("Loaded SwaggerUI")
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json",
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
console.log("added key " + key);
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.swaggerUi.load();
});
window.swaggerUi.load();
});
</script>
</script>
</head>
<body>
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl"
type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
&nbsp;
&nbsp;
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">
+2 -2
View File
@@ -1,10 +1,10 @@
<label for="contentType"></label>
<select name="contentType">
{{#if produces}}
{{#each produces}}
{{#each produces}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
{{else}}
<option value="application/json">application/json</option>
<option value="application/json">application/json</option>
{{/if}}
</select>
+9 -1
View File
@@ -1,4 +1,12 @@
<div class='info' id='api_info'>
{{#if info}}
<div class="info_title">{{info.title}}</div>
<div class="info_description">{{{info.description}}}</div>
{{#if info.termsOfServiceUrl}}<div class="info_tos"><a href="{{info.termsOfServiceUrl}}">Terms of service</a></div>{{/if}}
{{#if info.contact}}<div class='info_contact'><a href="mailto:{{info.contact}}">Contact the developer</a></div>{{/if}}
{{#if info.license}}<div class='info_license'><a href='{{info.licenseUrl}}'>{{info.license}}</a></div>{{/if}}
{{/if}}
</div>
<div class='container' id='resources_container'>
<ul id='resources'>
</ul>
+83 -83
View File
@@ -1,85 +1,85 @@
<ul class='operations' >
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}'>
<div class='heading'>
<h3>
<span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{httpMethod}}</a>
</span>
<span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{path}}</a>
</span>
</h3>
<ul class='options'>
<li>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
</li>
</ul>
</div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}_content' style='display:none'>
{{#if notes}}
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
{{/if}}
{{#if responseClass}}
<h4>Response Class</h4>
<p><span class="model-signature" /></p>
<br/>
<div class="content-type" />
{{/if}}
<form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div>
{{#if parameters}}
<h4>Parameters</h4>
<table class='fullwidth'>
<thead>
<tr>
<th style="width: 100px; max-width: 100px">Parameter</th>
<th style="width: 310px; max-width: 310px">Value</th>
<th style="width: 200px; max-width: 200px">Description</th>
<th style="width: 100px; max-width: 100px">Parameter Type</th>
<th style="width: 220px; max-width: 230px">Data Type</th>
</tr>
</thead>
<tbody class="operation-params">
<ul class='operations' >
<li class='{{method}} operation' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}'>
<div class='heading'>
<h3>
<span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{method}}</a>
</span>
<span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{path}}</a>
</span>
</h3>
<ul class='options'>
<li>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
</li>
</ul>
</div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}_content' style='display:none'>
{{#if notes}}
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
{{/if}}
{{#if type}}
<h4>Response Class</h4>
<p><span class="model-signature" /></p>
<br/>
<div class="response-content-type" />
{{/if}}
<form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div>
{{#if parameters}}
<h4>Parameters</h4>
<table class='fullwidth'>
<thead>
<tr>
<th style="width: 100px; max-width: 100px">Parameter</th>
<th style="width: 310px; max-width: 310px">Value</th>
<th style="width: 200px; max-width: 200px">Description</th>
<th style="width: 100px; max-width: 100px">Parameter Type</th>
<th style="width: 220px; max-width: 230px">Data Type</th>
</tr>
</thead>
<tbody class="operation-params">
</tbody>
</table>
{{/if}}
{{#if errorResponses}}
<div style='margin:0;padding:0;display:inline'></div>
<h4>Error Status Codes</h4>
<table class='fullwidth'>
<thead>
<tr>
<th>HTTP Status Code</th>
<th>Reason</th>
</tr>
</thead>
<tbody class="operation-status">
</tbody>
</table>
{{/if}}
{{#if isReadOnly}}
{{else}}
<div class='sandbox_header'>
<input class='submit' name='commit' type='button' value='Try it out!' />
<a href='#' class='response_hider' style='display:none'>Hide Response</a>
<img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />
</div>
{{/if}}
</form>
<div class='response' style='display:none'>
<h4>Request URL</h4>
<div class='block request_url'></div>
<h4>Response Body</h4>
<div class='block response_body'></div>
<h4>Response Code</h4>
<div class='block response_code'></div>
<h4>Response Headers</h4>
<div class='block response_headers'></div>
</div>
</div>
</li>
</ul>
</tbody>
</table>
{{/if}}
{{#if responseMessages}}
<div style='margin:0;padding:0;display:inline'></div>
<h4>Error Status Codes</h4>
<table class='fullwidth'>
<thead>
<tr>
<th>HTTP Status Code</th>
<th>Reason</th>
</tr>
</thead>
<tbody class="operation-status">
</tbody>
</table>
{{/if}}
{{#if isReadOnly}}
{{else}}
<div class='sandbox_header'>
<input class='submit' name='commit' type='button' value='Try it out!' />
<a href='#' class='response_hider' style='display:none'>Hide Response</a>
<img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />
</div>
{{/if}}
</form>
<div class='response' style='display:none'>
<h4>Request URL</h4>
<div class='block request_url'></div>
<h4>Response Body</h4>
<div class='block response_body'></div>
<h4>Response Code</h4>
<div class='block response_code'></div>
<h4>Response Headers</h4>
<div class='block response_headers'></div>
</div>
</div>
</li>
</ul>
+2 -2
View File
@@ -4,13 +4,14 @@
{{#if isBody}}
{{#if isFile}}
<input type="file" name='{{name}}'/>
<div class="parameter-content-type" />
{{else}}
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' name='{{name}}'></textarea>
<br />
<div class="content-type" />
<div class="parameter-content-type" />
{{/if}}
{{/if}}
{{else}}
@@ -27,4 +28,3 @@
<td>
<span class="model-signature"></span>
</td>
+20 -17
View File
@@ -1,22 +1,25 @@
<td class='code'>{{name}}</td>
<td>
<select class='parameter' name='{{name}}'>
{{#if required}}
{{else}}
{{#if defaultValue}}
{{else}}
<option selected="" value=''></option>
{{/if}}
{{/if}}
{{#each allowableValues.descriptiveValues}}
{{#if isDefault}}
<option value='{{value}}'>{{value}} (default)</option>
{{else}}
<option value='{{value}}'>{{value}}</option>
{{/if}}
{{/each}}
</select>
<select {{#if allowMultiple}} multiple='multiple'{{/if}} class='parameter' name='{{name}}'>
{{#if required}}
{{else}}
{{#if defaultValue}}
{{else}}
{{#if allowMultiple}}
{{else}}
<option selected="" value=''></option>
{{/if}}
{{/if}}
{{/if}}
{{#each allowableValues.descriptiveValues}}
{{#if isDefault}}
<option selected="" value='{{value}}'>{{value}} (default)</option>
{{else}}
<option value='{{value}}'>{{value}}</option>
{{/if}}
{{/each}}
</select>
</td>
<td>{{{description}}}</td>
<td>{{{paramType}}}</td>
<td><span class="model-signature"></span></td>
<td><span class="model-signature"></span></td>
+1 -1
View File
@@ -9,7 +9,7 @@
{{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<br />
<div class="content-type" />
<div class="parameter-content-type" />
{{/if}}
{{/if}}
{{else}}
@@ -0,0 +1,10 @@
<label for="parameterContentType"></label>
<select name="parameterContentType">
{{#if consumes}}
{{#each consumes}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
{{else}}
<option value="application/json">application/json</option>
{{/if}}
</select>
+22 -22
View File
@@ -1,26 +1,26 @@
<div class='heading'>
<h2>
<a href='#!/{{name}}' onclick="Docs.toggleEndpointListForResource('{{name}}');">/{{name}}</a>
</h2>
<ul class='options'>
<li>
<a href='#!/{{name}}' id='endpointListTogger_{{name}}'
onclick="Docs.toggleEndpointListForResource('{{name}}');">Show/Hide</a>
</li>
<li>
<a href='#' onclick="Docs.collapseOperationsForResource('{{name}}'); return false;">
List Operations
</a>
</li>
<li>
<a href='#' onclick="Docs.expandOperationsForResource('{{name}}'); return false;">
Expand Operations
</a>
</li>
<li>
<a href='{{url}}'>Raw</a>
</li>
</ul>
<h2>
<a href='#!/{{name}}' onclick="Docs.toggleEndpointListForResource('{{name}}');">{{name}}</a> {{#description}} : {{/description}}{{{description}}}
</h2>
<ul class='options'>
<li>
<a href='#!/{{name}}' id='endpointListTogger_{{name}}'
onclick="Docs.toggleEndpointListForResource('{{name}}');">Show/Hide</a>
</li>
<li>
<a href='#' onclick="Docs.collapseOperationsForResource('{{name}}'); return false;">
List Operations
</a>
</li>
<li>
<a href='#' onclick="Docs.expandOperationsForResource('{{name}}'); return false;">
Expand Operations
</a>
</li>
<li>
<a href='{{url}}'>Raw</a>
</li>
</ul>
</div>
<ul class='endpoints' id='{{name}}_endpoint_list' style='display:none'>
@@ -0,0 +1,10 @@
<label for="responseContentType"></label>
<select name="responseContentType">
{{#if produces}}
{{#each produces}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
{{else}}
<option value="application/json">application/json</option>
{{/if}}
</select>
+1 -2
View File
@@ -1,3 +1,2 @@
<td width='15%' class='code'>{{code}}</td>
<td>{{{reason}}}</td>
<td>{{{message}}}</td>
+2 -3
View File
@@ -1,5 +1,4 @@
window.api_key = 'a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5'
window.discoveryUrl = "http://api.wordnik.com/v4/resources.json"
window.url = "http://api.wordnik.com/v4/resources.json"
describe 'SwaggerUi', ->
@@ -8,7 +7,7 @@ describe 'SwaggerUi', ->
beforeEach ->
window.ui = new SwaggerUi
api_key: window.api_key
discoveryUrl: window.discoveryUrl
url: window.url
waitsFor ->
ui.ready