@@ -757,6 +757,101 @@ describe('SchemaTree', () => {
757
757
} ) ,
758
758
) ;
759
759
} ) ;
760
+
761
+ it ( 'node of type array should adopt description of referenced node' , ( ) => {
762
+ const schema = {
763
+ definitions : {
764
+ Cave : {
765
+ type : 'string' ,
766
+ summary : 'A cave' ,
767
+ description : '_Everyone_ ~hates~ loves caves' ,
768
+ } ,
769
+ } ,
770
+ type : 'object' ,
771
+ properties : {
772
+ caves : {
773
+ type : 'array' ,
774
+ items : {
775
+ $ref : '#/definitions/Cave' ,
776
+ } ,
777
+ } ,
778
+ } ,
779
+ } ;
780
+
781
+ const tree = new SchemaTree ( schema ) ;
782
+ tree . populate ( ) ;
783
+
784
+ expect (
785
+ // @ts -ignore
786
+ tree . root . children [ 0 ] . children [ 0 ] . annotations . description ,
787
+ ) . toEqual ( '_Everyone_ ~hates~ loves caves' ) ;
788
+ } ) ;
789
+
790
+ it ( 'node of type array should keep its own description even when referenced node has a description' , ( ) => {
791
+ const schema = {
792
+ definitions : {
793
+ Cave : {
794
+ type : 'string' ,
795
+ summary : 'A cave' ,
796
+ description : '_Everyone_ ~hates~ loves caves' ,
797
+ } ,
798
+ } ,
799
+ type : 'object' ,
800
+ properties : {
801
+ caves : {
802
+ type : 'array' ,
803
+ description : 'I have my own description' ,
804
+ items : {
805
+ $ref : '#/definitions/Cave' ,
806
+ } ,
807
+ } ,
808
+ } ,
809
+ } ;
810
+
811
+ const tree = new SchemaTree ( schema ) ;
812
+ tree . populate ( ) ;
813
+
814
+ expect (
815
+ // @ts -ignore
816
+ tree . root . children [ 0 ] . children [ 0 ] . annotations . description ,
817
+ ) . toEqual ( 'I have my own description' ) ;
818
+ } ) ;
819
+
820
+ it ( 'referenced node description should appear for all properties with that ref' , ( ) => {
821
+ const schema = {
822
+ definitions : {
823
+ Cave : {
824
+ type : 'string' ,
825
+ summary : 'A cave' ,
826
+ description : '_Everyone_ ~hates~ loves caves' ,
827
+ } ,
828
+ } ,
829
+ type : 'object' ,
830
+ properties : {
831
+ caves : {
832
+ type : 'array' ,
833
+ items : {
834
+ $ref : '#/definitions/Cave' ,
835
+ } ,
836
+ } ,
837
+ bear : {
838
+ $ref : '#/definitions/Cave' ,
839
+ } ,
840
+ } ,
841
+ } ;
842
+
843
+ const tree = new SchemaTree ( schema ) ;
844
+ tree . populate ( ) ;
845
+
846
+ expect (
847
+ // @ts -ignore
848
+ tree . root . children [ 0 ] . children [ 0 ] . annotations . description ,
849
+ ) . toEqual ( '_Everyone_ ~hates~ loves caves' ) ;
850
+ expect (
851
+ // @ts -ignore
852
+ tree . root . children [ 0 ] . children [ 1 ] . annotations . description ,
853
+ ) . toEqual ( '_Everyone_ ~hates~ loves caves' ) ;
854
+ } ) ;
760
855
} ) ;
761
856
762
857
describe ( 'position' , ( ) => {
0 commit comments