Skip to content

Commit 3c17c2b

Browse files
committed
refactor
1 parent b67d799 commit 3c17c2b

File tree

1 file changed

+24
-17
lines changed
  • packages/models-library/src/models_library/api_schemas_webserver

1 file changed

+24
-17
lines changed

packages/models-library/src/models_library/api_schemas_webserver/users.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ValidationInfo,
1717
field_validator,
1818
)
19+
from pydantic.config import JsonDict
1920
from simcore_postgres_database.utils_users import MIN_USERNAME_LEN
2021

2122
from ..basic_types import IDStr
@@ -82,27 +83,33 @@ class MyProfileGet(OutputSchemaWithoutCamelCase):
8283
privacy: MyProfilePrivacyGet
8384
preferences: AggregatedPreferences
8485

86+
@staticmethod
87+
def _update_json_schema_extra(schema: JsonDict) -> None:
88+
schema.update(
89+
{
90+
"examples": [
91+
{
92+
"id": 42,
93+
"login": "[email protected]",
94+
"userName": "bla42",
95+
"role": "admin", # pre
96+
"expirationDate": "2022-09-14", # optional
97+
"preferences": {},
98+
"privacy": {
99+
"hide_username": 0,
100+
"hide_fullname": 0,
101+
"hide_email": 1,
102+
},
103+
},
104+
]
105+
}
106+
)
107+
85108
model_config = ConfigDict(
86109
# NOTE: old models have an hybrid between snake and camel cases!
87110
# Should be unified at some point
88111
populate_by_name=True,
89-
json_schema_extra={
90-
"examples": [
91-
{
92-
"id": 42,
93-
"login": "[email protected]",
94-
"userName": "bla42",
95-
"role": "admin", # pre
96-
"expirationDate": "2022-09-14", # optional
97-
"preferences": {},
98-
"privacy": {
99-
"hide_username": 0,
100-
"hide_fullname": 0,
101-
"hide_email": 1,
102-
},
103-
},
104-
]
105-
},
112+
json_schema_extra=_update_json_schema_extra,
106113
)
107114

108115
@field_validator("role", mode="before")

0 commit comments

Comments
 (0)