Skip to content

Commit

Permalink
fix(swagger): removed id property from swagger and updated the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfede committed Mar 30, 2017
1 parent afffd3a commit e2bc265
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,15 @@ export class API implements Swagger {
out.host = req.headers['host'];
out.basePath = req.baseUrl;
let proto = this.schemes && this.schemes.length ? this.schemes[0] : 'http';
out.id = proto + '://' + out.host + out.basePath + '/swagger.json#';
let id = proto + '://' + out.host + out.basePath + '/swagger.json#';
if (originalSwagger.securityDefinitions) {
_.each(originalSwagger.securityDefinitions, (i:any, k) => {
if (k) {
if (i.authorizationUrl) {
out.securityDefinitions[k].authorizationUrl = jr.normalizeUri(i.authorizationUrl, out.id, true);
out.securityDefinitions[k].authorizationUrl = jr.normalizeUri(i.authorizationUrl, id, true);
}
if (i.tokenUrl) {
out.securityDefinitions[k].tokenUrl = jr.normalizeUri(i.tokenUrl, out.id, true);
out.securityDefinitions[k].tokenUrl = jr.normalizeUri(i.tokenUrl, id, true);
}
}
});
Expand Down
42 changes: 2 additions & 40 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,45 +166,13 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('');
data.id.should.equal('https://' + host + '/swagger.json#');
should.not.exist(data.id);
should.not.exist(data.tags);
});
});

it('should return a swagger with an http basePath if that\'s the only scheme', function() {
api.schemes = [ 'http' ];
return request
.get('/swagger.json')
.expect(200)
.expect('Content-Type', /json/)
.then(({ body: data }) => {
data.id.should.equal('http://' + host + '/swagger.json#');
});
});

it('should return a swagger with an http basePath if no scheme is defined (empty array)', function() {
api.schemes = [ ];
return request
.get('/swagger.json')
.expect(200)
.expect('Content-Type', /json/)
.then(({ body: data }) => {
data.id.should.equal('http://' + host + '/swagger.json#');
});
});

it('should return a swagger with an http basePath if no scheme is defined (no array)', function() {
delete api.schemes;
return request
.get('/swagger.json')
.expect(200)
.expect('Content-Type', /json/)
.then(({ body: data }) => {
data.id.should.equal('http://' + host + '/swagger.json#');
});
});

it('should normalize oauth2 urls in security definitions', function() {
delete api.schemes;
return request
.get('/swagger.json')
.expect(200)
Expand Down Expand Up @@ -304,7 +272,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('/v3');
data.id.should.equal('https://' + host + '/v3/swagger.json#');
});
});

Expand All @@ -321,7 +288,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('/v4');
data.id.should.equal('https://' + host + '/v4/swagger.json#');
});
});
});
Expand Down Expand Up @@ -386,7 +352,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('');
data.id.should.equal('http://' + host + '/swagger.json#');
data.schemes.should.deep.equal([ 'http' ]);
});
});
Expand Down Expand Up @@ -415,7 +380,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('');
data.id.should.equal('https://' + host + '/swagger.json#');
data.schemes.should.deep.equal([ 'https' ]);
});
});
Expand Down Expand Up @@ -449,7 +413,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal(host);
data.basePath.should.equal('');
data.id.should.equal('https://' + host + '/swagger.json#');
data.schemes.should.deep.equal([ 'https', 'http' ]);
}),
supertest('https://localhost:' + (port + 2))
Expand All @@ -461,7 +424,6 @@ describe('API', function() {
data.swagger.should.equal('2.0');
data.host.should.equal('localhost:' + (port + 2));
data.basePath.should.equal('');
data.id.should.equal('https://localhost:' + (port + 2) + '/swagger.json#');
data.schemes.should.deep.equal([ 'https', 'http' ]);
})
]);
Expand Down

0 comments on commit e2bc265

Please sign in to comment.