@@ -197,7 +197,7 @@ public function content(MediaType ...$content): self
197197 */
198198 public function toArray (): array
199199 {
200- $ output = $ this ->buildArray ([
200+ return $ this ->buildArray ([
201201 'name ' => $ this ->name ,
202202 'in ' => $ this ->in ->value ,
203203 'description ' => $ this ->description ,
@@ -207,33 +207,10 @@ public function toArray(): array
207207 'style ' => $ this ->style ,
208208 'explode ' => $ this ->explode ,
209209 'allowReserved ' => $ this ->allowReserved ,
210+ 'example ' => $ this ->example ,
210211 'examples ' => $ this ->examples ,
211212 'schema ' => $ this ->schema ,
212213 'content ' => $ this ->content ,
213- ]);
214-
215- if ($ this ->hasExample ) {
216- // Insert example before examples/schema/content so conventional order is preserved,
217- // even when the example value is literal null (which buildArray would otherwise drop).
218- $ reordered = [];
219-
220- foreach ($ output as $ key => $ value ) {
221- if (! array_key_exists ('example ' , $ reordered )
222- && in_array ($ key , ['examples ' , 'schema ' , 'content ' ], true )
223- ) {
224- $ reordered ['example ' ] = $ this ->example ;
225- }
226-
227- $ reordered [$ key ] = $ value ;
228- }
229-
230- if (! array_key_exists ('example ' , $ reordered )) {
231- $ reordered ['example ' ] = $ this ->example ;
232- }
233-
234- return $ reordered ;
235- }
236-
237- return $ output ;
214+ ], $ this ->hasExample ? ['example ' ] : []);
238215 }
239216}
0 commit comments