Skip to content

added type extension for int64 format support#214

Merged
tfranzel merged 1 commit intotfranzel:masterfrom
archandha:feature/add_int64_explicit_support
Nov 26, 2020
Merged

added type extension for int64 format support#214
tfranzel merged 1 commit intotfranzel:masterfrom
archandha:feature/add_int64_explicit_support

Conversation

@archandha
Copy link
Copy Markdown
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
Copy Markdown
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