-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathsettings.py
More file actions
43 lines (33 loc) · 1.2 KB
/
settings.py
File metadata and controls
43 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from pydantic import field_validator
from pydantic_settings import BaseSettings
from pydantic_settings import SettingsConfigDict
ENV_PREFIX = "OPENAPI_SPEC_VALIDATOR_"
RESOLVED_CACHE_MAXSIZE_DEFAULT = 128
class OpenAPISpecValidatorSettings(BaseSettings):
model_config = SettingsConfigDict(
env_prefix=ENV_PREFIX,
extra="ignore",
)
resolved_cache_maxsize: int = RESOLVED_CACHE_MAXSIZE_DEFAULT
@field_validator("resolved_cache_maxsize", mode="before")
@classmethod
def normalize_resolved_cache_maxsize(
cls, value: int | str | None
) -> int:
if value is None:
return RESOLVED_CACHE_MAXSIZE_DEFAULT
if isinstance(value, int):
parsed_value = value
elif isinstance(value, str):
try:
parsed_value = int(value)
except ValueError:
return RESOLVED_CACHE_MAXSIZE_DEFAULT
else:
return RESOLVED_CACHE_MAXSIZE_DEFAULT
if parsed_value < 0:
return RESOLVED_CACHE_MAXSIZE_DEFAULT
return parsed_value
def get_resolved_cache_maxsize() -> int:
settings = OpenAPISpecValidatorSettings()
return settings.resolved_cache_maxsize