This repository was archived by the owner on Nov 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ class DataStructureGenerator {
120120 } ) ;
121121 element . content . push ( ...requiredMembers ) ;
122122
123+ if ( schema . additionalProperties === false ) {
124+ const typeAttributes = element . attributes . get ( 'typeAttributes' ) || new this . minim . elements . Array ( [ ] ) ;
125+ typeAttributes . push ( 'fixed-type' ) ;
126+ element . attributes . set ( 'typeAttributes' , typeAttributes ) ;
127+ }
128+
123129 return element ;
124130 }
125131
Original file line number Diff line number Diff line change @@ -692,6 +692,36 @@ describe('JSON Schema to Data Structure', () => {
692692 expect ( samples ) . to . be . instanceof ( ArrayElement ) ;
693693 expect ( samples . toValue ( ) ) . to . be . deep . equal ( [ { name : 'Doe' } ] ) ;
694694 } ) ;
695+
696+ it ( 'produces object with additionalProperties as true' , ( ) => {
697+ const schema = {
698+ type : 'object' ,
699+ additionalProperties : true ,
700+ } ;
701+
702+ const dataStructure = schemaToDataStructure ( schema ) ;
703+
704+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
705+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
706+
707+ expect ( dataStructure . content . length ) . to . equal ( 0 ) ;
708+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . be . undefined ;
709+ } ) ;
710+
711+ it ( 'produces object with additionalProperties as false' , ( ) => {
712+ const schema = {
713+ type : 'object' ,
714+ additionalProperties : false ,
715+ } ;
716+
717+ const dataStructure = schemaToDataStructure ( schema ) ;
718+
719+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
720+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
721+
722+ expect ( dataStructure . content . length ) . to . equal ( 0 ) ;
723+ expect ( dataStructure . content . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'fixed-type' ] ) ;
724+ } ) ;
695725 } ) ;
696726
697727 context ( 'array schema' , ( ) => {
You can’t perform that action at this time.
0 commit comments