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

Commit

Permalink
Merge pull request #105 from apiaryio/kylef/schema-empty-items
Browse files Browse the repository at this point in the history
Handle empty items in JSON Schema arrays
  • Loading branch information
kylef authored Jun 13, 2017
2 parents e720eac + 7b7bbd5 commit 9dce36c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.12.0-beta.2

## Bug Fixes

- Data Structure generation from JSON Schema handles array items which
contain empty values.

# 0.12.0-beta.1

## Enhancements
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fury-adapter-swagger",
"version": "0.12.0-beta.1",
"version": "0.12.0-beta.2",
"description": "Swagger 2.0 parser for Fury.js",
"main": "./lib/adapter.js",
"tonicExampleFilename": "tonic-example.js",
Expand Down
10 changes: 8 additions & 2 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ export default class DataStructureGenerator {
if (schema.items) {
if (_.isArray(schema.items)) {
schema.items.forEach((item) => {
element.push(this.generateElement(item));
const itemElement = this.generateElement(item);
if (itemElement) {
element.push(itemElement);
}
});
} else {
element.push(this.generateElement(schema.items));
const itemElement = this.generateElement(schema.items);
if (itemElement) {
element.push(itemElement);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ describe('JSON Schema to Data Structure', () => {
expect(dataStructure.content.description.toValue())
.to.equal('- Array contents must be unique');
});

it('produces empty array element with empty items', () => {
const schema = {
type: 'array',
items: {},
};

const dataStructure = schemaToDataStructure(schema);

expect(dataStructure.element).to.equal('dataStructure');
expect(dataStructure.content).to.be.instanceof(ArrayElement);
expect(dataStructure.content.content.length).to.be.equal(0);
});
});

it('exposes the schema title', () => {
Expand Down

0 comments on commit 9dce36c

Please sign in to comment.