@@ -720,7 +720,90 @@ describe('JSON Schema to Data Structure', () => {
720720 expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
721721
722722 expect ( dataStructure . content . length ) . to . equal ( 0 ) ;
723- expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixed-type' ] ) ;
723+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixedType' ] ) ;
724+ } ) ;
725+
726+ it ( 'produces object with additionalProperties as false with required properties' , ( ) => {
727+ const schema = {
728+ type : 'object' ,
729+ required : [ 'type' ] ,
730+ additionalProperties : false ,
731+ } ;
732+
733+ const dataStructure = schemaToDataStructure ( schema ) ;
734+
735+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
736+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
737+
738+ expect ( dataStructure . content . length ) . to . equal ( 1 ) ;
739+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixedType' ] ) ;
740+
741+ const type = dataStructure . content . getMember ( 'type' ) ;
742+ expect ( type ) . to . be . instanceof ( MemberElement ) ;
743+ expect ( type . attributes . getValue ( 'variable' ) ) . to . be . undefined ;
744+ expect ( type . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'required' ] ) ;
745+ expect ( type . value ) . to . be . undefined ;
746+ } ) ;
747+
748+ it ( 'produces object with additionalProperties containing a structure' , ( ) => {
749+ const schema = {
750+ type : 'object' ,
751+ additionalProperties : {
752+ type : 'string' ,
753+ } ,
754+ } ;
755+
756+ const dataStructure = schemaToDataStructure ( schema ) ;
757+
758+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
759+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
760+
761+ expect ( dataStructure . content . length ) . to . equal ( 1 ) ;
762+
763+ const member = dataStructure . content . getMember ( '' ) ;
764+ expect ( member ) . to . be . instanceof ( MemberElement ) ;
765+ expect ( member . attributes . getValue ( 'variable' ) ) . to . be . true ;
766+ expect ( member . value ) . to . be . instanceof ( StringElement ) ;
767+
768+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixedType' ] ) ;
769+ } ) ;
770+
771+ it ( 'produces object with required additionalProperties containing a structure' , ( ) => {
772+ const schema = {
773+ type : 'object' ,
774+ additionalProperties : {
775+ type : 'string' ,
776+ } ,
777+ required : [ 'type' , 'mode' ] ,
778+ } ;
779+
780+ const dataStructure = schemaToDataStructure ( schema ) ;
781+
782+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
783+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
784+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixedType' ] ) ;
785+
786+ expect ( dataStructure . content . length ) . to . equal ( 3 ) ;
787+
788+ // Variable property
789+ const variable = dataStructure . content . getMember ( '' ) ;
790+ expect ( variable ) . to . be . instanceof ( MemberElement ) ;
791+ expect ( variable . attributes . getValue ( 'variable' ) ) . to . be . true ;
792+ expect ( variable . value ) . to . be . instanceof ( StringElement ) ;
793+
794+ // Required 'type' property
795+ const type = dataStructure . content . getMember ( 'type' ) ;
796+ expect ( type ) . to . be . instanceof ( MemberElement ) ;
797+ expect ( type . attributes . getValue ( 'variable' ) ) . to . be . undefined ;
798+ expect ( type . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'required' ] ) ;
799+ expect ( type . value ) . to . be . instanceof ( StringElement ) ;
800+
801+ // Required 'mode' property
802+ const mode = dataStructure . content . getMember ( 'mode' ) ;
803+ expect ( mode ) . to . be . instanceof ( MemberElement ) ;
804+ expect ( mode . attributes . getValue ( 'variable' ) ) . to . be . undefined ;
805+ expect ( mode . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'required' ] ) ;
806+ expect ( mode . value ) . to . be . instanceof ( StringElement ) ;
724807 } ) ;
725808 } ) ;
726809
0 commit comments