Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions browser/swagger-client.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions browser/swagger-client.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) {
accept: self.scope.swaggerRequestHeaders || 'application/json'
},
on: {
error: function () {
error: function (error) {
processedCalls += 1;
unresolvedRefs[item.key] = {
root: item.root,
Expand Down Expand Up @@ -362,7 +362,7 @@ Resolver.prototype.finish = function (spec, root, resolutionTable, resolvedRefs,
}
var existingUnresolved = this.countUnresolvedRefs(spec);

if(existingUnresolved.length === 0 || this.iteration > 5) {
if(existingUnresolved === 0 || this.iteration > 5) {
this.resolveAllOf(spec.definitions);
callback.call(this.scope, spec, unresolvedRefs);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/spec-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ SwaggerSpecConverter.prototype.responseMessages = function(operation, existingOp
}
// Convert responseModel -> schema{$ref: responseModel}
if(existingResponse.responseModel) {
response.schema = {'$ref': existingResponse.responseModel};
response.schema = {'$ref': '#/definitions/' + existingResponse.responseModel};
}
operation.responses['' + existingResponse.code] = response;
}
Expand Down
2 changes: 1 addition & 1 deletion test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ describe('SwaggerClient', function () {
});
});

it('applies both a request and response interceptor per #601 with promies', function(done) {
it('applies both a request and response interceptor per #601 with promises', function(done) {
var startTime = 0;
var elapsed = 0;

Expand Down
36 changes: 34 additions & 2 deletions test/compat/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('converts specs', function () {

// models
var definitions = swagger.definitions;
expect(Object.keys(definitions).length).toBe(8);
expect(Object.keys(definitions).length).toBe(9);
var pet = definitions.Pet;
expect(Object.keys(pet.properties).length).toBe(8);
var photos = pet.properties.photoUrls;
Expand All @@ -125,6 +125,7 @@ describe('converts specs', function () {
var converter = new SwaggerSpecConverter();
converter.setDocumentationLocation('http://localhost:8001/v1/api-docs');
converter.convert(data.obj, {}, function(swagger) {

// metadata tests
expect(swagger.swagger).toBe('2.0');
test.object(swagger.info);
Expand Down Expand Up @@ -279,7 +280,7 @@ describe('converts specs', function () {
var operation = spec.paths['/responseModels'].get;
expect(Object.keys(operation.responses).length).toBe(3); // 200 + 400 + default

expect(operation.responses['200'].schema).toEqual({'$ref': 'Test'});
expect(operation.responses['200'].schema).toEqual({'$ref': '#/definitions/Test'});
expect(operation.responses['404']).toEqual({description: 'You got no Test'});

});
Expand All @@ -295,5 +296,36 @@ describe('converts specs', function () {
expect(model.required).toInclude('one');

});

it('makes the expected requests', function(done) {
var callCount = 0;

var interceptor = {
requestInterceptor: {
apply: function (requestObj) {
// rewrites an invalid pet id (-100) to be valid (1)
// you can do what you want here, like inject headers, etc.
callCount += 1
return requestObj;
}
}
};

new SwaggerClient({
url: 'http://localhost:8001/v1/api-docs.json',
usePromise: true,
requestInterceptor: interceptor.requestInterceptor
}).then(function(client) {
var operation = client.apis.pet.operations.getPetById;
expect(operation.successResponse[200].definition).toBeAn('object');
expect(operation.responses[400].schema).toBeAn('object');
expect(operation.responses[400].schema['$ref']).toBe('#/definitions/VeryBad');
expect(callCount).toEqual(1);
done();
}).catch(function(e) {
console.log(e);
done(e);
});
});
});
});
10 changes: 9 additions & 1 deletion test/spec/v1/pet
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"responseMessages": [
{
"code": 400,
"message": "Invalid ID supplied"
"message": "Invalid ID supplied",
"responseModel": "VeryBad"
},
{
"code": 404,
Expand Down Expand Up @@ -554,6 +555,13 @@
"$ref": "Phone"
}
}
},
"VeryBad": {
"properties": {
"message": {
"type": "string"
}
}
}
}
}