@@ -47,7 +47,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI
4747 \Flight::route ('DELETE /pet/@petId ' , function (string $ petId ) use ($ handler ) {
4848 $ r = \Flight::request ();
4949 $ handler ->deletePet (
50- parseParam ($ petId , 'int ' ),
50+ parseParam ($ petId , 'int ' ),
5151 parseParam ($ r ->getHeader ('api_key ' ), '?string ' )
5252 );
5353 \Flight::halt (204 );
@@ -313,7 +313,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI
313313 \Flight::route ('GET /user/login ' , function () use ($ handler ) {
314314 $ r = \Flight::request ();
315315 $ result = $ handler ->loginUser (
316- parseParam ($ r ->query ['username ' ] ?? null , 'string ' ),
316+ parseParam ($ r ->query ['username ' ] ?? null , 'string ' ),
317317 parseParam ($ r ->query ['password ' ] ?? null , 'string ' )
318318 );
319319 if ($ result === null ) {
@@ -343,7 +343,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI
343343 \Flight::route ('PUT /user/@username ' , function (string $ username ) use ($ handler ) {
344344 $ r = \Flight::request ();
345345 $ handler ->updateUser (
346- parseParam ($ username , 'string ' ),
346+ parseParam ($ username , 'string ' ),
347347 parseParam (json_decode ($ r ->getBody (), true ), '\\OpenAPIServer \\Model \\User ' )
348348 );
349349 \Flight::halt (204 );
@@ -368,7 +368,10 @@ function parseParam(mixed $param, string $type)
368368 } elseif (str_ends_with ($ type , '[] ' )) {
369369 return array_map (fn ($ el ) => parseParam ($ el , substr ($ type , 0 , -2 )), $ param );
370370 } elseif (str_starts_with ($ nonNullType , '\\OpenAPIServer \\Model ' )) {
371- return new $ nonNullType ($ param );
371+ if (enum_exists ($ nonNullType )) {
372+ return $ nonNullType ::tryFrom ($ param );
373+ }
374+ return $ nonNullType ::fromArray ($ param );
372375 } else {
373376 return $ param ;
374377 }
@@ -377,4 +380,4 @@ function parseParam(mixed $param, string $type)
377380function declaresMethod (\ReflectionClass $ reflectionClass , string $ methodName ): bool
378381{
379382 return $ reflectionClass ->hasMethod ($ methodName ) && $ reflectionClass ->getMethod ($ methodName )->getDeclaringClass ()->getName () === $ reflectionClass ->getName ();
380- }
383+ }
0 commit comments