-
Notifications
You must be signed in to change notification settings - Fork 265
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
OpenAPI schema contains invalid unicode characters if project uses a Django URL field #175
Comments
oh... i think it's difficult issue yaml/pyyaml#250 YAML Standard Spec does not allow these things therefore but regex should be allow to include unicode like a and drf-spectacular should be trade off
or
in my opinion, The second seems more appropriate. I haven't checked it out yet. but P.S. Oh and , I'm not a core contributor so it's just only my opinion |
@KimSoungRyoul thanks for lookup that up. that is a tricky one! ok so lets get down to brass tacks.
these are the assumptions i currently hold:
with that said, these are the problems:
so i would simply propose removing only the Django URL regex and adding |
@fyhertz so this is the current state. please check this out and close the issue if it works for you.
the normalizing even worked surprisingly well for the URL pattern. i tested it with https://editor.swagger.io/ (in chrome 86) and it properly validated all URLs i tried. But for compliance sake i opted not to include it anymore. parameters:
- in: header
name: url_test
required: True
schema:
type: string
format: uri
pattern: ^(?:[a-z0-9.+-]*)://(?:[^\s:@/]+(?::[^\s:@/]*)?@)?(?:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|\[[0-9a-f:.]+\]|([a-z\u00a1-\uffff0-9](?:[a-z\u00a1-\uffff0-9-]{0,61}[a-z\u00a1-\uffff0-9])?(?:\.(?!-)[a-z\u00a1-\uffff0-9-]{1,63}(?<!-))*\.(?!-)(?:[a-z\u00a1-\uffff-]{2,63}|xn--[a-z0-9]{1,59})(?<!-)\.?|localhost))(?::\d{2,5})?(?:[/?#][^\s]*)?$ |
Great ! Thanks @tfranzel, I'm closing the issue. |
Describe the bug
Not really a bug of drf-spectacular per se, but probably worth mentioning:
When using
django.db.model.URLField
, the OpenAPI spec ends up containing the same regex pattern that Django uses to validates URLs:Issues arise when the JSON or YAML parser used by a consumer of OpenAPI specs does not allow such characters. For instance
pyyaml
will raise an error:Expected behavior
What do you think is the best approach here? Should OpenAPI specs produced by drf-spectacular avoid invalid unicode characters?
The text was updated successfully, but these errors were encountered: