Skip to content

Commit

Permalink
Adds failing test for whitlockjc#93
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego de Estrada committed Sep 13, 2016
1 parent 5ad1f63 commit 46a4b79
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/browser/documents/nested-refs/a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
swagger: "2.0"
info:
title: test
version: '0.0.0'
responses:
500:
description: "error"
schema:
$ref: "#/definitions/e"
paths: {}
definitions:
y:
type: object
properties:
children:
type: array
items:
$ref: "#/definitions/z"
z:
type: object
properties:
name:
type: string
t:
type: string
enum:
- unauthorized
- forbidden
f:
type: object
properties:
error_type:
$ref: '#/definitions/t'
e:
type: object
properties:
error_type:
$ref: "#/definitions/t"
per_property_error_messages:
type: array
items:
$ref: '#/definitions/f'
11 changes: 11 additions & 0 deletions test/browser/documents/nested-refs/b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
swagger: "2.0"
info:
title: test
version: '0.0.0'
responses:
$ref: "./a.yaml#/responses"
paths: {}
definitions:
x:
$ref: "./a.yaml#/definitions/y"
24 changes: 24 additions & 0 deletions test/test-issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,28 @@ describe('json-refs Issues', function () {
.then(done, done);
});
});

describe('Issue #93', function () {
it('should resolve nested references correctly', function (done) {
JsonRefs.resolveRefsAt('nested-refs/b.yaml', {
filter: ['relative', 'local'],
loaderOptions: {
processContent: function (res, callback) {
callback(undefined, YAML.safeLoad(res.text));
}
},
relativeBase: relativeBase
})
.then(function (results) {
assert.ok(!_.has(results, 'resolved.definitions.x.properties.children.items.$ref'));
assert.equal(results.resolved.definitions.x.properties.children.items.type, 'object');

assert.ok(!_.has(results, 'resolved.responses.500.schema.properties.error_type.$ref'));
assert.equal(results.resolved.responses['500'].schema.properties.error_type.type, 'string');

assert.ok(!_.has(results, 'resolved.responses.500.schema.properties.per_property_error_messages.items.properties.error_type.$ref'));
})
.then(done, done);
});
});
});

0 comments on commit 46a4b79

Please sign in to comment.