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

added type extension for int64 format support #214

Merged

Conversation

archandha
Copy link
Contributor

@archandha archandha commented Nov 26, 2020

Hi,
for a current project I need to be able to explicitly declare an integer value with format int64. As I didn't find a workaround, I did a minimal code extension to drf-spectacular to provide this.

I currently use this with such sample code:

class BigIntegerFieldFix(OpenApiSerializerFieldExtension):
    """fix serializer field BigIntegerField beeing reported as type integer, format int64 by spectacular"""
    target_class = 'restapi.serializers.BigIntegerField'

    def map_serializer_field(self, auto_schema, direction):
        return build_basic_type(OpenApiTypes.INT64)


class BigIntegerField(serializers.IntegerField):
    """dummy serializer field implementation to have spectacular make this type integer, format int64 in schema"""
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

in my drf serializers. Maybe, this is somewhat usefull for others, too.

@tfranzel
Copy link
Owner

hi @archandha, thank you it makes perfect sense. i noticed there are a few others missing. gonna add then too

@tfranzel tfranzel merged commit 1217a31 into tfranzel:master Nov 26, 2020
tfranzel added a commit that referenced this pull request Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants