Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-client

Package Overview
Dependencies
Maintainers
1
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-client - npm Package Compare versions

Comparing version 2.1.8-M1 to 2.1.8

browser/index.html

61

package.json
{
"name": "swagger-client",
"author": "Tony Tam <fehguy@gmail.com>",
"description": "swagger.js is a javascript client for use with swaggering APIs.",
"version": "2.1.8-M1",
"contributors": [
{
"name": "Jeremy Whitlock",
"email": "jcscoobyrs@gmail.com"
}
],
"description": "swagger-client is a javascript client for use with swaggering APIs.",
"version": "2.1.8",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
"url": "git://github.com/swagger-api/swagger-js.git"
"url": "https://github.com/swagger-api/swagger-js.git"
},
"main": "lib/swagger-client.js",
"main": "index.js",
"scripts": {
"build": "gulp build",
"dev": "gulp watch",
"test": "gulp test"
"test": "gulp test",
"browsertest": "gulp browsertest"
},
"files": [
"LICENSE",
"lib",
"browser",
"index.js"
],
"engines": {

@@ -21,22 +34,40 @@ "node": ">= 0.6.6"

"dependencies": {
"shred": "0.8.10",
"btoa": "1.1.1"
"btoa": "^1.1.2",
"cookiejar": "^2.0.1",
"js-yaml": "^3.3.0",
"lodash-compat": "^3.5.0",
"q": "^1.4.1",
"superagent": "^1.2"
},
"devDependencies": {
"async": "^0.9.0",
"brfs": "^1.4.0",
"browserify": "^9.0.3",
"chai": "^2.3.0",
"connect-cors": "^0.5.6",
"del": "^1.1.1",
"expect": "1.4.0",
"faux-jax": "^4.0.0",
"gulp": "^3.8.10",
"gulp-header": "1.2.2",
"gulp-concat": "^2.4.3",
"gulp-buffer": "0.0.2",
"gulp-connect": "^2.2.0",
"gulp-header": "^1.2.2",
"gulp-istanbul": "^0.5.0",
"gulp-jshint": "^1.9.0",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.2",
"gulp-util": "^3.0.1",
"gulp-wrap": "0.10.1",
"http-server": "git://github.com/nodeapps/http-server.git",
"jshint-stylish": "^1.0.1",
"karma": "^0.12.35",
"karma-browserify": "^4.2.1",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.1.10",
"karma-source-map-support": "^1.0.0",
"mocha": "^1.21.3",
"unit.js": "1.1.2"
"object.assign": "^3.0.0",
"selenium-webdriver": "^2.45.1",
"uglifyify": "^3.0.1",
"unit.js": "^2.0.0",
"vinyl-source-stream": "^1.1.0"
},
"license": "apache 2.0"
"license": "Apache-2.0"
}
# Swagger JS library
[![Build Status](https://api.travis-ci.org/swagger-api/swagger-js.png)](https://travis-ci.org/swagger-api/swagger-js)
[![Build Status](https://travis-ci.org/swagger-api/swagger-js.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-js)

@@ -8,7 +8,2 @@ This is the Swagger javascript client for use with [swagger](http://swagger.io) enabled APIs.

## 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, Swager removes the guesswork in calling the service.
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.

@@ -24,15 +19,25 @@

or:
```
bower install swagger-js
```
Then let swagger do the work!
```js
var client = require("swagger-client")
var client = require('swagger-client');
var swagger = new client.SwaggerClient({
url: 'http://petstore.swagger.wordnik.com/v2/swagger.json',
var swagger = new client({
url: 'http://petstore.swagger.io/v2/swagger.json',
success: function() {
swagger.apis.pet.getPetById({petId:1});
swagger.pet.getPetById({petId:7},{responseContentType: 'application/json'},function(pet){
console.log('pet', pet);
});
}
});
```
NOTE: we're explicitly setting the responseContentType, because we don't want you getting stuck when
there is more than one content type available.
That's it! You'll get a JSON response with the default callback handler:

@@ -66,28 +71,82 @@

Need to pass an API key? Configure one as a querystring:
### Handling success and failures
You need to pass success and error functions to do anything reasonable with the responses:
```js
client.authorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","query"));
var client = require('swagger-client');
var swagger = new client({
url: 'http://petstore.swagger.io/v2/swagger.json',
success: function() {
swagger.pet.getPetById({petId:7}, function(success){
console.log('succeeded and returned this object: ' + success.obj);
},
function(error) {
console.log('failed with the following: ' + error.statusText);
});
}
});
```
You can use promises too, by passing the `usePromise: true` option:
```js
var Swagger = require('swagger-client');
new Swagger({
url: 'http://petstore.swagger.io/v2/swagger.json',
usePromise: true
})
.then(function(client) {
client.pet.getPetById({petId:7})
.then(function(pet) {
console.log(pet.obj);
})
.catch(function(error) {
console.log('Oops! failed with message: ' + error.statusText);
});
});
```
Need to pass an API key? Configure one as a query string:
```js
client.clientAuthorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","query"));
```
...or with a header:
```js
client.authorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","header"));
client.clientAuthorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","header"));
```
...or with the swagger-client constructor:
```js
var swagger = new client({
url: 'http://example.com/spec.json',
success: function() {},
authorizations : {
easyapi_basic: new client.PasswordAuthorization('<username>', '<password>'),
someHeaderAuth: new client.ApiKeyAuthorization('<nameOfHeader>', '<value>', 'header'),
someQueryAuth: new client.ApiKeyAuthorization('<nameOfQueryKey>', '<value>', 'query'),
someCookieAuth: new client.CookieAuthorization('<cookie>'),
}
});
```
### Calling an API with swagger + the browser!
Download `swagger-client.js` and `shred.bundle.js` into your lib folder
Download `browser/swagger-client.js` into your webapp:
```js
<script src='lib/shred.bundle.js' type='text/javascript'></script>
<script src='lib/swagger-client.js' type='text/javascript'></script>
<script src='browser/swagger-client.js' type='text/javascript'></script>
<script type="text/javascript">
// initialize swagger, point to a resource listing
window.swagger = new SwaggerClient({
url: "http://petstore.swagger.wordnik.com/api/api-docs",
url: "http://petstore.swagger.io/v2/swagger.json",
success: function() {
// upon connect, fetch a pet and set contents to element "mydata"
swagger.apis.pet.getPetById({petId:1}, function(data) {
swagger.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) {
document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);

@@ -97,4 +156,7 @@ });

});
</script>
</script>
<body>
<div id="mydata"></div>
</body>
```

@@ -108,3 +170,3 @@

swagger.apis.pet.addPet({body: pet});
swagger.pet.addPet({body: pet});
```

@@ -116,3 +178,3 @@

swagger.apis.pet.addPet({body: pet}, {requestContentType:"application/xml"});
swagger.pet.addPet({body: pet}, {requestContentType:"application/xml"});
```

@@ -122,3 +184,3 @@

```js
swagger.apis.pet.getPetById({petId:1}, {responseContentType:"application/xml"});
swagger.pet.getPetById({petId:1}, {responseContentType:"application/xml"});
```

@@ -144,3 +206,3 @@

In the above simple example, we're creating a new request signer that simply
base 64 encodes the URL. Of course you'd do something more sophisticated, but
Base64 encodes the URL. Of course you'd do something more sophisticated, but
after encoding it, a header called `signature` is set before sending the request.

@@ -163,3 +225,3 @@

Please [fork the code](https://github.com/swagger-api/swagger-js) and help us improve
swagger-client.js. Send us a pull request and **we'll mail you a wordnik T-shirt!**
swagger-client.js. Send us a pull request to the `master` branch! Tests make merges get accepted more quickly.

@@ -180,16 +242,19 @@ swagger-js use gulp for Node.js.

# Run the test suite
# Run lint (will not fail if there are errors/warnings), tests (without coverage) and builds the browser binaries
gulp
# Run the test suite (without coverage)
gulp test
# Build the library (minified and unminified) in the dist folder
# Build the browser binaries (One for development with source maps and one that is minified and without source maps) in the browser directory
gulp build
# continuously run the test suite:
# Continuously run the test suite:
gulp watch
# run jshint report
# Run jshint report
gulp lint
# run a coverage report
gulp cover
# Run a coverage report based on running the unit tests
gulp coverage
```

@@ -200,3 +265,3 @@

Copyright 2011-2015 Reverb Technologies, Inc.
Copyright 2011-2015 SmartBear Software

@@ -203,0 +268,0 @@ Licensed under the Apache License, Version 2.0 (the "License");

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc