@@ -163,48 +163,28 @@ public function getParamExample(array $param): string
163163 $ type = $ param ['type ' ] ?? '' ;
164164 $ example = $ param ['example ' ] ?? '' ;
165165
166- $ output = '' ;
166+ $ hasExample = ! empty ( $ example ) || $ example === 0 || $ example === false ;
167167
168- if (empty ($ example ) && $ example !== 0 && $ example !== false ) {
169- switch ($ type ) {
170- case self ::TYPE_NUMBER :
171- case self ::TYPE_INTEGER :
172- case self ::TYPE_BOOLEAN :
173- $ output .= 'null ' ;
174- break ;
175- case self ::TYPE_STRING :
176- $ output .= "'' " ;
177- break ;
178- case self ::TYPE_ARRAY :
179- $ output .= '[] ' ;
180- break ;
181- case self ::TYPE_OBJECT :
182- $ output .= '{} ' ;
183- break ;
184- case self ::TYPE_FILE :
185- $ output .= "InputFile.fromPath('/path/to/file.png', 'file.png') " ;
186- break ;
187- }
188- } else {
189- switch ($ type ) {
190- case self ::TYPE_NUMBER :
191- case self ::TYPE_INTEGER :
192- case self ::TYPE_ARRAY :
193- case self ::TYPE_OBJECT :
194- $ output .= $ example ;
195- break ;
196- case self ::TYPE_BOOLEAN :
197- $ output .= ($ example ) ? 'true ' : 'false ' ;
198- break ;
199- case self ::TYPE_STRING :
200- $ output .= "' {$ example }' " ;
201- break ;
202- case self ::TYPE_FILE :
203- $ output .= "InputFile.fromPath('/path/to/file.png', 'file.png') " ;
204- break ;
205- }
168+ if (!$ hasExample ) {
169+ return match ($ type ) {
170+ self ::TYPE_ARRAY => '[] ' ,
171+ self ::TYPE_FILE => 'InputFile.fromPath( \'/path/to/file.png \', \'file.png \') ' ,
172+ self ::TYPE_INTEGER , self ::TYPE_NUMBER , self ::TYPE_BOOLEAN => 'null ' ,
173+ self ::TYPE_OBJECT => '{} ' ,
174+ self ::TYPE_STRING => "'' " ,
175+ };
206176 }
207177
208- return $ output ;
178+ return match ($ type ) {
179+ self ::TYPE_ARRAY , self ::TYPE_INTEGER , self ::TYPE_NUMBER => $ example ,
180+ self ::TYPE_FILE => 'InputFile.fromPath( \'/path/to/file.png \', \'file.png \') ' ,
181+ self ::TYPE_BOOLEAN => ($ example ) ? 'true ' : 'false ' ,
182+ self ::TYPE_OBJECT => ($ example === '{} ' )
183+ ? '{} '
184+ : (($ formatted = json_encode (json_decode ($ example , true ), JSON_PRETTY_PRINT ))
185+ ? preg_replace ('/\n/ ' , "\n " , $ formatted )
186+ : $ example ),
187+ self ::TYPE_STRING => "' {$ example }' " ,
188+ };
209189 }
210190}
0 commit comments