Skip to content

Commit 39aed6a

Browse files
⬆️ Upgrade API Server service (Pydantic v2) (#6580)
1 parent 7410516 commit 39aed6a

File tree

73 files changed

+2014
-1306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2014
-1306
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from models_library.folders import FolderID
1111
from models_library.workspaces import WorkspaceID
12-
from pydantic import Field, HttpUrl, field_validator
12+
from pydantic import ConfigDict, Field, HttpUrl, field_validator
1313

1414
from ..api_schemas_long_running_tasks.tasks import TaskGet
1515
from ..basic_types import LongTruncatedStr, ShortTruncatedStr
@@ -78,14 +78,18 @@ class ProjectGet(OutputSchema):
7878
ui: EmptyModel | StudyUI | None = None
7979
quality: dict[str, Any] = {}
8080
dev: dict | None = None
81-
permalink: ProjectPermalink = FieldNotRequired()
82-
workspace_id: WorkspaceID | None
83-
folder_id: FolderID | None
81+
permalink: ProjectPermalink | None = FieldNotRequired()
82+
workspace_id: WorkspaceID | None = None
83+
folder_id: FolderID | None = None
8484

8585
_empty_description = field_validator("description", mode="before")(
8686
none_to_empty_str_pre_validator
8787
)
8888

89+
model_config = ConfigDict(
90+
frozen=False
91+
)
92+
8993

9094
TaskProjectGet: TypeAlias = TaskGet
9195

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from datetime import datetime
22
from decimal import Decimal
3-
from typing import Literal, TypeAlias
3+
from typing import Annotated, Literal, TypeAlias
44

5-
from pydantic import ConfigDict, Field, HttpUrl, field_validator
5+
from pydantic import ConfigDict, Field, HttpUrl, PlainSerializer, field_validator
66

77
from ..basic_types import AmountDecimal, IDStr, NonNegativeDecimal
88
from ..users import GroupID
@@ -21,9 +21,13 @@ class WalletGet(OutputSchema):
2121
created: datetime
2222
modified: datetime
2323

24+
model_config = ConfigDict(
25+
frozen=False
26+
)
27+
2428

2529
class WalletGetWithAvailableCredits(WalletGet):
26-
available_credits: Decimal
30+
available_credits: Annotated[Decimal, PlainSerializer(float)]
2731

2832

2933
class WalletGetPermissions(WalletGet):

packages/pytest-simcore/src/pytest_simcore/helpers/httpx_calls_capture_parameters.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class CapturedParameterSchema(BaseModel):
99
title: str | None = None
1010
type_: Literal["str", "int", "float", "bool"] | None = Field(None, alias="type")
11-
pattern: str | None
11+
pattern: str | None = None
1212
format_: Literal["uuid"] | None = Field(None, alias="format")
13-
exclusiveMinimum: bool | None
14-
minimum: int | None
15-
anyOf: list["CapturedParameterSchema"] | None
16-
allOf: list["CapturedParameterSchema"] | None
17-
oneOf: list["CapturedParameterSchema"] | None
13+
exclusiveMinimum: bool | None = None
14+
minimum: int | float | None = None
15+
anyOf: list["CapturedParameterSchema"] | None = None
16+
allOf: list["CapturedParameterSchema"] | None = None
17+
oneOf: list["CapturedParameterSchema"] | None = None
1818

1919
class Config:
2020
validate_always = True
@@ -34,15 +34,15 @@ def preprocess_type_(cls, val):
3434
@model_validator(mode="after")
3535
@classmethod
3636
def check_compatibility(cls, values):
37-
type_ = values.get("type_")
38-
pattern = values.get("pattern")
39-
format_ = values.get("format_")
40-
anyOf = values.get("anyOf")
41-
allOf = values.get("allOf")
42-
oneOf = values.get("oneOf")
37+
type_ = values.type_
38+
pattern = values.pattern
39+
format_ = values.format_
40+
anyOf = values.anyOf
41+
allOf = values.allOf
42+
oneOf = values.oneOf
4343
if not any([type_, oneOf, anyOf, allOf]):
4444
type_ = "str" # this default is introduced because we have started using json query params in the webserver
45-
values["type_"] = type_
45+
values.type_ = type_
4646
if type_ != "str" and any([pattern, format_]):
4747
msg = f"For {type_=} both {pattern=} and {format_=} must be None"
4848
raise ValueError(msg)

services/api-server/Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ reqs: ## compiles pip requirements (.in -> .txt)
1515

1616

1717
# specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator)
18-
OPENAPI_GENERATOR_NAME := itisfoundation/openapi-generator-cli-openapi-generator-v4.2.3
19-
OPENAPI_GENERATOR_TAG := v0
18+
OPENAPI_GENERATOR_NAME := openapitools/openapi-generator-cli
19+
OPENAPI_GENERATOR_TAG := latest
2020
OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG)
2121

2222
define _create_and_validate_openapi
@@ -25,10 +25,6 @@ define _create_and_validate_openapi
2525
export API_SERVER_DEV_FEATURES_ENABLED=$1; \
2626
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@
2727

28-
# patching version until tools adapted
29-
@sed -i 's/"openapi": "3.1.0",/"openapi": "3.0.2",/g' $@
30-
31-
3228
# validates OAS file: $@
3329
docker run --rm \
3430
--volume "$(CURDIR):/local" \

0 commit comments

Comments
 (0)