From e2f6de68fb75677457c62e47fc29b45e9f3da4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kratochv=C3=ADl?= Date: Tue, 11 Jun 2019 11:52:49 +0200 Subject: [PATCH] fix: serialization ver 0.6 for enum with default --- CHANGELOG.md | 7 +++++++ lib/serialisers/JSON06Serialiser.js | 4 +++- package.json | 2 +- test/serialisers/JSON06Serialiser-test.js | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81319c40..a64dc10a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/serialisers/JSON06Serialiser.js b/lib/serialisers/JSON06Serialiser.js index ebfe7382..e3346b04 100644 --- a/lib/serialisers/JSON06Serialiser.js +++ b/lib/serialisers/JSON06Serialiser.js @@ -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])); } diff --git a/package.json b/package.json index df39e73e..c761a37d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/serialisers/JSON06Serialiser-test.js b/test/serialisers/JSON06Serialiser-test.js index 8db86f1c..addf58c8 100644 --- a/test/serialisers/JSON06Serialiser-test.js +++ b/test/serialisers/JSON06Serialiser-test.js @@ -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';