Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ef-parser into pull-requests/5

# Conflicts:
#	dist/ref-parser.js
#	dist/ref-parser.js.map
#	dist/ref-parser.min.js
#	dist/ref-parser.min.js.map
  • Loading branch information
JamesMessinger committed Dec 31, 2015
2 parents 2cb2a6e + f3e4de0 commit 71772db
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 680 deletions.
969 changes: 428 additions & 541 deletions dist/ref-parser.js

Large diffs are not rendered by default.

64 changes: 33 additions & 31 deletions dist/ref-parser.js.map

Large diffs are not rendered by default.

148 changes: 73 additions & 75 deletions dist/ref-parser.min.js

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions dist/ref-parser.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ $RefParser.dereference("my-schema.yaml", {
|`cache.fs` |number |60 |<a name="caching"></a>The length of time (in seconds) to cache local files. The default is one minute. Setting to zero will cache forever.
|`cache.http` |number |300 |The length of time (in seconds) to cache HTTP URLs. The default is five minutes. Setting to zero will cache forever.
|`cache.https` |number |300 |The length of time (in seconds) to cache HTTPS URLs. The default is five minutes. Setting to zero will cache forever.
|`http.withCredentials` |bool |true |When used in browser specifies `withCredentials` option of `XMLHttpRequest` object. Setting to `false` allows loading via CORS with `Access-Control-Allow-Origin` set to `*`
6 changes: 6 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ function $RefParserOptions(options) {
https: 5 * 60 // 5 minutes
};

/* http options */
this.http = {
/* withCredentials option of XMLHttpRequest */
withCredentials: true
}

merge(options, this);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ function download(protocol, u, options) {
hostname: u.hostname,
port: u.port,
path: u.path,
auth: u.auth
auth: u.auth,
withCredentials: options.http.withCredentials
},
onResponse
);
Expand Down
2 changes: 2 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<script src="specs/callbacks.spec.js"></script>
<script src="specs/yaml.spec.js"></script>

<script src="specs/cors.spec.js"></script>

<script>
mocha.run();
</script>
Expand Down
46 changes: 46 additions & 0 deletions tests/specs/cors/cors.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

describe('parse from CORS with Access-Control-Allow-Origin: *', function() {
var windowOnError, testDone;

beforeEach(function() {
windowOnError = global.onerror;
global.onerror = function() {
testDone();
return true;
}
});

afterEach(function() {
global.onerror = windowOnError;
});

it('should parse successfully with http.withCredentials = false', function() {
var parser = new $RefParser();
return parser
.parse('http://petstore.swagger.io:80/v2/swagger.json', {
http: { withCredentials: false }
})
.then(function(schema) {
expect(schema).to.be.an('object');
expect(schema).not.to.be.empty;
expect(parser.schema).to.equal(schema);
});
});

if (userAgent.isBrowser) {
it('should throw error in browser if http.withCredentials = true (default)', function(done) {
testDone = done;
var parser = new $RefParser();
return parser
.parse('http://petstore.swagger.io:80/v2/swagger.json', {
http: { withCredentials: true }
})
.then(helper.shouldNotGetCalled)
.catch(function(err) {
expect(err.message).to.contain('Error downloading file');
done();
});
});
}
});

0 comments on commit 71772db

Please sign in to comment.