-
Notifications
You must be signed in to change notification settings - Fork 270
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
Request component properties not marked as required when using COMPONENT_SPLIT_REQUEST=True
#243
Comments
COMPONENT_SPLIT_REQUEST=True
COMPONENT_SPLIT_REQUEST=True
is invalid according to DRF and won't run. you cannot set simply removing Required:
type: object
properties:
read_only_property:
type: string
readOnly: true
required_property:
type: string
required:
- read_only_property
- required_property
RequiredRequest:
type: object
properties:
required_property:
type: string
required:
- required_property |
Oops, yea you can't explicitly set I only included the read only property here to show some difference between the generated class RequiredSerializer(serializers.Serializer):
required_property = serializers.CharField(required=True) --> Required:
type: object
properties:
required_property:
type: string
required:
- required_property
RequiredRequest:
type: object
properties:
required_property:
type: string
required:
- required_property # this is not included at the moment, even though it is a required field |
@tfranzel I'm going to open an issue on DRF because frankly, a |
i cannot confirm this statement. for me this is actually included. i tried to compile all the cases here: class XSerializer(serializers.Serializer):
plain_property = serializers.CharField()
required_property = serializers.CharField(required=True)
non_required_property = serializers.CharField(required=False)
read_only_property = serializers.CharField(read_only=True)
read_only_non_required_property = serializers.CharField(read_only=True, required=False)
write_only_property = serializers.CharField(write_only=True)
write_only_non_required_property = serializers.CharField(write_only=True, required=False) which yielded for me: X:
type: object
properties:
plain_property:
type: string
required_property:
type: string
non_required_property:
type: string
read_only_property:
type: string
readOnly: true
read_only_non_required_property:
type: string
readOnly: true
required:
- plain_property
- read_only_non_required_property
- read_only_property
- required_property
XRequest:
type: object
properties:
plain_property:
type: string
required_property:
type: string
non_required_property:
type: string
write_only_property:
type: string
writeOnly: true
write_only_non_required_property:
type: string
writeOnly: true
required:
- plain_property
- required_property
- write_only_property the the only thing that bothers me here is |
Hm, I guess my issue is more complicated than that. Thanks for looking into it! I'll dig into find the real root cause at some point |
How would I go about telling spectacular that my field is |
https://drf-spectacular.readthedocs.io/en/latest/settings.html you can either go the proper route with if you just want to fix the |
I tried setting |
the answer is right there. the setting is off by default because serializers almost always contain fields on response even if they are not required. My interpretation of the |
I guess as a note, tools like schemathesis seem to use the |
Describe the bug
When setting the
COMPONENT_SPLIT_REQUEST
setting toTrue
, the generated components do not indicate that any field is required.To Reproduce
COMPONENT_SPLIT_REQUEST=True
in settingsThis serializer produces the following components:
Expected behavior
In the above example
RequiredRequest
is missing therequired
properties list. It should generateThis is causing issues with client code generation tools.
The text was updated successfully, but these errors were encountered: