Skip to content

Commit

Permalink
fix: serialization ver 0.6 for enum with default
Browse files Browse the repository at this point in the history
  • Loading branch information
klokane authored and kylef committed Jun 11, 2019
1 parent 7945b8b commit e2f6de6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Minim Changelog

## 0.23.4 (2019-06-11)

### Bug Fixes

- Fixes serialisation of default values in enumerations in
Refract JSON 0.6 serialisation.

## 0.23.3 (2019-04-06)

### Enhancements
Expand Down
4 changes: 3 additions & 1 deletion lib/serialisers/JSON06Serialiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ module.exports = class JSON06Serialiser extends JSONSerialiser {
let samples = attributes.get('samples') || new this.namespace.elements.Array([]);

if (defaultValue && defaultValue.content) {
defaultValue.content.attributes.remove('typeAttributes');
if (defaultValue.content.attributes) {
defaultValue.content.attributes.remove('typeAttributes');
}
// Wrap default in array (not sure it is really needed because tests pass without this line)
attributes.set('default', new this.namespace.elements.Array([defaultValue.content]));
}
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": "minim",
"version": "0.23.3",
"version": "0.23.4",
"description": "A library for interacting with JSON through Refract elements",
"main": "lib/minim.js",
"scripts": {
Expand Down
22 changes: 22 additions & 0 deletions test/serialisers/JSON06Serialiser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,28 @@ describe('JSON 0.6 Serialiser', () => {
});
});

it('serialises enum with default', () => {
const defaultElement = new minim.elements.String('one');
const enumeration = new minim.Element();
enumeration.element = 'enum';
enumeration.attributes.set('default', defaultElement);

const result = serialiser.serialise(enumeration);

expect(result).to.deep.equal({
element: 'enum',
attributes: {
default: [
{
element: 'string',
content: 'one',
},
],
},
content: [],
});
});

it('serialises enum with fixed values', () => {
const defaultElement = new minim.Element(new minim.elements.String('North'));
defaultElement.element = 'enum';
Expand Down

0 comments on commit e2f6de6

Please sign in to comment.