How to use swagger-client - 10 common examples

To help you get started, we’ve selected a few swagger-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github couchbaselabs / react-native-couchbase-lite / index.js View on Github external
Couchbase.init(url => {
  spec.host = url.split('/')[2];

  new Swagger({spec: spec, usePromise: true})
    .then(client => {
      var encodedCredentials = "Basic " + base64.encode(url.split("//")[1].split('@')[0]);
      client.clientAuthorizations.add("auth", new Swagger.ApiKeyAuthorization('Authorization', encodedCredentials, 'header'));
      manager = client;
      if (typeof callback == 'function') {
        callback(manager);
      }
    });

  // stop and start are needed because the OS appears to kill the listener when the app
  // becomes inactive (when the screen is locked, or its put in the background)
  AppState.addEventListener('change', (appState) => {
    if (String(appState).match(/inactive|background/)) {
      Couchbase.stopListener();
    } else if (String(appState).match(/active/)) {
      Couchbase.startListener();
github apigee-127 / bagpipes / lib / fittingTypes / swagger.js View on Github external
module.exports = function createFitting(pipes, fittingDef) {

  assert(fittingDef.url, util.format('url is required on fitting: %j', fittingDef));

  var client = require('swagger-client');
  var swagger = new client.SwaggerClient({
    url: fittingDef.url,
    success: function() {
      debug('swaggerjs initialized');
    },
    failure: function(err) {
      console.log('swaggerjs', err); // todo: what?
    },
    progress: function(msg) {
      debug('swaggerjs', msg);
    }
  });
  swagger.build();

  return function(context, next) {
    var api = swagger.apis[context.input.api];
    var operation = api[context.input.operation];
github apispots / apispots-extension / src / lib / openapi / api-definition.js View on Github external
], (e) => {

          if (e) {
            reject(e);
          } else {

            // if spec is provided as a string,
            // convert it to an object
            if (typeof spec === 'string') {
              spec = jsyaml.load(spec);
            }

            // try to resolve the API definition
            // using either a URI or a spec
            new Swagger({
              url,
              spec
            })
              .then((openapi) => {
                const api = new ApiDefinition(openapi);

                // set the original Url of the definition
                api.specUrl = originalUrl;

                if (_.isEmpty(api.spec)) {
                  reject(new Error('Invalid Open API specification'));
                } else {
                  // return the API instance
                  resolve(api);
                }
              }, (err) => {
github wso2 / carbon-apimgt / components / web / apps / org.wso2.carbon.apimgt.publisher_originaluufapp / src / main / pages / src / app / data / api.js View on Github external
constructor(access_key) {
        this.client = new SwaggerClient({
            url: this._getSwaggerURL(),
            usePromise: true,
            requestInterceptor: this._getRequestInterceptor(),
            responseInterceptor: this._getResponseInterceptor()
        });
        this.auth_client = new AuthClient();
        this.client.then(
            (swagger) => {
                swagger.setHost(window.location.host);
                this.keyMan = new KeyManager(access_key);
                let scopes = swagger.swaggerObject["x-wso2-security"].apim["x-wso2-scopes"];
                for (let index in scopes) {
                    if (scopes.hasOwnProperty(index)) {
                        let scope_key = scopes[index].key;
                        this.keyMan.addKey(null, scope_key);
                        /* Fill with available scopes */
github openstf / stf-appium-example / scripts / stf_disconnect.js View on Github external
var Swagger = require('swagger-client');

var SWAGGER_URL = 'http://localhost:7100/api/v1/swagger.json'
var AUTH_TOKEN  = '03f5e019a2f94a35b90c30e40829395b5a0d0f0e7fd14bc496a176b03e229540';


var client = new Swagger({
  url: SWAGGER_URL
, usePromise: true
, authorizations: {
    accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + AUTH_TOKEN, 'header')
  }
})

var serial = process.argv.slice(2)[0]

client.then(function(api) {
  return api.user.getUserDevices({
    serial: serial
  , fields: 'serial,present,ready,using,owner'
  }).then(function(res) {
      // check if device can be added or not
      var devices = res.obj.devices

      var hasDevice = false
      devices.forEach(function(device) {
        if(device.serial === serial) {
github se02035 / Viber-and-the-Microsoft-Bot-Framework / source / microsoftBotConnectorNew.js View on Github external
}).then((client) => {
                logger.debug('Swagger client ready');

                // add authorization header
                client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'BotConnector ' + directLineSecret, 'header'));
                return client;
            }).catch((err) =>
                logger.error('Error initializing DirectLine client', err));
github microsoft / BotBuilder-Samples / Node / core-DirectLine / DirectLineClient / app.js View on Github external
.then(function (client) {
        // add authorization header to client
        client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + directLineSecret, 'header'));
        return client;
    })
    .catch(function (err) {
github wso2 / carbon-apimgt / components / web / apps / org.wso2.carbon.apimgt.publisher_originaluufapp / src / main / pages / src / app / data / api.js View on Github external
_requestMetaData(data = {}) {
        AuthClient.refreshTokenOnExpire();
        let access_key_header = "Bearer " + AuthClient.getCookie("WSO2_AM_TOKEN_1");
        let request_meta = {
            clientAuthorizations: {
                am_token1: new SwaggerClient.ApiKeyAuthorization("Authorization", access_key_header, "header")
            },
            requestContentType: data['Content-Type'] || "application/json"
        };
        let am_token2 = AuthClient.getCookie('WSO2_AM_TOKEN_MSF4J'); // This cookie is meant to be send via browser, Hence this will be overridden by browser
        if (am_token2) {
            request_meta.clientAuthorizations['am_token2'] = new SwaggerClient.ApiKeyAuthorization("Cookie", "WSO2_AM_TOKEN_MSF4J=" + am_token2, "header")
        }
        return request_meta;
    }
github wso2 / carbon-apimgt / features / apimgt / org.wso2.carbon.apimgt.publisher.feature / src / main / resources / publisher / source / src / app / data / api.js View on Github external
_requestMetaData(data = {}) {
        AuthClient.refreshTokenOnExpire();
        let access_key_header = "Bearer " + AuthClient.getUser().getPartialToken(); // Anti-CSRF token
        let request_meta = {
            clientAuthorizations: {
                am_token1: new SwaggerClient.ApiKeyAuthorization("Authorization", access_key_header, "header")
            },
            requestContentType: data['Content-Type'] || "application/json"
        };
        let am_token2 = Utils.getCookie('WSO2_AM_TOKEN_MSF4J'); // This cookie is meant to be send via browser, Hence this will be overridden by browser
        if (am_token2) {
            request_meta.clientAuthorizations['am_token2'] = new SwaggerClient.ApiKeyAuthorization("Cookie", "WSO2_AM_TOKEN_MSF4J=" + am_token2, "header")
        }
        return request_meta;
    }
github asterisk / node-ari-client / lib / client.js View on Github external
return new Promise(function(resolve, reject) {

    swagger.authorizations.add(
      'basic-auth',
      new swagger.PasswordAuthorization(
        self._connection.hostname,
        self._connection.user,
        self._connection.pass
      )
    );

    // Connect to API using swagger and attach resources on Client instance
    var ariUrl = util.format(
      '%s//%s/ari/api-docs/resources.json',
      self._connection.protocol,
      self._connection.host
    );

    request(ariUrl, function (err) {
      if (err &&
        ['ETIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED'].indexOf(err.code) !== -1) {