-
Notifications
You must be signed in to change notification settings - Fork 260
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
Using TypeDict with djangorestframework_camel_case sets required fields to optional #861
Comments
Looks like the string replacement does not account for nested objects properly. It goes through the nested props properly, but it fails on nested required list. |
Thanks for the quick fix @tfranzel |
I just noticed one small issue. After adding a nested Serializer: class ChildRankData(TypedDict):
value: int
created_at: str
class RankData(TypedDict):
value: int
created_at: str
name: str
rank_by_value: bool
child_rank: List[ChildRankData]
class RankSerializer(serializers.Serializer):
rank_data = serializers.SerializerMethodField()
def get_rank_data(self) -> RankData:
return RankData(
value=290,
created_at="2022-01-01",
name="Checkpoint A",
rank_by_value=False,
child_rank=[ChildRankData(value=123, created_at="022-02-02")],
) |
ahh yes, I forgot about that case, since we now do translation manually. |
Also use feature detection for __required_keys__ instead of probing Py version
did a drive-by bugfix that came to my attention. this should work now as expected. |
Everything works perfectly now 👍 |
Hi, when using
TypeDict
in combination with thedrf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields
hook all fields that are converted from snake_case to camelCase are set to optional.Serializer:
Settings:
This produces the following schema:
-> All names that are converted from snake_case to camelCase are set to optional.
Removing
"drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields"
from the settings produces the correct schema (all fields are required):The text was updated successfully, but these errors were encountered: