|
4 | 4 | from enum import Enum |
5 | 5 | from typing import Any, Dict, Generator, Iterable, List, Optional, Set, Union |
6 | 6 |
|
7 | | -from .properties import EnumListProperty, EnumProperty, Property, ReferenceListProperty, RefProperty, property_from_dict |
| 7 | +from .properties import ( |
| 8 | + DateProperty, |
| 9 | + DateTimeProperty, |
| 10 | + EnumListProperty, |
| 11 | + EnumProperty, |
| 12 | + Property, |
| 13 | + ReferenceListProperty, |
| 14 | + RefProperty, |
| 15 | + property_from_dict, |
| 16 | +) |
8 | 17 | from .reference import Reference |
9 | 18 | from .responses import ListRefResponse, RefResponse, Response, response_from_dict |
10 | 19 |
|
@@ -108,11 +117,16 @@ def _add_parameters(self, data: Dict[str, Any]) -> None: |
108 | 117 | prop = property_from_dict( |
109 | 118 | name=param_dict["name"], required=param_dict["required"], data=param_dict["schema"] |
110 | 119 | ) |
111 | | - if ( |
| 120 | + if isinstance(prop, DateProperty): |
| 121 | + self.relative_imports.add("from datetime import date") |
| 122 | + elif isinstance(prop, DateTimeProperty): |
| 123 | + self.relative_imports.add("from datetime import datetime") |
| 124 | + elif ( |
112 | 125 | isinstance(prop, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) |
113 | 126 | and prop.reference |
114 | 127 | ): |
115 | 128 | self.relative_imports.add(import_string_from_reference(prop.reference, prefix="..models")) |
| 129 | + |
116 | 130 | if param_dict["in"] == ParameterLocation.QUERY: |
117 | 131 | self.query_parameters.append(prop) |
118 | 132 | elif param_dict["in"] == ParameterLocation.PATH: |
@@ -168,7 +182,11 @@ def from_dict(d: Dict[str, Any], /) -> Schema: |
168 | 182 | required_properties.append(p) |
169 | 183 | else: |
170 | 184 | optional_properties.append(p) |
171 | | - if isinstance(p, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) and p.reference: |
| 185 | + if isinstance(p, DateTimeProperty): |
| 186 | + relative_imports.add("from datetime import datetime") |
| 187 | + elif isinstance(p, DateProperty): |
| 188 | + relative_imports.add("from datetime import date") |
| 189 | + elif isinstance(p, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) and p.reference: |
172 | 190 | relative_imports.add(import_string_from_reference(p.reference)) |
173 | 191 | schema = Schema( |
174 | 192 | reference=Reference.from_ref(d["title"]), |
|
0 commit comments