Skip to content

Commit 6530b7d

Browse files
authored
Merge pull request #934 from swagger-api/issue-903
apply interceptor in mock mode
2 parents 25f45a7 + 0bff277 commit 6530b7d

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

browser/swagger-client.js

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

browser/swagger-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/types/operation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
904904

905905
this.clientAuthorizations.apply(obj, this.operation.security);
906906
if (opts.mock === true) {
907+
if(opts.requestInterceptor) {
908+
opts.requestInterceptor.apply(obj);
909+
}
907910
return obj;
908911
} else {
909912
return new SwaggerHttp().execute(obj, opts);

test/request.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,19 @@ describe('swagger basePath override functions', function () {
510510
});
511511
});
512512

513+
it('applies a request interceptor to asCurl #903', function() {
514+
var petApi = sample.pet;
515+
var requestInterceptor = {
516+
apply: function(data) {
517+
data.url = 'http://localhost:8000/v2/api/pet/1';
518+
return data;
519+
}
520+
};
521+
522+
var curl = petApi.getPetById.asCurl({petId: -100}, {requestInterceptor: requestInterceptor});
523+
expect(curl).toBe('curl -X GET --header \'Accept: application/json\' \'http://localhost:8000/v2/api/pet/1\'');
524+
});
525+
513526
it('applies request interceptor and waits for beforeSend as per #701', function(done) {
514527
this.timeout(10000);
515528
var petApi = sample.pet;

0 commit comments

Comments
 (0)