swagger-client 2.1.21 → 2.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Swagger JS library
2
2
 
3
3
  [![Build Status](https://travis-ci.org/swagger-api/swagger-js.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-js)
4
+ [![NPM version](https://badge.fury.io/js/swagger-client.svg)](http://badge.fury.io/js/swagger-client)
4
5
 
5
6
  This is the Swagger javascript client for use with [swagger](http://swagger.io) enabled APIs.
6
7
  It's written in javascript and tested with mocha, and is the fastest way to enable a javascript client to communicate with a swagger-enabled server.
@@ -35,7 +36,7 @@ var client = new Swagger({
35
36
  });
36
37
  ```
37
38
 
38
- NOTE: we're explicitly setting the responseContentType, because we don't want you getting stuck when
39
+ NOTE: we're explicitly setting the responseContentType, because we don't want you getting stuck when
39
40
  there is more than one content type available.
40
41
 
41
42
  That's it! You'll get a JSON response with the default callback handler:
@@ -224,6 +225,46 @@ You can add it to the swagger-client like such:
224
225
  client.clientAuthorizations.add('my-auth', new CustomRequestSigner());
225
226
  ```
226
227
 
228
+ ### Setting headers
229
+
230
+ Headers are a type of `parameter`, and can be passed with the other parameters. For example, if you supported translated pet details via the `Accept-Language` header:
231
+
232
+ ```js
233
+ "parameters": [
234
+ {
235
+ "name": "petId",
236
+ "description": "ID of pet that needs to be fetched",
237
+ "required": true,
238
+ "type": "integer",
239
+ "format": "int64",
240
+ "paramType": "path",
241
+ "minimum": "1.0",
242
+ "defaultValue": 3,
243
+ "maximum": "100000.0"
244
+ },
245
+ "LanguageHeader": {
246
+ "name": "Accept-Language",
247
+ "in": "header",
248
+ "description": "Specify the user's language",
249
+ "required": false,
250
+ "type": "string"
251
+ }
252
+ ...
253
+ ```
254
+
255
+ Then you would pass the header value via the parameters ([header parameters are case-insenstive](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2)):
256
+
257
+ ```js
258
+
259
+ client.pet.getPetById({
260
+ petId: 7,
261
+ 'accept-language': 'fr'
262
+ }, function(pet){
263
+ console.log('pet', pet);
264
+ });
265
+
266
+ ```
267
+
227
268
  ### Using your own HTTP client
228
269
 
229
270
  Don't like [superagent](https://github.com/visionmedia/superagent)? Despise [JQuery](https://github.com/jquery/jquery)? Well, you're in luck. You can plug your own HTTP library easily:
@@ -258,6 +299,45 @@ var client = new SwaggerClient({
258
299
  });
259
300
  ```
260
301
 
302
+ You can also pass in your own version superagent (if, for example, you have other superagent plugins etc that you want to use)
303
+
304
+ var agent = require('some-other-special-superagent');
305
+
306
+ var client = new SwaggerClient({
307
+ spec: petstoreRaw,
308
+ requestAgent: agent,
309
+ success: function () {
310
+ client.pet.getPetById({petId: 3}, function(data){
311
+ expect(data).toBe('ok');
312
+ done();
313
+ });
314
+ }
315
+ });
316
+ ```
317
+
318
+ ### Using custom http(s) agent
319
+ In case if you need to sign all requests to petstore with custom certificate
320
+
321
+ ```js
322
+ var connectionAgent = {
323
+ rejectUnauthorized: false,
324
+ key: "/certs/example.key",
325
+ cert: "/certs/example.pem",
326
+ ca: ["/certs/example.ca.pem"]
327
+ }
328
+
329
+ var client = new SwaggerClient({
330
+ url: "http://petstore.swagger.io/v2/swagger.json",
331
+ connectionAgent: connectionAgent,
332
+ success: function() {
333
+ // upon connect, fetch a pet and set contents to element "mydata"
334
+ client.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) {
335
+ document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
336
+ });
337
+ }
338
+ });
339
+ ```
340
+
261
341
  ### How does it work?
262
342
  The swagger javascript client reads the swagger api definition directly from the server. As it does, it constructs a client based on the api definition, which means it is completely dynamic. It even reads the api text descriptions (which are intended for humans!) and provides help if you need it:
263
343