Skip to content

Commit

Permalink
move to legacy notation
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Dec 5, 2024
1 parent fe31052 commit 9f20961
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 78 deletions.
30 changes: 15 additions & 15 deletions services/api-server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ServicePricingPlanGet"
"$ref": "#/components/schemas/ServicePricingPlanGetLegacy"
}
}
}
Expand Down Expand Up @@ -3790,7 +3790,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WalletGetWithAvailableCredits"
"$ref": "#/components/schemas/WalletGetWithAvailableCreditsLegacy"
}
}
}
Expand Down Expand Up @@ -3929,7 +3929,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PricingUnitGet"
"$ref": "#/components/schemas/PricingUnitGetLegacy"
}
}
}
Expand Down Expand Up @@ -5121,7 +5121,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WalletGetWithAvailableCredits"
"$ref": "#/components/schemas/WalletGetWithAvailableCreditsLegacy"
}
}
}
Expand Down Expand Up @@ -5234,7 +5234,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WalletGetWithAvailableCredits"
"$ref": "#/components/schemas/WalletGetWithAvailableCreditsLegacy"
}
}
}
Expand Down Expand Up @@ -5336,7 +5336,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetCreditPrice"
"$ref": "#/components/schemas/GetCreditPriceLegacy"
}
}
}
Expand Down Expand Up @@ -5565,7 +5565,7 @@
],
"title": "FileUploadData"
},
"GetCreditPrice": {
"GetCreditPriceLegacy": {
"properties": {
"productName": {
"type": "string",
Expand Down Expand Up @@ -5604,7 +5604,7 @@
"usdPerCredit",
"minPaymentAmountUsd"
],
"title": "GetCreditPrice"
"title": "GetCreditPriceLegacy"
},
"Groups": {
"properties": {
Expand Down Expand Up @@ -6473,7 +6473,7 @@
],
"title": "PricingPlanClassification"
},
"PricingUnitGet": {
"PricingUnitGetLegacy": {
"properties": {
"pricingUnitId": {
"type": "integer",
Expand Down Expand Up @@ -6506,7 +6506,7 @@
"currentCostPerUnit",
"default"
],
"title": "PricingUnitGet"
"title": "PricingUnitGetLegacy"
},
"Profile": {
"properties": {
Expand Down Expand Up @@ -6648,7 +6648,7 @@
"title": "RunningState",
"description": "State of execution of a project's computational workflow\n\nSEE StateType for task state"
},
"ServicePricingPlanGet": {
"ServicePricingPlanGetLegacy": {
"properties": {
"pricingPlanId": {
"type": "integer",
Expand Down Expand Up @@ -6678,7 +6678,7 @@
},
"pricingUnits": {
"items": {
"$ref": "#/components/schemas/PricingUnitGet"
"$ref": "#/components/schemas/PricingUnitGetLegacy"
},
"type": "array",
"title": "Pricingunits"
Expand All @@ -6694,7 +6694,7 @@
"pricingPlanKey",
"pricingUnits"
],
"title": "ServicePricingPlanGet"
"title": "ServicePricingPlanGetLegacy"
},
"Solver": {
"properties": {
Expand Down Expand Up @@ -7035,7 +7035,7 @@
],
"title": "ValidationError"
},
"WalletGetWithAvailableCredits": {
"WalletGetWithAvailableCreditsLegacy": {
"properties": {
"walletId": {
"type": "integer",
Expand Down Expand Up @@ -7106,7 +7106,7 @@
"modified",
"availableCredits"
],
"title": "WalletGetWithAvailableCredits"
"title": "WalletGetWithAvailableCreditsLegacy"
},
"WalletStatus": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fastapi import APIRouter, Depends, status

from ...models.schemas.model_adapter import GetCreditPrice
from ...models.schemas.model_adapter import GetCreditPriceLegacy
from ..dependencies.webserver import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

Expand All @@ -12,7 +12,7 @@
@router.get(
"/price",
status_code=status.HTTP_200_OK,
response_model=GetCreditPrice,
response_model=GetCreditPriceLegacy,
description=FMSG_CHANGELOG_NEW_IN_VERSION.format("0.6.0"),
)
async def get_credits_price(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ...models.basic_types import VersionStr
from ...models.pagination import OnePage, Page, PaginationParams
from ...models.schemas.errors import ErrorGet
from ...models.schemas.model_adapter import ServicePricingPlanGet
from ...models.schemas.model_adapter import ServicePricingPlanGetLegacy
from ...models.schemas.solvers import Solver, SolverKeyId, SolverPort
from ...services.catalog import CatalogApi
from ..dependencies.application import get_reverse_url_mapper
Expand Down Expand Up @@ -262,7 +262,7 @@ async def list_solver_ports(

@router.get(
"/{solver_key:path}/releases/{version}/pricing_plan",
response_model=ServicePricingPlanGet,
response_model=ServicePricingPlanGetLegacy,
description="Gets solver pricing plan\n\n"
+ FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7"),
responses=_SOLVER_STATUS_CODES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
JobOutputs,
)
from ...models.schemas.model_adapter import (
PricingUnitGet,
WalletGetWithAvailableCredits,
PricingUnitGetLegacy,
WalletGetWithAvailableCreditsLegacy,
)
from ...models.schemas.solvers import SolverKeyId
from ...services.catalog import CatalogApi
Expand Down Expand Up @@ -378,7 +378,7 @@ async def get_job_custom_metadata(

@router.get(
"/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/wallet",
response_model=WalletGetWithAvailableCredits,
response_model=WalletGetWithAvailableCreditsLegacy,
responses=WALLET_STATUS_CODES,
description=("Get job wallet\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7")),
)
Expand All @@ -387,7 +387,7 @@ async def get_job_wallet(
version: VersionStr,
job_id: JobID,
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
) -> WalletGetWithAvailableCredits:
) -> WalletGetWithAvailableCreditsLegacy:
job_name = _compose_job_resource_name(solver_key, version, job_id)
_logger.debug("Getting wallet for job '%s'", job_name)

Expand All @@ -398,7 +398,7 @@ async def get_job_wallet(

@router.get(
"/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/pricing_unit",
response_model=PricingUnitGet,
response_model=PricingUnitGetLegacy,
responses=_PRICING_UNITS_STATUS_CODES,
description=(
"Get job pricing unit\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ...exceptions.service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
from ...models.schemas.errors import ErrorGet
from ...models.schemas.model_adapter import WalletGetWithAvailableCredits
from ...models.schemas.model_adapter import WalletGetWithAvailableCreditsLegacy
from ..dependencies.webserver import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

Expand All @@ -29,7 +29,7 @@
@router.get(
"/default",
description="Get default wallet\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7"),
response_model=WalletGetWithAvailableCredits,
response_model=WalletGetWithAvailableCreditsLegacy,
responses=WALLET_STATUS_CODES,
)
async def get_default_wallet(
Expand All @@ -40,7 +40,7 @@ async def get_default_wallet(

@router.get(
"/{wallet_id}",
response_model=WalletGetWithAvailableCredits,
response_model=WalletGetWithAvailableCreditsLegacy,
responses=WALLET_STATUS_CODES,
description="Get wallet\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,85 +7,98 @@
from models_library.api_schemas_api_server.pricing_plans import (
ServicePricingPlanGet as _ServicePricingPlanGet,
)
from models_library.api_schemas_webserver._base import OutputSchema
from models_library.api_schemas_webserver.product import (
GetCreditPrice as _GetCreditPrice,
)
from models_library.api_schemas_webserver.resource_usage import (
PricingUnitGet as _PricingUnitGet,
)
from models_library.api_schemas_webserver.wallets import WalletGet
from models_library.api_schemas_webserver.wallets import (
WalletGetWithAvailableCredits as _WalletGetWithAvailableCredits,
)
from models_library.basic_types import NonNegativeDecimal
from models_library.basic_types import IDStr, NonNegativeDecimal
from models_library.resource_tracker import (
PricingPlanClassification,
PricingPlanId,
PricingUnitId,
UnitExtraInfo,
)
from pydantic import Field, NonNegativeFloat, NonNegativeInt, PlainSerializer


class GetCreditPrice(OutputSchema):
product_name: str
usd_per_credit: Annotated[
NonNegativeDecimal,
PlainSerializer(float, return_type=NonNegativeFloat, when_used="json"),
] | None = Field(
from models_library.users import GroupID
from models_library.wallets import WalletID, WalletStatus
from pydantic import BaseModel, Field, NonNegativeFloat, NonNegativeInt, PlainSerializer


class GetCreditPriceLegacy(BaseModel):
product_name: str = Field(alias="productName")
usd_per_credit: (
Annotated[
NonNegativeDecimal,
PlainSerializer(float, return_type=NonNegativeFloat, when_used="json"),
]
| None
) = Field(
...,
description="Price of a credit in USD. "
"If None, then this product's price is UNDEFINED",
alias="usdPerCredit",
)
min_payment_amount_usd: NonNegativeInt | None = Field(
...,
description="Minimum amount (included) in USD that can be paid for this product"
"Can be None if this product's price is UNDEFINED",
alias="minPaymentAmountUsd",
)


assert set(GetCreditPrice.model_fields.keys()) == set(
assert set(GetCreditPriceLegacy.model_fields.keys()) == set(
_GetCreditPrice.model_fields.keys()
)


class PricingUnitGet(OutputSchema):
pricing_unit_id: PricingUnitId
unit_name: str
unit_extra_info: UnitExtraInfo
class PricingUnitGetLegacy(BaseModel):
pricing_unit_id: PricingUnitId = Field(alias="pricingUnitId")
unit_name: str = Field(alias="unitName")
unit_extra_info: UnitExtraInfo = Field(alias="unitExtraInfo")
current_cost_per_unit: Annotated[
Decimal, PlainSerializer(float, return_type=NonNegativeFloat, when_used="json")
]
] = Field(alias="currentCostPerUnit")
default: bool


assert set(PricingUnitGet.model_fields.keys()) == set(
assert set(PricingUnitGetLegacy.model_fields.keys()) == set(
_PricingUnitGet.model_fields.keys()
)


class WalletGetWithAvailableCredits(WalletGet):
class WalletGetWithAvailableCreditsLegacy(BaseModel):
wallet_id: WalletID = Field(alias="walletId")
name: IDStr
description: str | None = None
owner: GroupID
thumbnail: str | None = None
status: WalletStatus
created: datetime
modified: datetime
available_credits: Annotated[
Decimal, PlainSerializer(float, return_type=NonNegativeFloat, when_used="json")
]
] = Field(alias="availableCredits")


assert set(WalletGetWithAvailableCredits.model_fields.keys()) == set(
assert set(WalletGetWithAvailableCreditsLegacy.model_fields.keys()) == set(
_WalletGetWithAvailableCredits.model_fields.keys()
)


class ServicePricingPlanGet(OutputSchema):
pricing_plan_id: PricingPlanId
display_name: str
class ServicePricingPlanGetLegacy(BaseModel):
pricing_plan_id: PricingPlanId = Field(alias="pricingPlanId")
display_name: str = Field(alias="displayName")
description: str
classification: PricingPlanClassification
created_at: datetime
pricing_plan_key: str
pricing_units: list[PricingUnitGet]
created_at: datetime = Field(alias="createdAt")
pricing_plan_key: str = Field(alias="pricingPlanKey")
pricing_units: list[PricingUnitGetLegacy] = Field(alias="pricingUnits")


assert set(ServicePricingPlanGet.model_fields.keys()) == set(
assert set(ServicePricingPlanGetLegacy.model_fields.keys()) == set(
_ServicePricingPlanGet.model_fields.keys()
)
Loading

0 comments on commit 9f20961

Please sign in to comment.