Skip to content

Commit dd2aef2

Browse files
committed
Replace getattr with direct config access for schema_version_mode
1 parent 65bdcee commit dd2aef2

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

src/datamodel_code_generator/parser/jsonschema.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ def schema_paths(self) -> list[tuple[str, list[str]]]:
791791
fallback_path = f"#/{fallback_key}"
792792

793793
# Strict mode: only use version-specific path
794-
version_mode = getattr(self.config, "schema_version_mode", None)
795-
if version_mode == VersionMode.Strict:
794+
if self.config.schema_version_mode == VersionMode.Strict:
796795
return [(str(primary_path), [str(primary_key)])]
797796

798797
# Lenient mode (default): check both paths, primary first
@@ -3681,8 +3680,7 @@ def _check_version_specific_features(
36813680
This method checks the raw schema data before Pydantic validation
36823681
to detect features that may not be valid for the declared version.
36833682
"""
3684-
version_mode = getattr(self.config, "schema_version_mode", None)
3685-
if version_mode != VersionMode.Strict:
3683+
if self.config.schema_version_mode != VersionMode.Strict:
36863684
return
36873685

36883686
# Check boolean schemas (Draft 6+)
@@ -3749,8 +3747,7 @@ def _check_array_version_features(
37493747
Warns when prefixItems is used in versions that don't support it,
37503748
or when items as array (tuple style) is used in Draft 2020-12+.
37513749
"""
3752-
version_mode = getattr(self.config, "schema_version_mode", None)
3753-
if version_mode != VersionMode.Strict:
3750+
if self.config.schema_version_mode != VersionMode.Strict:
37543751
return
37553752

37563753
# Check prefixItems usage (Draft 2020-12+ only)

src/datamodel_code_generator/parser/openapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ def get_data_type(self, obj: JsonSchemaObject) -> DataType:
255255
obj.type = [obj.type, "null"]
256256
else:
257257
# OpenAPI 3.1+: nullable is deprecated, still process but warn in Strict mode
258-
version_mode = getattr(self.config, "schema_version_mode", None)
259-
if version_mode == VersionMode.Strict:
258+
if self.config.schema_version_mode == VersionMode.Strict:
260259
warn(
261260
'nullable keyword is deprecated in OpenAPI 3.1, use type: ["string", "null"] instead',
262261
DeprecationWarning,

0 commit comments

Comments
 (0)