This repository was archived by the owner on Nov 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 2121 values of the array to be a string type. Instead provided an example that the
2222 value of the array MAY be a string.
2323
24+ - Support required keys in a Schema Object which are not found in the
25+ properties list.
26+
2427## 0.30.0 (2020-04-29)
2528
2629The package has been renamed to ` @apielements/openapi2-parser`.
Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ class DataStructureGenerator {
111111 return member ;
112112 } ) ) ;
113113
114+ // Create member elements for required keys which are not defined in properties
115+ const missingRequiredProperties = required . filter ( name => properties [ name ] === undefined ) ;
116+ const requiredMembers = missingRequiredProperties . map ( ( name ) => {
117+ const member = new this . minim . elements . Member ( name ) ;
118+ member . attributes . set ( 'typeAttributes' , [ 'required' ] ) ;
119+ return member ;
120+ } ) ;
121+ element . content = element . content . concat ( requiredMembers ) ;
122+
114123 return element ;
115124 }
116125
Original file line number Diff line number Diff line change @@ -460,6 +460,21 @@ describe('JSON Schema to Data Structure', () => {
460460 expect ( member . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'required' ] ) ;
461461 } ) ;
462462
463+ it ( 'produces object members from required which are not found in properties' , ( ) => {
464+ const schema = {
465+ type : 'object' ,
466+ required : [ 'name' ] ,
467+ } ;
468+
469+ const dataStructure = schemaToDataStructure ( schema ) ;
470+
471+ expect ( dataStructure . element ) . to . equal ( 'dataStructure' ) ;
472+ expect ( dataStructure . content ) . to . be . instanceof ( ObjectElement ) ;
473+
474+ const name = dataStructure . content . getMember ( 'name' ) ;
475+ expect ( name . attributes . getValue ( 'typeAttributes' ) ) . to . deep . equal ( [ 'required' ] ) ;
476+ } ) ;
477+
463478 it ( 'produces object element with description of maxProperties' , ( ) => {
464479 const schema = {
465480 type : 'object' ,
You can’t perform that action at this time.
0 commit comments