GithubHelp home page GithubHelp logo

classicvalues / ember-swagger-ui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rynam0/ember-swagger-ui

0.0 1.0 0.0 470 KB

An Ember addon for quickly and easily adding a swagger-ui to your Ember App.

Home Page: http://rynam0.github.io/ember-swagger-ui/

License: MIT License

JavaScript 92.02% HTML 4.30% Shell 1.00% CSS 2.44% Handlebars 0.24%

ember-swagger-ui's Introduction

ember-swagger-ui

Build Status npm version Ember Observer Score

An ember-cli addon for quickly and easily adding swagger-ui components to your ember application.

Screenshot

Installation

$ ember install ember-swagger-ui

ember-swagger-ui >= 1.0.0

About

As of version 1.0.0, the addon is based on swagger-ui 3.x. Some notable differences from previous versions include:

  • A simplified component API
  • No Bower dependencies

Configuration

Configuring a component is done by passing a config object to the component's config attribute. The object takes any and all supported swagger-ui 3.x configuration

// controllers/application.js

import Controller from '@ember/controller';
import Swag from 'swagger-ui';

const {
  SwaggerUIBundle,
  SwaggerUIStandalonePreset
} = Swag;

export default Controller.extend({
  swaggerConfig: {
    url: 'http://petstore.swagger.io/v2/swagger.json',
    deepLinking: false,
    presets: [
      SwaggerUIStandalonePreset,
      SwaggerUIBundle.presets.apis,
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",
    docExpansion: 'none',
    tagsSorter: 'alpha',
    operationsSorter: 'alpha',
    defaultModelsExpandDepth: -1,
    defaultModelExpandDepth: 1,
    validatorUrl: 'https://online.swagger.io/validator'
  }
});

Usage

{{!-- application.hbs --}}
{{swagger-ui config=swaggerConfig}}

ember-swagger-ui < 1.0.0 (Pre-releases)

About

Releases preceeding 1.0.0 are based on swagger-ui 2.x and are considered pre-releases.

Many of the swagger-ui configuration properties are available as attributes on the component. The currently supported options are documented below. For more details on each of these options, please refer to the swagger-ui docs:

url

The component's default url is "http://petstore.swagger.io/v2/swagger.json". The following would load the API docs of the default petstore example:

{{swagger-ui}}}

To load your API docs, simply supply the URL of your swagger.json as the "url" attribute value:

{{swagger-ui url="http://petstore.swagger.io/v2/swagger.json"}}

spec

As noted in the swagger-ui docs, you could alternately supply a JSON object that is a valid Swagger definition:

{{swagger-ui spec=mySpec}}

docExpansion

{{swagger-ui docExpansion="list"}}

supportedSubmitMethods

{{swagger-ui supportedSubmitMethods=anArrayOfHttpMethods}}

showRequestHeaders

{{swagger-ui showRequestHeaders=true}}

authorizations

Authorizations are configured in the same manner they would be if pulling in the entire swagger-ui distribution. See below for an example of query parameter apiKey configuration.

A Full Example

{{#swagger-ui showRequestHeaders=true docExpansion="list" supportedSubmitMethods=submitMethods authorizations=authz}}
    <div id='header'>
        <div class="swagger-ui-wrap">
            <a id="logo" href="http://swagger.io">swagger</a>
            <form id='api_selector'>
                <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="#" data-sw-translate>Explore</a></div>
            </form>
        </div>
    </div>
{{/swagger-ui}}
// my-route.js
// set up component attribute values on your controller
setupController(controller) {
  controller.set('submitMethods', ['get', 'post'] );
  controller.set('authz', { name: 'api_key', value: 'myQueryParamApiKey', type: 'query'} );
}

Block syntax

The component supports block syntax to aid in customizing any content necessary to interact with your API documentation. Following is a contrived example of adding basic auth via a form:

{{#swagger-ui}}
  <div>
      <form {{action "submit" on="submit"}}>
          {{input value=user placeholder="Username"}}
          {{input value=pw placeholder="Password" type="password"}}
          {{input type="submit" value="Submit"}}
      </form>
  </div>
{{/swagger-ui}}

// my-route.js
// setup action to handle the form submission and addition of the swagger authorization
actions: {
  submit() {
    let { user, pw } = this.controllerFor('application').getProperties('user', 'pw');
    let creds = window.btoa(user + ':' + pw);
    let basicAuth = new window.SwaggerClient.ApiKeyAuthorization("Authorization", "Basic " + creds, "header");
    window.swaggerUi.api.clientAuthorizations.add("Authorization", basicAuth);
    window.swaggerUi.load();
  }
}

Contributing

Installation

  • git clone <repository-url> this repository
  • cd ember-swagger-ui
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.

ember-swagger-ui's People

Contributors

rynam0 avatar ember-tomster avatar ffissore avatar classicvalues avatar theaxeman301 avatar mend-bolt-for-github[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.