Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ Upgrade API server (Pydantic v2) #6511

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
079e9d4
upgrade reqs
giancarloromeo Oct 10, 2024
0fb353a
fix code
giancarloromeo Oct 10, 2024
a7e72c2
fix url type
giancarloromeo Oct 10, 2024
9c1a498
fix typeadapter
giancarloromeo Oct 10, 2024
13502ac
fix download url type
giancarloromeo Oct 10, 2024
7346f8a
fix url type
giancarloromeo Oct 10, 2024
9294f6b
fix typecheck
giancarloromeo Oct 15, 2024
0184526
Merge branch 'pydantic_v2_migration' into is4481/upgrade-api-server
giancarloromeo Oct 15, 2024
f592daa
fix typechecking
giancarloromeo Oct 15, 2024
1d713bf
fix typecheck
giancarloromeo Oct 15, 2024
7968bb3
continue migration
giancarloromeo Oct 15, 2024
6c2c044
continue fixing
giancarloromeo Oct 15, 2024
21d5906
fix url type
giancarloromeo Oct 15, 2024
04cd728
continue upgrade
giancarloromeo Oct 16, 2024
ba3b868
⬆️ ♻️ Upgrade pagination customisation in api-server (#6545)
pcrespov Oct 16, 2024
29f67ff
fix tests
giancarloromeo Oct 21, 2024
b06e171
fix pagination
giancarloromeo Oct 21, 2024
a974048
fix url
giancarloromeo Oct 21, 2024
85d01a4
Merge branch 'pydantic_v2_migration' into is4481/upgrade-api-server
giancarloromeo Oct 21, 2024
df11489
fix validation
giancarloromeo Oct 21, 2024
8dd57a7
fix frozen field
giancarloromeo Oct 21, 2024
e01f8c1
fix url
giancarloromeo Oct 21, 2024
4aae323
continue fixing
giancarloromeo Oct 21, 2024
00c4164
continue fixing
giancarloromeo Oct 22, 2024
2331b89
continue fixing
giancarloromeo Oct 22, 2024
f8ac22b
fix test
giancarloromeo Oct 22, 2024
866ded6
upgrade reqs
giancarloromeo Oct 22, 2024
f68123b
fix mypy
giancarloromeo Oct 22, 2024
e9abfbd
fix url
giancarloromeo Oct 22, 2024
51d1aca
fix wallet
giancarloromeo Oct 22, 2024
245739e
fix mypy
giancarloromeo Oct 22, 2024
f8145be
fix test
giancarloromeo Oct 22, 2024
55f5af5
fix openapi spec validation
giancarloromeo Oct 22, 2024
8bdfa5e
fix serialization
giancarloromeo Oct 22, 2024
be61302
revert HttpUrl legacy
giancarloromeo Oct 22, 2024
c15224e
fix url
giancarloromeo Oct 22, 2024
003aff8
fix http
giancarloromeo Oct 22, 2024
3c0c9fe
fix mock
giancarloromeo Oct 22, 2024
08ea530
fix starlette exception handlers
giancarloromeo Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from common_library.pydantic_basic_types import LongTruncatedStr, ShortTruncatedStr
from models_library.folders import FolderID
from models_library.workspaces import WorkspaceID
from pydantic import Field, HttpUrl, field_validator
from pydantic import ConfigDict, Field, HttpUrl, field_validator

from ..api_schemas_long_running_tasks.tasks import TaskGet
from ..emails import LowerCaseEmailStr
Expand Down Expand Up @@ -78,9 +78,13 @@ class ProjectGet(OutputSchema):
ui: EmptyModel | StudyUI | None = None
quality: dict[str, Any] = {}
dev: dict | None = None
permalink: ProjectPermalink = FieldNotRequired()
workspace_id: WorkspaceID | None
folder_id: FolderID | None
permalink: ProjectPermalink | None = FieldNotRequired()
workspace_id: WorkspaceID | None = None
folder_id: FolderID | None = None

model_config = ConfigDict(
frozen=False
)

_empty_description = field_validator("description", mode="before")(
none_to_empty_str_pre_validator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class WalletGet(OutputSchema):
created: datetime
modified: datetime

model_config = ConfigDict(
frozen=False,
)


class WalletGetWithAvailableCredits(WalletGet):
available_credits: Decimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class CapturedParameterSchema(BaseModel):
title: str | None = None
type_: Literal["str", "int", "float", "bool"] | None = Field(None, alias="type")
pattern: str | None
pattern: str | None = None
format_: Literal["uuid"] | None = Field(None, alias="format")
exclusiveMinimum: bool | None
minimum: int | None
anyOf: list["CapturedParameterSchema"] | None
allOf: list["CapturedParameterSchema"] | None
oneOf: list["CapturedParameterSchema"] | None
exclusiveMinimum: bool | None = None
minimum: int | float | None = None
anyOf: list["CapturedParameterSchema"] | None = None
allOf: list["CapturedParameterSchema"] | None = None
oneOf: list["CapturedParameterSchema"] | None = None

class Config:
validate_always = True
Expand All @@ -34,15 +34,15 @@ def preprocess_type_(cls, val):
@model_validator(mode="after")
@classmethod
def check_compatibility(cls, values):
type_ = values.get("type_")
pattern = values.get("pattern")
format_ = values.get("format_")
anyOf = values.get("anyOf")
allOf = values.get("allOf")
oneOf = values.get("oneOf")
type_ = values.type_
pattern = values.pattern
format_ = values.format_
anyOf = values.anyOf
allOf = values.allOf
oneOf = values.oneOf
if not any([type_, oneOf, anyOf, allOf]):
type_ = "str" # this default is introduced because we have started using json query params in the webserver
values["type_"] = type_
values.type_ = type_
if type_ != "str" and any([pattern, format_]):
msg = f"For {type_=} both {pattern=} and {format_=} must be None"
raise ValueError(msg)
Expand Down
8 changes: 2 additions & 6 deletions services/api-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ reqs: ## compiles pip requirements (.in -> .txt)


# specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator)
OPENAPI_GENERATOR_NAME := itisfoundation/openapi-generator-cli-openapi-generator-v4.2.3
OPENAPI_GENERATOR_TAG := v0
OPENAPI_GENERATOR_NAME := openapitools/openapi-generator-cli
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Official tool used for validation

OPENAPI_GENERATOR_TAG := latest
OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG)

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

# patching version until tools adapted
@sed -i 's/"openapi": "3.1.0",/"openapi": "3.0.2",/g' $@
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore



# validates OAS file: $@
docker run --rm \
--volume "$(CURDIR):/local" \
Expand Down
Loading
Loading