Skip to content

Commit 935252b

Browse files
committed
added tags description support for #243
1 parent fdf2f1a commit 935252b

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

lib/swagger-client.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
433433
// legacy support
434434
this.authSchemes = response.securityDefinitions;
435435

436-
var location;
436+
var definedTags = {};
437+
if(Array.isArray(response.tags)) {
438+
definedTags = {};
439+
for(k = 0; k < response.tags.length; k++) {
440+
var t = response.tags[k];
441+
definedTags[t.name] = t;
442+
}
443+
}
437444

445+
var location;
438446
if(typeof this.url === 'string') {
439447
location = this.parseUri(this.url);
440448
}
@@ -500,8 +508,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
500508
operationGroup.operations = {};
501509
operationGroup.label = tag;
502510
operationGroup.apis = [];
511+
var tagObject = definedTags[tag];
512+
if(typeof tagObject === 'object') {
513+
operationGroup.description = tagObject.description;
514+
operationGroup.externalDocs = tagObject.externalDocs;
515+
}
503516
this[tag].help = this.help.bind(operationGroup);
504-
this.apisArray.push(new OperationGroup(tag, operationObject));
517+
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
505518
}
506519
operationGroup[operationId] = operationObject.execute.bind(operationObject);
507520
operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -570,9 +583,11 @@ SwaggerClient.prototype.fail = function(message) {
570583
throw message;
571584
};
572585

573-
var OperationGroup = function(tag, operation) {
586+
var OperationGroup = function(tag, description, externalDocs, operation) {
574587
this.tag = tag;
575588
this.path = tag;
589+
this.description = description;
590+
this.externalDocs = externalDocs;
576591
this.name = tag;
577592
this.operation = operation;
578593
this.operationsArray = [];

lib/swagger-client.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/swagger-a.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
130130
// legacy support
131131
this.authSchemes = response.securityDefinitions;
132132

133-
var location;
133+
var definedTags = {};
134+
if(Array.isArray(response.tags)) {
135+
definedTags = {};
136+
for(k = 0; k < response.tags.length; k++) {
137+
var t = response.tags[k];
138+
definedTags[t.name] = t;
139+
}
140+
}
134141

142+
var location;
135143
if(typeof this.url === 'string') {
136144
location = this.parseUri(this.url);
137145
}
@@ -197,8 +205,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
197205
operationGroup.operations = {};
198206
operationGroup.label = tag;
199207
operationGroup.apis = [];
208+
var tagObject = definedTags[tag];
209+
if(typeof tagObject === 'object') {
210+
operationGroup.description = tagObject.description;
211+
operationGroup.externalDocs = tagObject.externalDocs;
212+
}
200213
this[tag].help = this.help.bind(operationGroup);
201-
this.apisArray.push(new OperationGroup(tag, operationObject));
214+
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
202215
}
203216
operationGroup[operationId] = operationObject.execute.bind(operationObject);
204217
operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -267,9 +280,11 @@ SwaggerClient.prototype.fail = function(message) {
267280
throw message;
268281
};
269282

270-
var OperationGroup = function(tag, operation) {
283+
var OperationGroup = function(tag, description, externalDocs, operation) {
271284
this.tag = tag;
272285
this.path = tag;
286+
this.description = description;
287+
this.externalDocs = externalDocs;
273288
this.name = tag;
274289
this.operation = operation;
275290
this.operationsArray = [];

test/request.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ describe('swagger request functions', function() {
2020
});
2121

2222
it('gets the resource description', function() {
23-
var storeApi = sample.apisArray[1];
24-
var req = storeApi.description;
23+
var userApi = sample.user;
24+
expect(userApi.description).toEqual('All about the Users');
25+
});
2526

26-
expect(req).toBe.undefined;
27+
it('gets the resource external docs', function() {
28+
var petApi = sample.pet;
29+
expect(petApi.description).toEqual('Pet Operations');
30+
expect(petApi.externalDocs).toEqual('http://swagger.io');
2731
});
2832

2933
it('generate a get request', function() {

test/spec/v2/petstore.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
"schemes": [
1919
"http"
2020
],
21+
"tags" : [
22+
{
23+
"name": "pet",
24+
"description": "Pet Operations",
25+
"externalDocs": "http://swagger.io"
26+
}, {
27+
"name": "user",
28+
"description": "All about the Users"
29+
}
30+
],
2131
"paths": {
2232
"/pet": {
2333
"post": {

0 commit comments

Comments
 (0)