Skip to content

Commit 72ba4bb

Browse files
committed
@pcrespov review: use pydantic examples
1 parent edbf177 commit 72ba4bb

File tree

1 file changed

+32
-1
lines changed
  • packages/settings-library/src/settings_library

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
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

@@ -8,7 +10,7 @@
810

911

1012
class RabbitDsn(AnyUrl):
11-
allowed_schemes = {"amqp", "amqps"}
13+
allowed_schemes: ClassVar[set[str]] = {"amqp", "amqps"}
1214

1315

1416
class RabbitSettings(BaseCustomSettings):
@@ -33,3 +35,32 @@ def dsn(self) -> str:
3335
)
3436
)
3537
return rabbit_dsn
38+
39+
@staticmethod
40+
def _update_json_schema_extra(schema: JsonDict) -> None:
41+
schema.update(
42+
{
43+
"examples": [
44+
{
45+
"RABBIT_HOST": "rabbitmq.example.com",
46+
"RABBIT_USER": "guest",
47+
"RABBIT_PASSWORD": "guest-password",
48+
"RABBIT_SECURE": False,
49+
"RABBIT_PORT": 5672,
50+
},
51+
{
52+
"RABBIT_HOST": "secure.rabbitmq.example.com",
53+
"RABBIT_USER": "guest",
54+
"RABBIT_PASSWORD": "guest-password",
55+
"RABBIT_SECURE": True,
56+
"RABBIT_PORT": 15672,
57+
},
58+
]
59+
}
60+
)
61+
62+
model_config = ConfigDict(
63+
extra="ignore",
64+
populate_by_name=True,
65+
json_schema_extra=_update_json_schema_extra,
66+
)

0 commit comments

Comments
 (0)