|
8 | 8 |
|
9 | 9 | from django.urls import resolve |
10 | 10 | import openapi_core |
11 | | -from openapi_core.contrib.django import DjangoOpenAPIResponseFactory |
12 | 11 | from openapi_core.contrib.django import DjangoOpenAPIRequestFactory |
13 | | -from openapi_core.schema.schemas.models import Format |
14 | | -from openapi_core.validation.request.validators import RequestValidator |
15 | | -from openapi_core.validation.response.validators import ResponseValidator |
16 | | -from openapi_core.schema.parameters.exceptions import OpenAPIParameterError |
| 12 | +from openapi_core.contrib.django import DjangoOpenAPIResponseFactory |
17 | 13 | from openapi_core.schema.media_types.exceptions import OpenAPIMediaTypeError |
| 14 | +from openapi_core.schema.parameters.exceptions import OpenAPIParameterError |
18 | 15 | from openapi_core.templating import util |
| 16 | +from openapi_core.unmarshalling.schemas.formatters import Formatter |
| 17 | +from openapi_core.validation.request.validators import RequestValidator |
| 18 | +from openapi_core.validation.response.validators import ResponseValidator |
19 | 19 | from rest_framework import status |
20 | 20 | import yaml |
21 | 21 |
|
@@ -57,17 +57,25 @@ def __call__(self, value): |
57 | 57 |
|
58 | 58 |
|
59 | 59 | CUSTOM_FORMATTERS = { |
60 | | - 'uri': Format(str, RegexValidator( |
61 | | - r'^(?:http|ftp)s?://' |
62 | | - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa |
63 | | - r'localhost|' |
64 | | - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' |
65 | | - r'(?::\d+)?' |
66 | | - r'(?:/?|[/?]\S+)$')), |
67 | | - 'iso8601': Format(str, RegexValidator( |
68 | | - r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$')), |
69 | | - 'email': Format(str, RegexValidator( |
70 | | - r'[^@]+@[^@]+\.[^@]+')), |
| 60 | + 'uri': Formatter.from_callables( |
| 61 | + RegexValidator( |
| 62 | + r'^(?:http|ftp)s?://' |
| 63 | + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa: E501 |
| 64 | + r'localhost|' |
| 65 | + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' |
| 66 | + r'(?::\d+)?' |
| 67 | + r'(?:/?|[/?]\S+)$', |
| 68 | + ), |
| 69 | + str, |
| 70 | + ), |
| 71 | + 'iso8601': Formatter.from_callables( |
| 72 | + RegexValidator(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$'), |
| 73 | + str, |
| 74 | + ), |
| 75 | + 'email': Formatter.from_callables( |
| 76 | + RegexValidator(r'[^@]+@[^@]+\.[^@]+'), |
| 77 | + str, |
| 78 | + ), |
71 | 79 | } |
72 | 80 |
|
73 | 81 |
|
|
0 commit comments