Using TypeDict with djangorestframework_camel_case sets required fields to optional
See original GitHub issueHi, when using TypeDict
in combination with the drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields
hook all fields that are converted from snake_case to camelCase are set to optional.
Serializer:
class RankData(TypedDict):
value: int
created_at: str
name: str
rank_by_value: bool
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,
)
Settings:
SPECTACULAR_SETTINGS = {
"POSTPROCESSING_HOOKS": [
"drf_spectacular.hooks.postprocess_schema_enums",
"drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields",
],
}
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):
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Camel case JSON support for Django REST framework. - GitHub
GitHub - vbabiy/djangorestframework-camel-case: Camel case JSON support for Django REST ... To use the second case, specify it in your django settings file....
Read more >Validate Python TypedDict at runtime - Stack Overflow
The simplest solution I found works using pydantic. from typing import cast, TypedDict import pydantic class SomeDict(TypedDict): val: int ...
Read more >PEP 655 – Marking individual TypedDict items as required or ...
The difficulty is that the best word for marking a potentially-missing key, Optional[] , is already used in Python for a completely different...
Read more >T. Franzel - drf-spectacular
Sane and flexible OpenAPI 3 schema generation for Django REST framework. Documentation is an integral part of API development and OpenAPI 3 ...
Read more >Making a field required for POST, but optional for PUTs?
The POST includes username and password, along with some optional fields (e.g. ... case, you just need to use PATCH instead of PUT,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Everything works perfectly now 👍
did a drive-by bugfix that came to my attention. this should work now as expected.