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

Fix extend_schema_field type hint to allow a Field type #569

Closed
johnthagen opened this issue Oct 13, 2021 · 3 comments
Closed

Fix extend_schema_field type hint to allow a Field type #569

johnthagen opened this issue Oct 13, 2021 · 3 comments
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@johnthagen
Copy link
Contributor

def extend_schema_field(
field: Union[_SerializerType, Field, OpenApiTypes, Dict],

I would suggest also allowing Type[Field] to be passed in. I tried it out and it seems to work, but type checking will fail unless you pass an instance.

@extend_schema_field(field=_CustomField)
class CustomJSONField(JSONField):
    ...

Perhaps it would make more sense to only allow passing in Type[Field]? Not sure why an instance would make sense in this context (but Serializer instances are also currently allowed, so to be consistent it should probably allow Field instances too).

@tfranzel
Copy link
Owner

good point! verified that field classes work as well.

FYI: we need instances to model cases like these:

@extend_schema_field(OrderOfferDiscountSerializer(many=True))

@extend_schema_field(serializers.ChoiceField(choices=['a', 'b']))

@tfranzel tfranzel added enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Oct 14, 2021
@johnthagen
Copy link
Contributor Author

FYI: we need instances to model cases like these:

Ah, good point. Hadn't thought of that

@johnthagen
Copy link
Contributor Author

I tried out installing 5104ef6 master and the type hint looks great now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants