@@ -54,7 +54,7 @@ public function example(?string $phpType, ?string $swaggerType = null, ?string $
54
54
$ isArray = $ this ->isTypeArray ($ phpType );
55
55
if ($ rule === null || ($ example = $ this ->exampleByRule ($ rule )) === null ) {
56
56
$ typeClean = $ isArray ? substr ($ phpType , 0 , -2 ) : $ phpType ;
57
- $ example = $ this ->exampleByType ($ typeClean );
57
+ $ example = $ this ->exampleByType ($ typeClean, $ varName );
58
58
}
59
59
$ example = $ this ->typeCastExample ($ example , $ phpType );
60
60
$ example = $ isArray ? [$ example ] : $ example ;
@@ -141,7 +141,7 @@ protected function exampleByTypeSequential(?string $type, int $iteration = 1): m
141
141
case 'double ' :
142
142
return 1.65 * $ iteration ;
143
143
case 'string ' :
144
- $ strArr = ['string ' , 'str value ' , 'str example ' , 'string data ' , 'some txt ' ];
144
+ $ strArr = ['string ' , 'string value ' , 'string example ' , 'string data ' , 'some text ' ];
145
145
return $ this ->takeFromArray ($ strArr , $ iteration );
146
146
case 'bool ' :
147
147
case 'boolean ' :
@@ -358,11 +358,15 @@ protected function exampleByRuleSequential(string $rule, int $iteration = 1): mi
358
358
* Get example by given type
359
359
*
360
360
* @param string|null $type
361
+ * @param string|null $varName
361
362
* @return array|int|string|null
362
363
*/
363
- protected function exampleByType (?string $ type ): mixed
364
+ protected function exampleByType (?string $ type, ? string $ varName = null ): mixed
364
365
{
365
366
$ type = is_string ($ type ) ? $ this ->normalizeType ($ type , true ) : null ;
367
+ if ($ type === 'string ' && is_string ($ varName )) {
368
+ return Str::headline ($ varName );
369
+ }
366
370
$ key = $ type ;
367
371
if (! isset ($ this ->varsSequences [$ key ])) {
368
372
$ this ->varsSequences [$ key ] = $ this ->generateExampleByTypeSequence ($ type , 10 );
0 commit comments