@@ -99,6 +99,173 @@ describe("sampleFromSchema", function() {
9999
100100 expect ( sampleFromSchema ( definition , { includeWriteOnly : true } ) ) . toEqual ( expected )
101101 } )
102+
103+ describe ( "for array type" , function ( ) {
104+ it ( "returns array with sample of array type" , function ( ) {
105+ var definition = {
106+ type : "array" ,
107+ items : {
108+ type : "integer"
109+ }
110+ }
111+
112+ var expected = [ 0 ]
113+
114+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
115+ } )
116+
117+ it ( "returns array of examples for array that has example" , function ( ) {
118+ var definition = {
119+ type : "array" ,
120+ items : {
121+ type : "string"
122+ } ,
123+ example : "dog"
124+ }
125+
126+ var expected = [ "dog" ]
127+
128+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
129+ } )
130+
131+ it ( "returns array of examples for array that has examples" , function ( ) {
132+ var definition = {
133+ type : "array" ,
134+ items : {
135+ type : "string" ,
136+ } ,
137+ example : [ "dog" , "cat" ]
138+ }
139+
140+ var expected = [ "dog" , "cat" ]
141+
142+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
143+ } )
144+
145+ it ( "returns array of samples for oneOf type" , function ( ) {
146+ var definition = {
147+ type : "array" ,
148+ items : {
149+ type : "string" ,
150+ oneOf : [
151+ {
152+ type : "integer"
153+ }
154+ ]
155+ }
156+ }
157+
158+ var expected = [ 0 ]
159+
160+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
161+ } )
162+
163+ it ( "returns array of samples for oneOf types" , function ( ) {
164+ var definition = {
165+ type : "array" ,
166+ items : {
167+ type : "string" ,
168+ oneOf : [
169+ {
170+ type : "string"
171+ } ,
172+ {
173+ type : "integer"
174+ }
175+ ]
176+ }
177+ }
178+
179+ var expected = [ "string" , 0 ]
180+
181+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
182+ } )
183+
184+ it ( "returns array of samples for oneOf examples" , function ( ) {
185+ var definition = {
186+ type : "array" ,
187+ items : {
188+ type : "string" ,
189+ oneOf : [
190+ {
191+ type : "string" ,
192+ example : "dog"
193+ } ,
194+ {
195+ type : "integer" ,
196+ example : 1
197+ }
198+ ]
199+ }
200+ }
201+
202+ var expected = [ "dog" , 1 ]
203+
204+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
205+ } )
206+
207+ it ( "returns array of samples for anyOf type" , function ( ) {
208+ var definition = {
209+ type : "array" ,
210+ items : {
211+ type : "string" ,
212+ anyOf : [
213+ {
214+ type : "integer"
215+ }
216+ ]
217+ }
218+ }
219+
220+ var expected = [ 0 ]
221+
222+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
223+ } )
224+
225+ it ( "returns array of samples for anyOf types" , function ( ) {
226+ var definition = {
227+ type : "array" ,
228+ items : {
229+ type : "string" ,
230+ anyOf : [
231+ {
232+ type : "string"
233+ } ,
234+ {
235+ type : "integer"
236+ }
237+ ]
238+ }
239+ }
240+
241+ var expected = [ "string" , 0 ]
242+
243+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
244+ } )
245+
246+ it ( "returns array of samples for anyOf examples" , function ( ) {
247+ var definition = {
248+ type : "array" ,
249+ items : {
250+ type : "string" ,
251+ anyOf : [
252+ {
253+ type : "string" ,
254+ example : "dog"
255+ } ,
256+ {
257+ type : "integer" ,
258+ example : 1
259+ }
260+ ]
261+ }
262+ }
263+
264+ var expected = [ "dog" , 1 ]
265+
266+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
267+ } )
268+ } )
102269} )
103270
104271describe ( "createXMLExample" , function ( ) {
0 commit comments