Skip to content

Commit e3ffe7d

Browse files
committed
annotated
1 parent aad32e7 commit e3ffe7d

File tree

5 files changed

+42
-76
lines changed

5 files changed

+42
-76
lines changed

api/specs/web-server/_users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
MyProfileGet,
1212
MyProfilePatch,
1313
PermissionGet,
14-
SearchQueryParams,
1514
ThirdPartyToken,
1615
TokenCreate,
1716
UserGet,
17+
UsersSearchQueryParams,
1818
)
1919
from models_library.api_schemas_webserver.users_preferences import PatchRequestBody
2020
from models_library.generics import Envelope
@@ -146,7 +146,7 @@ async def list_user_permissions():
146146
"po",
147147
],
148148
)
149-
async def search_users(_params: Annotated[SearchQueryParams, Depends()]):
149+
async def search_users(_params: Annotated[UsersSearchQueryParams, Depends()]):
150150
# NOTE: see `Search` in `Common Custom Methods` in https://cloud.google.com/apis/design/custom_methods
151151
...
152152

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

Lines changed: 0 additions & 45 deletions
This file was deleted.

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Annotated, Any, Literal
55
from uuid import UUID
66

7+
from common_library.basic_types import DEFAULT_FACTORY
78
from common_library.users_enums import UserStatus
89
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator
910

@@ -17,17 +18,18 @@
1718

1819

1920
#
20-
# TOKENS resource
21+
# THIRD-PARTY TOKENS
2122
#
2223
class ThirdPartyToken(BaseModel):
2324
"""
2425
Tokens used to access third-party services connected to osparc (e.g. pennsieve, scicrunch, etc)
2526
"""
2627

27-
service: str = Field(
28-
..., description="uniquely identifies the service where this token is used"
29-
)
30-
token_key: UUID = Field(..., description="basic token key")
28+
service: Annotated[
29+
str,
30+
Field(description="uniquely identifies the service where this token is used"),
31+
]
32+
token_key: Annotated[UUID, Field(..., description="basic token key")]
3133
token_secret: UUID | None = None
3234

3335
model_config = ConfigDict(
@@ -45,7 +47,7 @@ class TokenCreate(ThirdPartyToken):
4547

4648

4749
#
48-
# Permissions
50+
# PERMISSIONS
4951
#
5052
class Permission(BaseModel):
5153
name: str
@@ -57,7 +59,7 @@ class PermissionGet(Permission, OutputSchema):
5759

5860

5961
#
60-
# My Profile
62+
# MY PROFILE
6163
#
6264

6365

@@ -179,16 +181,19 @@ def _validate_user_name(cls, value: str):
179181

180182

181183
#
182-
# User
184+
# USER
183185
#
184186

185187

186-
class SearchQueryParams(BaseModel):
187-
email: str = Field(
188-
min_length=3,
189-
max_length=200,
190-
description="complete or glob pattern for an email",
191-
)
188+
class UsersSearchQueryParams(BaseModel):
189+
email: Annotated[
190+
str,
191+
Field(
192+
min_length=3,
193+
max_length=200,
194+
description="complete or glob pattern for an email",
195+
),
196+
]
192197

193198

194199
class UserGet(OutputSchema):
@@ -199,24 +204,29 @@ class UserGet(OutputSchema):
199204
phone: str | None
200205
address: str | None
201206
city: str | None
202-
state: str | None = Field(description="State, province, canton, ...")
207+
state: Annotated[str | None, Field(description="State, province, canton, ...")]
203208
postal_code: str | None
204209
country: str | None
205-
extras: dict[str, Any] = Field(
206-
default_factory=dict,
207-
description="Keeps extra information provided in the request form",
208-
)
210+
extras: Annotated[
211+
dict[str, Any],
212+
Field(
213+
default_factory=dict,
214+
description="Keeps extra information provided in the request form",
215+
),
216+
] = DEFAULT_FACTORY
209217

210218
# authorization
211-
invited_by: str | None = Field(default=None)
219+
invited_by: str | None = None
212220

213221
# user status
214222
registered: bool
215223
status: UserStatus | None
216-
products: list[ProductName] | None = Field(
217-
default=None,
218-
description="List of products this users is included or None if fields is unset",
219-
)
224+
products: Annotated[
225+
list[ProductName] | None,
226+
Field(
227+
description="List of products this users is included or None if fields is unset",
228+
),
229+
]
220230

221231
@field_validator("status")
222232
@classmethod

services/web/server/src/simcore_service_webserver/users/_users_rest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from models_library.api_schemas_webserver.users import (
66
MyProfileGet,
77
MyProfilePatch,
8-
SearchQueryParams,
8+
UsersSearchQueryParams,
99
)
1010
from servicelib.aiohttp import status
1111
from servicelib.aiohttp.requests_validation import (
@@ -106,8 +106,8 @@ async def search_users(request: web.Request) -> web.Response:
106106
req_ctx = UsersRequestContext.model_validate(request)
107107
assert req_ctx.product_name # nosec
108108

109-
query_params: SearchQueryParams = parse_request_query_parameters_as(
110-
SearchQueryParams, request
109+
query_params: UsersSearchQueryParams = parse_request_query_parameters_as(
110+
UsersSearchQueryParams, request
111111
)
112112

113113
found = await _users_service.search_users(

services/web/server/src/simcore_service_webserver/users/common/_schemas.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" input/output datasets used in the rest-API
22
3-
NOTE: Most of the model schemas are in `models_library.api_schemas_webserver.users`, the rest (hidden or needs a dependency) is here
3+
NOTE: Most of the model schemas are in `models_library.api_schemas_webserver.users`,
4+
the rest (hidden or needs a dependency) is here
45
"""
56

67

@@ -48,7 +49,7 @@ class PreRegisteredUserGet(InputSchema):
4849
dict[str, Any],
4950
Field(
5051
default_factory=dict,
51-
description="Keeps extra information provided in the request form. At most MAX_NUM_EXTRAS fields",
52+
description="Keeps extra information provided in the request form.",
5253
),
5354
]
5455

0 commit comments

Comments
 (0)