Skip to content

Commit

Permalink
Merge branch 'issue/VNG-Realisatie#215-revisit-duration-types' into d…
Browse files Browse the repository at this point in the history
…rf_compatibilty_newer_django_fix
  • Loading branch information
Sonny Bakker committed Sep 23, 2022
2 parents 720244f + d61066f commit 8f91810
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions vng_api_common/extensions/fields/duration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from drf_spectacular.extensions import OpenApiSerializerFieldExtension


class DurationFieldExtension(OpenApiSerializerFieldExtension):
target_class = "rest_framework.fields.DurationField"
match_subclasses = True

def map_serializer_field(self, auto_schema, direction):
default_schema = auto_schema._map_serializer_field(
self.target, direction, bypass_extensions=True
)

schema = {
**default_schema,
"format": "duration",
}

label = getattr(self.target, "label", None)
return {**schema, "title": label} if label else schema

0 comments on commit 8f91810

Please sign in to comment.