|
11 | 11 | from collections import defaultdict |
12 | 12 | from contextlib import nullcontext |
13 | 13 | from enum import Enum |
| 14 | +from functools import cached_property |
14 | 15 | from pathlib import Path |
15 | 16 | from re import Pattern |
16 | 17 | from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypeVar, Union |
|
26 | 27 | load_data, |
27 | 28 | snooper_to_methods, |
28 | 29 | ) |
| 30 | +from datamodel_code_generator.enums import OpenAPIVersion |
29 | 31 | from datamodel_code_generator.parser.base import get_special_path |
30 | 32 | from datamodel_code_generator.parser.jsonschema import ( |
31 | 33 | JsonSchemaObject, |
|
45 | 47 | from datamodel_code_generator._types import OpenAPIParserConfigDict |
46 | 48 | from datamodel_code_generator.config import OpenAPIParserConfig |
47 | 49 | from datamodel_code_generator.model import DataModelFieldBase |
| 50 | + from datamodel_code_generator.parser.schema_version import OpenAPISchemaFeatures |
48 | 51 |
|
49 | 52 |
|
50 | 53 | RE_APPLICATION_JSON_PATTERN: Pattern[str] = re.compile(r"^application/.*json$") |
@@ -167,6 +170,17 @@ class OpenAPIParser(JsonSchemaParser): |
167 | 170 |
|
168 | 171 | SCHEMA_PATHS: ClassVar[list[str]] = ["#/components/schemas"] |
169 | 172 |
|
| 173 | + @cached_property |
| 174 | + def schema_features(self) -> OpenAPISchemaFeatures: |
| 175 | + """Get schema features based on detected OpenAPI version.""" |
| 176 | + from datamodel_code_generator.parser.schema_version import ( # noqa: PLC0415 |
| 177 | + OpenAPISchemaFeatures, |
| 178 | + detect_openapi_version, |
| 179 | + ) |
| 180 | + |
| 181 | + version = detect_openapi_version(self.raw_obj) if self.raw_obj else OpenAPIVersion.Auto |
| 182 | + return OpenAPISchemaFeatures.from_openapi_version(version) |
| 183 | + |
170 | 184 | @classmethod |
171 | 185 | def _create_default_config(cls, options: OpenAPIParserConfigDict) -> OpenAPIParserConfig: |
172 | 186 | """Create an OpenAPIParserConfig from options.""" |
|
0 commit comments