-
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
Non-blank strings emit schema that allows blanks #186
Comments
hi @zefciu, that is quite interesting and has been an oversight until now. |
revisited this. We now add
drf-spectacular/drf_spectacular/settings.py Lines 42 to 47 in bdea0c2
|
This behavior is the rule, not the exception. Validation only occurs during input (from the request), validations are mostly ignored on output (response). By that logic, for example you should not add |
@intgr totally agree. I have always brushed over this aspect. However, I would assume that the majority do use their serializers in a predictable symmetric way. Also I consider the blank thing a DRF/Django quirk that is worth pointing out more prominently in the schema. Theoretically we could remove all "restricting" keywords from Imho there will always be some gray area due to the way DRF works. Can we gain something here by being pedantic? |
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
As stated in OpenAPI3 documentation: “ Note that an empty string "" is a valid string unless minLength or pattern is specified. ”
https://swagger.io/docs/specification/data-models/data-types/#string In drf, however "" is not a valid input for fields that have
allow_blank
set to False. drf-spectacular emits a field that allows blanks even if allow_blank is set to False.To Reproduce
A simple way to show this error is to create any API that contains a non-blank character field and then run schemathesis against it. Output:
Proposed fix
A simple idea to fix this would be to add
minLength: 1
to all the fields that aren’t marked withallow_blank
.Please confirm that this would be a good solution, so I can work on a patch.
The text was updated successfully, but these errors were encountered: