swagger-client
Advanced tools
Comparing version 2.1.8-M1 to 2.1.8
{ | ||
"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" | ||
} |
129
README.md
# 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2705183
0
31131
1
267
11
2
6
28
17
1
+ Addedcookiejar@^2.0.1
+ Addedjs-yaml@^3.3.0
+ Addedlodash-compat@^3.5.0
+ Addedq@^1.4.1
+ Addedsuperagent@^1.2
+ Addedargparse@1.0.10(transitive)
+ Addedasync@1.5.2(transitive)
+ Addedbtoa@1.2.1(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcomponent-emitter@1.2.1(transitive)
+ Addedcookiejar@2.0.62.1.4(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedextend@3.0.0(transitive)
+ Addedform-data@1.0.0-rc3(transitive)
+ Addedformidable@1.0.17(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedlodash-compat@3.10.2(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.3.4(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.0(transitive)
+ Addedq@1.5.1(transitive)
+ Addedqs@2.3.3(transitive)
+ Addedreadable-stream@1.0.27-1(transitive)
+ Addedreduce-component@1.0.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedsuperagent@1.8.5(transitive)
- Removedshred@0.8.10
- Removedax@0.1.8(transitive)
- Removedbtoa@1.1.1(transitive)
- Removedcookiejar@1.3.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedshred@0.8.10(transitive)
- Removedsprintf@0.1.1(transitive)
Updatedbtoa@^1.1.2