looker/swagger-ui

Name: swagger-ui

Owner: looker

Description: Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

Created: 2014-12-10 00:06:45.0

Updated: 2016-01-22 02:23:11.0

Pushed: 2018-01-08 20:30:17.0

Homepage: http://swagger.io

Size: 5899

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Swagger UI

Swagger UI is part of the Swagger 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 API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.

What's Swagger?

The goal of Swagger? is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.

Check out Swagger-Spec for additional information about the Swagger project, including additional libraries with support for other languages and more.

Compatibility

The Swagger Specification has undergone 3 revisions since initial creation in 2010. Compatibility between swagger-ui and the Swagger specification is as follows:

Swagger UI Version | Release Date | Swagger Spec compatibility | Notes | Status —————— | ———— | ————————– | —– | —— 2.1.0-alpha.1 (in development) | 2014-10-06 | 1.1, 1.2, 2.0 | master | Issues 2.0.24 | 2014-09-12 | 1.1, 1.2 | tag v2.0.24 | 1.0.13 | 2013-03-08 | 1.1, 1.2 | tag v1.0.13 | 1.0.1 | 2011-10-11 | 1.0, 1.1 | tag v1.0.1 |

How to Use It
Download

You can use the swagger-ui code AS-IS! No need to build or recompile–just clone this repo and use the pre-built files in the dist folder. If you like swagger-ui as-is, stop here.

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. install handlebars
  2. npm install
  3. npm run-script build
  4. 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 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:

SwaggerUi

To use swagger-ui you should take a look at the source of swagger-ui html page and customize it. This basically requires you to instantiate a SwaggerUi object and call load() on it as below:

window.swaggerUi = new SwaggerUi({
    url:"http://petstore.swagger.wordnik.com/api/api-docs",
    dom_id:"swagger-ui-container"
});

window.swaggerUi.load();
HTTP Methods and API Invocation

swagger-ui supports invocation of all HTTP methods APIs including GET, PUT, POST, DELETE, PATCH, OPTIONS. These are handled in the swagger-js project, please see there for specifics on their usage.

Header Parameters

Header params are supported through a pluggable mechanism in swagger-js. You can see the index.html for a sample of how to dynamically set headers:

dd a new ApiKeyAuthorization when the api-key changes in the ui.
input_apiKey').change(function() {
r key = $('#input_apiKey')[0].value;
(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:

ow.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX", "header"));

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

Create your own fork of swagger-api/swagger-ui

To share your changes, submit a pull request.

Since the javascript files are compiled from coffeescript, please submit changes in the *.coffee files! We have to reject changes only in the .js files as they will be lost on each build of the ui.

License

Copyright 2011-2014 Reverb technologies, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.