-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Feature Request
Right now, it is not easy to use a custom naming scheme for a generic models. But I think this could be useful in some cases.
I recently faced this problem when I realized that the generated schema for List[Optional[T]] types doesn't actually mark the value type as optional (strangely/sadly I think there isn't currently a well-supported way to do this under OpenAPI).
My workaround was to create a wrapper class for optionals:
class OptionalWrapper(GenericModel, Generic[T]):
value: Optional[T]But I wanted to override the cls.__name__ since that is used by FastAPI when generating the openapi spec. (For example, I wanted to see OptionalInt instead of OptionalWrapper[int].)
Given how small a code change this requires, I think it should be reasonable, but I figured I'd create an issue for discussion just in case.