Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set required fields in PATCH API in Swagger UI

I’m using drf-spectacular and here’s code in settings.py

SPECTACULAR_SETTINGS = {
    'TITLE': 'TITLE',
    'VERSION': '1.0.0',
    'SCHEMA_PATH_PREFIX_TRIM': True,
    'PREPROCESSING_HOOKS': ["custom.url_remover.preprocessing_filter_spec"],  
}

in serializers.py

class ChangePasswordSerilaizer(serializers.Serializer):
    current_password = serializers.CharField(write_only=True, min_length=8, required=True)
    new_password = serializers.CharField(write_only=True, min_length=8, required=True)
    confirm_new_password = serializers.CharField(write_only=True, min_length=8, required=True)

but still fields in request body are showing not required

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

change your SPECTACULAR_SETTINGS

    SPECTACULAR_SETTINGS = {
        'TITLE': 'APP NAME',
        'VERSION': '1.0.0',
        'SCHEMA_PATH_PREFIX_TRIM': True,
        'PREPROCESSING_HOOKS': ["custom.url_remover.preprocessing_filter_spec"], 
        'COMPONENT_SPLIT_PATCH': False, 
    }

by default COMPONENT_SPLIT_PATCH is true in SPECTACULAR_SETTINGS so you can simply override('COMPONENT_SPLIT_PATCH': False) it to fix this problem

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading