Skip to content

Support for DurationField #20

Description

@martin-san03

Hello, I need support for DurationField.

Would be this a valid implementation in converters.py?

@converter
class DurationFieldConverter:
    """
    A converter specifically for Django's DurationField.
    """
    # This attribute tells the registration system which field this handles.
    field_class = serializers.DurationField

    def convert(self, field):
        """
        The method that returns the JSON schema for the field.
        The `field_to_jsonschema` function will automatically add
        the 'title' and 'description' from the field's label and
        help_text afterwards.
        """
        return {
            'type': 'string',
            'format': 'duration',
            # Per ISO 8601 duration format (e.g., "P3DT6H4M")
            'pattern': r'^(\-)?P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d*(\.\d+)?)S)?)?$'
        }

If so, would it be possible to add it to the lib?
Thanks in advance

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions