Re: How to not allow additional properties

2018-01-16 Thread Daniel Chimeno
Hi, thanks for the response.
The reasons is because I'm migrating a previous API design that does that, 
so I'm keeping that way.
I've asked just in case there were a more generic solution for that.

Just come to my mind if there is a way to view the fields that are in a 
declared serializer.

In this example:
class IntervalSerializer(serializers.Serializer):
month = serializers.DateField(format='%Y-%m', input_formats=['%Y-%m'])
day_of_week = serializers.IntegerField(min_value=1, max_value=7)
start_hour = serializers.IntegerField(min_value=0, max_value=24)
end_hour = serializers.IntegerField(min_value=1, max_value=24)


something like:
qs = IntervalSerializer().defined_fields()

could work to make the whitelisting allowed params..





El martes, 16 de enero de 2018, 5:58:24 (UTC+1), Jani Tiainen escribió:
>
> Hi,
>
> Is there a reason you want to reject requests with extra data rather than 
> just ignore extra values?
>
> One way to do that could be whitelisting allowed params per view but that 
> you have to do yourself. You could probably use DRF authentication API for 
> that.
>
> 15.1.2018 18.43 "Daniel Chimeno"  
> kirjoitti:
>
>> Hello!
>>
>> How could I deny requests that has additional properties?
>> Example:
>>
>> class IntervalSerializer(serializers.Serializer):
>> month = serializers.DateField(format='%Y-%m', input_formats=['%Y-%m'])
>> day_of_week = serializers.IntegerField(min_value=1, max_value=7)
>> start_hour = serializers.IntegerField(min_value=0, max_value=24)
>> end_hour = serializers.IntegerField(min_value=1, max_value=24)
>>
>> I would like to allow incoming requests like:
>> {'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2}
>>
>>
>> but to not allow incoming requestse like:
>> {'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2, 
>> 'another_attribute': 3}
>>
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-rest-framework+unsubscr...@googlegroups.com 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to not allow additional properties

2018-01-15 Thread Jani Tiainen
Hi,

Is there a reason you want to reject requests with extra data rather than
just ignore extra values?

One way to do that could be whitelisting allowed params per view but that
you have to do yourself. You could probably use DRF authentication API for
that.

15.1.2018 18.43 "Daniel Chimeno"  kirjoitti:

> Hello!
>
> How could I deny requests that has additional properties?
> Example:
>
> class IntervalSerializer(serializers.Serializer):
> month = serializers.DateField(format='%Y-%m', input_formats=['%Y-%m'])
> day_of_week = serializers.IntegerField(min_value=1, max_value=7)
> start_hour = serializers.IntegerField(min_value=0, max_value=24)
> end_hour = serializers.IntegerField(min_value=1, max_value=24)
>
> I would like to allow incoming requests like:
> {'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2}
>
>
> but to not allow incoming requestse like:
> {'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2,
> 'another_attribute': 3}
>
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to not allow additional properties

2018-01-15 Thread Daniel Chimeno
Hello!

How could I deny requests that has additional properties?
Example:

class IntervalSerializer(serializers.Serializer):
month = serializers.DateField(format='%Y-%m', input_formats=['%Y-%m'])
day_of_week = serializers.IntegerField(min_value=1, max_value=7)
start_hour = serializers.IntegerField(min_value=0, max_value=24)
end_hour = serializers.IntegerField(min_value=1, max_value=24)

I would like to allow incoming requests like:
{'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2}


but to not allow incoming requestse like:
{'month': '2017-03', 'day_of_week': 7, 'start_hour': 3, 'end_hour': 2, 
'another_attribute': 3}


Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.