11from functools import cached_property
2+ from typing import ClassVar
23
4+ from pydantic .config import ConfigDict , JsonDict
35from pydantic .networks import AnyUrl
46from pydantic .types import SecretStr
57from pydantic_settings import SettingsConfigDict
911
1012
1113class RabbitDsn (AnyUrl ):
12- allowed_schemes = {"amqp" , "amqps" }
14+ allowed_schemes : ClassVar [ set [ str ]] = {"amqp" , "amqps" }
1315
1416
1517class 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