swagger-client 2.1.29 → 2.2.21
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 +5 -77
- package/browser/swagger-client.js +215 -323
- package/browser/swagger-client.min.js +8 -8
- package/lib/auth.js +1 -1
- package/lib/client.js +12 -57
- package/lib/helpers.js +2 -23
- package/lib/http.js +31 -22
- package/lib/resolver.js +97 -101
- package/lib/schema-markup.js +17 -10
- package/lib/spec-converter.js +1 -3
- package/lib/types/operation.js +41 -94
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ var client = new Swagger({
|
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
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
|
|
40
40
|
there is more than one content type available.
|
|
41
41
|
|
|
42
42
|
That's it! You'll get a JSON response with the default callback handler:
|
|
@@ -106,50 +106,17 @@ new Swagger({
|
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
|
-
### Authorization
|
|
110
109
|
|
|
111
|
-
Need to pass an API key?
|
|
112
|
-
|
|
113
|
-
```yaml
|
|
114
|
-
# ...
|
|
115
|
-
|
|
116
|
-
securityDefinitions:
|
|
117
|
-
|
|
118
|
-
api_scheme_name: # swagger scheme name
|
|
119
|
-
type: apiKey # swagger type (one of "basic", "apiKey" or "oauth2")
|
|
120
|
-
name: queryParamName # The name of the header or query parameter to be used
|
|
121
|
-
in: query # location of the API key
|
|
122
|
-
|
|
123
|
-
api_scheme_name_2:
|
|
124
|
-
type: apiKey
|
|
125
|
-
name: X-KEY-PARAM
|
|
126
|
-
in: header
|
|
127
|
-
|
|
128
|
-
# ...
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Configure auth for that definition in your client instance as a *query string*:
|
|
110
|
+
Need to pass an API key? Configure one in your client instance as a query string:
|
|
132
111
|
|
|
133
112
|
```js
|
|
134
|
-
client.clientAuthorizations.add("
|
|
135
|
-
new Swagger.ApiKeyAuthorization(
|
|
136
|
-
"queryParamName",
|
|
137
|
-
"<YOUR-SECRET-KEY>",
|
|
138
|
-
"query"
|
|
139
|
-
)
|
|
140
|
-
);
|
|
113
|
+
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","query"));
|
|
141
114
|
```
|
|
142
115
|
|
|
143
|
-
...or with a
|
|
116
|
+
...or with a header:
|
|
144
117
|
|
|
145
118
|
```js
|
|
146
|
-
client.clientAuthorizations.add("
|
|
147
|
-
new Swagger.ApiKeyAuthorization(
|
|
148
|
-
"X-KEY-PARAM",
|
|
149
|
-
"<YOUR-SECRET-KEY>",
|
|
150
|
-
"header"
|
|
151
|
-
)
|
|
152
|
-
);
|
|
119
|
+
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","header"));
|
|
153
120
|
```
|
|
154
121
|
|
|
155
122
|
...or with the swagger-client constructor:
|
|
@@ -332,45 +299,6 @@ var client = new SwaggerClient({
|
|
|
332
299
|
});
|
|
333
300
|
```
|
|
334
301
|
|
|
335
|
-
You can also pass in your own version superagent (if, for example, you have other superagent plugins etc that you want to use)
|
|
336
|
-
|
|
337
|
-
var agent = require('some-other-special-superagent');
|
|
338
|
-
|
|
339
|
-
var client = new SwaggerClient({
|
|
340
|
-
spec: petstoreRaw,
|
|
341
|
-
requestAgent: agent,
|
|
342
|
-
success: function () {
|
|
343
|
-
client.pet.getPetById({petId: 3}, function(data){
|
|
344
|
-
expect(data).toBe('ok');
|
|
345
|
-
done();
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
### Using custom http(s) agent
|
|
352
|
-
In case if you need to sign all requests to petstore with custom certificate
|
|
353
|
-
|
|
354
|
-
```js
|
|
355
|
-
var connectionAgent = {
|
|
356
|
-
rejectUnauthorized: false,
|
|
357
|
-
key: "/certs/example.key",
|
|
358
|
-
cert: "/certs/example.pem",
|
|
359
|
-
ca: ["/certs/example.ca.pem"]
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
var client = new SwaggerClient({
|
|
363
|
-
url: "http://petstore.swagger.io/v2/swagger.json",
|
|
364
|
-
connectionAgent: connectionAgent,
|
|
365
|
-
success: function() {
|
|
366
|
-
// upon connect, fetch a pet and set contents to element "mydata"
|
|
367
|
-
client.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) {
|
|
368
|
-
document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
```
|
|
373
|
-
|
|
374
302
|
### How does it work?
|
|
375
303
|
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:
|
|
376
304
|
|