Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom naming for GenericModel subclasses #859

dmontagu opened this issue Oct 3, 2019 · 0 comments · Fixed by #860

Support custom naming for GenericModel subclasses #859

dmontagu opened this issue Oct 3, 2019 · 0 comments · Fixed by #860


Copy link

dmontagu commented Oct 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

1 participant