Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
fix(json-schema): Allow $ref in the root of a definitions object
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Oct 25, 2018
1 parent 8aa2588 commit f8f7140
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Fury Swagger Parser Changelog

## Master

- Fixes a regression introduced in 0.22.0 where using `$ref` directly inside a
Swagger Schema found within the `definitions` section would cause a parsing
failure.

## 0.22.1 (2018-10-22)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion src/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function convertSchema(schema, root, swagger, copyDefinitions = true) {
}
}

if (result.$ref) {
if (result.$ref && copyDefinitions) {
const reference = lookupReference(result.$ref, root);

if (!checkSchemaHasReferences(result.definitions[reference.id])) {
Expand Down
39 changes: 38 additions & 1 deletion test/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { expect } from 'chai';

import { convertSchema } from '../src/json-schema';
import { convertSchema, convertSchemaDefinitions } from '../src/json-schema';

describe('Swagger Schema to JSON Schema', () => {
it('returns compatible schema when given valid JSON Schema', () => {
Expand Down Expand Up @@ -552,4 +552,41 @@ describe('Swagger Schema to JSON Schema', () => {
});
});
});

describe('converting JSON Schema definitions', () => {
it('can convert a Swagger Schema definitions section', () => {
const result = convertSchemaDefinitions({
User: {
type: 'object',
'x-extension': true,
},
});

expect(result).to.deep.equal({
User: {
type: 'object',
},
});
});

it('can convert a Swagger Schema definition with root reference', () => {
const result = convertSchemaDefinitions({
Base: {
type: 'object',
},
User: {
$ref: '#/definitions/Base',
},
});

expect(result).to.deep.equal({
Base: {
type: 'object',
},
User: {
$ref: '#/definitions/Base',
},
});
});
});
});

0 comments on commit f8f7140

Please sign in to comment.