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

DecimalField represented as type string with minimum and maximum #335

Closed
idesoto-rover opened this issue Mar 12, 2021 · 2 comments
Closed
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@idesoto-rover
Copy link

Describe the bug
DecimalField fields that use max_digits or decimal_places are represented in the schema as a type string with minimum and maximum properties, but according to the specs (or what I understand of them) is that minimum and maximum properties only apply to fields of type number.

This is giving me issues in the validation library I'm using (drf-openapi-tester) because it expects that fields with minimum and maximum properties to be numbers. After checking the specs IMHO the problem is in the schema (even if the validation library could be a bit more flexible and not fail on this).

To Reproduce
E.g.: for this field:

    latitude = serializers.DecimalField(
        max_digits=7,
        decimal_places=3
    )

This is generated in the schema:

        latitude:
          type: string
          format: decimal
          maximum: 10000
          minimum: -10000

Expected behavior
Maybe instead of specifying minimum and maximum values, specify a string pattern? Something like ^\d{1,7}(?:\.\d{1,3})?$ if max_digits is 7 and decimal_places is 3.

        latitude:
          type: string
          format: decimal
          pattern: ^\d{1,7}(?:\.\d{1,3})$
@tfranzel
Copy link
Owner

absolutely right! minimum and maximum are of type number, which is "correct" in the schema example. of course, it's comparing apples with oranges when the value itself is of type (decimal) string.

the resources as far as i can see make no statement about this.

however, common sense would suggest that the min/max value types should be the same as the field type. drf-openapi-tester must have a dedicated logic for this. the pattern solution seems like the right thing to do.

@tfranzel tfranzel added the bug Something isn't working label Mar 16, 2021
@tfranzel tfranzel added the fix confirmation pending issue has been fixed and confirmation from issue reporter is pending label Apr 3, 2021
@tfranzel
Copy link
Owner

tfranzel commented Apr 3, 2021

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.

@tfranzel tfranzel closed this as completed Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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