laravel-openapi
laravel-openapi copied to clipboard
Use Primary Key type as path parameter
Current Behavior
If a Controller function accesses the path variable by model binding (as described here https://laravel.com/docs/9.x/routing#implicit-binding) and doesn't manually specify a path type, it is typed as string.
Requested Behavior
I would suggest to automatically try to type the path variable like the primary key type of the model
Possible Solution
Change the guessFromReflectionType
of the SchemaHelpers
class to something like this:
public static function guessFromReflectionType(ReflectionType $reflectionType): Schema
{
$typeString = $reflectionType->getName();
if (is_subclass_of($reflectionType->getName(), 'Illuminate\Database\Eloquent\Model')) {
$modelInstance = new ($reflectionType->getName())();
$typeString = $modelInstance->getKeyType();
}
switch ($typeString) {
case 'int':
return Schema::integer();
case 'bool':
return Schema::boolean();
}
return Schema::string();
}
This functionality is also requested here #74