File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,15 +10,22 @@ export function ArrayItemDetails({ schema }: { schema: SchemaModel }) {
1010 const { hideSchemaPattern } = React . useContext ( OptionsContext ) ;
1111 if (
1212 ! schema ||
13- ( schema . type === 'string' && ! schema . constraints . length ) ||
1413 ( ( ! schema ?. pattern || hideSchemaPattern ) &&
1514 ! schema . items &&
1615 ! schema . displayFormat &&
17- ! schema . constraints . length ) // return null for cases where all constraints are empty
16+ ! schema . constraints ? .length ) // return null for cases where all constraints are empty
1817 ) {
1918 return null ;
2019 }
2120
21+ if ( schema . type === 'string' && schema . pattern ) {
22+ return (
23+ < Wrapper >
24+ [< Pattern schema = { schema } /> ]
25+ </ Wrapper >
26+ ) ;
27+ }
28+
2229 return (
2330 < Wrapper >
2431 [ items
Original file line number Diff line number Diff line change @@ -76,4 +76,41 @@ describe('FieldDetailsComponent', () => {
7676
7777 expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
7878 } ) ;
79+
80+ it ( 'renders correctly when field items have string type and pattern' , ( ) => {
81+ const mockFieldProps = {
82+ showExamples : true ,
83+ field : {
84+ schema : {
85+ type : 'array' ,
86+ displayType : 'Array of strings' ,
87+ title : 'test title' ,
88+ externalDocs : undefined ,
89+ constraints : [ '' ] ,
90+ items : {
91+ type : 'string' ,
92+ pattern : '^see regex[0-9]$' ,
93+ constraints : [ '' ] ,
94+ externalDocs : undefined ,
95+ } ,
96+ } as any as SchemaModel ,
97+ example : 'example' ,
98+ name : 'name' ,
99+ expanded : false ,
100+ required : false ,
101+ kind : '' ,
102+ deprecated : false ,
103+ collapse : jest . fn ( ) ,
104+ toggle : jest . fn ( ) ,
105+ explode : false ,
106+ expand : jest . fn ( ) ,
107+ description : 'test description' ,
108+ in : undefined ,
109+ } ,
110+ renderDiscriminatorSwitch : jest . fn ( ) ,
111+ } ;
112+ const wrapper = shallow ( withTheme ( < FieldDetails { ...mockFieldProps } /> ) ) ;
113+
114+ expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
115+ } ) ;
79116} ) ;
Original file line number Diff line number Diff line change @@ -133,3 +133,67 @@ exports[`FieldDetailsComponent renders correctly when default value is object in
133133 </div >
134134</div >
135135` ;
136+
137+ exports [` FieldDetailsComponent renders correctly when field items have string type and pattern 1` ] = `
138+ <div >
139+ <div >
140+ <span
141+ class = " sc-kpDqfm sc-dAlyuH cGRfjn gHomYR"
142+ />
143+ <span
144+ class = " sc-kpDqfm sc-jlZhew cGRfjn dYtiIA"
145+ >
146+ Array of strings
147+ </span >
148+ <span
149+ class = " sc-kpDqfm sc-cwHptR cGRfjn gyVIPr"
150+ >
151+ (test title)
152+ </span >
153+ <span >
154+
155+ <span
156+ class = " sc-kpDqfm sc-gFqAkR cGRfjn fYEICH"
157+ >
158+
159+ </span >
160+ </span >
161+ <span
162+ class = " sc-kpDqfm sc-dAlyuH sc-dxcDKg cGRfjn gHomYR gXntsr"
163+ >
164+ [
165+ <span
166+ class = " sc-kpDqfm sc-eDPEul cGRfjn erJHow"
167+ >
168+ ^see regex[0-9]$
169+ </span >
170+ ]
171+ </span >
172+ </div >
173+
174+ <div >
175+ <span
176+ class = " sc-kpDqfm cGRfjn"
177+ >
178+ Example:
179+ </span >
180+
181+ <span
182+ class = " sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
183+ >
184+ "example"
185+ </span >
186+ </div >
187+ <div >
188+ <div
189+ class = " sc-lcIPJg sc-hknOHE gBHqkN jFBMaE"
190+ >
191+ <p >
192+ test description
193+ </p >
194+
195+
196+ </div >
197+ </div >
198+ </div >
199+ ` ;
You can’t perform that action at this time.
0 commit comments