Skip to content

Commit e6fa2cf

Browse files
committed
@pcrespov review: use pydantic examples
1 parent 6d111c2 commit e6fa2cf

File tree

1 file changed

+30
-13
lines changed
  • packages/settings-library/src/settings_library

1 file changed

+30
-13
lines changed

packages/settings-library/src/settings_library/rabbit.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from functools import cached_property
2+
from typing import ClassVar
23

4+
from pydantic.config import ConfigDict, JsonDict
35
from pydantic.networks import AnyUrl
46
from pydantic.types import SecretStr
57
from pydantic_settings import SettingsConfigDict
@@ -9,7 +11,7 @@
911

1012

1113
class RabbitDsn(AnyUrl):
12-
allowed_schemes = {"amqp", "amqps"}
14+
allowed_schemes: ClassVar[set[str]] = {"amqp", "amqps"}
1315

1416

1517
class RabbitSettings(BaseCustomSettings):
@@ -35,16 +37,31 @@ def dsn(self) -> str:
3537
)
3638
return rabbit_dsn
3739

38-
model_config = SettingsConfigDict(
39-
json_schema_extra={
40-
"examples": [
41-
# minimal required
42-
{
43-
"RABBIT_SECURE": "1",
44-
"RABBIT_HOST": "localhost",
45-
"RABBIT_USER": "user",
46-
"RABBIT_PASSWORD": "foobar", # NOSONAR
47-
}
48-
],
49-
}
40+
@staticmethod
41+
def _update_json_schema_extra(schema: JsonDict) -> None:
42+
schema.update(
43+
{
44+
"examples": [
45+
{
46+
"RABBIT_HOST": "rabbitmq.example.com",
47+
"RABBIT_USER": "guest",
48+
"RABBIT_PASSWORD": "guest-password",
49+
"RABBIT_SECURE": False,
50+
"RABBIT_PORT": 5672,
51+
},
52+
{
53+
"RABBIT_HOST": "secure.rabbitmq.example.com",
54+
"RABBIT_USER": "guest",
55+
"RABBIT_PASSWORD": "guest-password",
56+
"RABBIT_SECURE": True,
57+
"RABBIT_PORT": 15672,
58+
},
59+
]
60+
}
61+
)
62+
63+
model_config = ConfigDict(
64+
extra="ignore",
65+
populate_by_name=True,
66+
json_schema_extra=_update_json_schema_extra,
5067
)

0 commit comments

Comments
 (0)