Skip to content
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

Map Django's EmailField to OpenAPI string format email #1329

Open
Zerotask opened this issue Nov 6, 2024 · 1 comment
Open

Map Django's EmailField to OpenAPI string format email #1329

Zerotask opened this issue Nov 6, 2024 · 1 comment

Comments

@Zerotask
Copy link
Contributor

Zerotask commented Nov 6, 2024

Is your feature request related to a problem? Please describe.
If you have a model which defines an EmailField, the generated OpenAPI specification is displayed as:
email string <= 254 characters
image

If you manually define this email field as email: pydantic.EmailStr in your schema, it will be displayed as:
email string email
image

So in this case, the string format email is used:
https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings

image

Describe the solution you'd like

Automatically map Django's EmailField to OpenAPI string format email

There are probably other Django field classes, which could be enhanced with string formats to be more precise

@Zerotask
Copy link
Contributor Author

Zerotask commented Nov 6, 2024

I noticed the same issue with Django's URLField, which is displayed as a regular string, but if you annotate it with pydantic.HttpUrl in your schema, it will be displayed with the OpenAPI string format uri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant