-
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
How to create parameters with regex patterns? #738
Comments
Hi! it is simply an oversight. I just added the possibility to add a pattern via the interface. You can also do OpenApiParameter(name='test', type=OpenApiTypes.REGEX, pattern='^[0-9]{3}$')
OpenApiParameter(name='test', type=str, pattern='^[0-9]{3}$') # alternatively Until this is released you can also do it manually with (raw schema support) OpenApiParameter(name='test', type={'pattern': '^[0-9]{3}$', 'type': 'string', 'format': 'regex'}) |
OK, interesting. I'd have to check my code at work, but I did try to add the |
@PaulWay you are reading it wrong 😄 I just added the parameter with above commit. You refer to the you can write arbitrary schemas into a dict and pass it to |
Ah - I'm with you now :-) |
On a similar note would it be possible/is there already a method to put a max_length constraint on OpenApiParameters (similar to fields)? |
@aupi0 no sry there is not. You would need to write a small custom schema dict as outlined above. The interface is already somewhat large and I don't want to dilute it further. |
I'll close this issue as the initial ask as added |
Hi there!
I'm just coming to
drf_spectacular
after usingdrf_yasg
for many years, and I'm having to change all myopenapi.Parameter
definitions over toOpenApiParameter
. What's really puzzling me is that I can settype=OpenApiTypes.REGEX
, but I cannot set a pattern when initialising the parameter. I understand that serializers can use Regex validators, but I can't see how to add a regex pattern to a parameter.I'm prepared to write the code to support it, but I thought I'd check first the correct way of setting a regex pattern on a parameter.
Thanks in advance,
Paul
The text was updated successfully, but these errors were encountered: