Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
@@ -1,10 +1,11 @@
from datetime import datetime
from typing import Any, NamedTuple, Self, cast
from datetime import date, datetime
from typing import Literal, NamedTuple, NotRequired, Self, cast

from models_library.basic_types import IDStr
from models_library.resource_tracker import PricingPlanId
from pydantic import BaseModel, ConfigDict, HttpUrl, PositiveInt
from pydantic.config import JsonDict
from typing_extensions import TypedDict

from ..licenses import (
VIP_DETAILS_EXAMPLE,
Expand All @@ -20,13 +21,38 @@
# RPC


class LicensedResourceFeaturesDict(TypedDict):
age: NotRequired[str]
date: date
ethnicity: NotRequired[str]
functionality: NotRequired[str]
height: NotRequired[str]
name: NotRequired[str]
sex: NotRequired[str]
species: NotRequired[str]
version: NotRequired[str]
weight: NotRequired[str]


class LicensedResource(BaseModel):
id: int
description: str
thumbnail: str
features: LicensedResourceFeaturesDict
doi: str | None
license_key: str
license_version: str
protection: Literal["Code", "PayPal"]
available_from_url: HttpUrl | None


class LicensedItemRpcGet(BaseModel):
licensed_item_id: LicensedItemID
key: LicensedItemKey
version: LicensedItemVersion
display_name: str
licensed_resource_type: LicensedResourceType
licensed_resources: list[dict[str, Any]]
licensed_resources: list[LicensedResource]
pricing_plan_id: PricingPlanId
is_hidden_on_market: bool
created_at: datetime
Expand Down
125 changes: 124 additions & 1 deletion services/api-server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6705,7 +6705,7 @@
},
"licensed_resources": {
"items": {
"type": "object"
"$ref": "#/components/schemas/LicensedResource"
},
"type": "array",
"title": "Licensed Resources"
Expand Down Expand Up @@ -6746,6 +6746,129 @@
],
"title": "LicensedItemGet"
},
"LicensedResource": {
"properties": {
"id": {
"type": "integer",
"title": "Id"
},
"description": {
"type": "string",
"title": "Description"
},
"thumbnail": {
"type": "string",
"title": "Thumbnail"
},
"features": {
"$ref": "#/components/schemas/LicensedResourceFeaturesDict"
},
"doi": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Doi"
},
"license_key": {
"type": "string",
"title": "License Key"
},
"license_version": {
"type": "string",
"title": "License Version"
},
"protection": {
"type": "string",
"enum": [
"Code",
"PayPal"
],
"title": "Protection"
},
"available_from_url": {
"anyOf": [
{
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
}
],
"title": "Available From Url"
}
},
"type": "object",
"required": [
"id",
"description",
"thumbnail",
"features",
"doi",
"license_key",
"license_version",
"protection",
"available_from_url"
],
"title": "LicensedResource"
},
"LicensedResourceFeaturesDict": {
"properties": {
"age": {
"type": "string",
"title": "Age"
},
"date": {
"type": "string",
"format": "date",
"title": "Date"
},
"ethnicity": {
"type": "string",
"title": "Ethnicity"
},
"functionality": {
"type": "string",
"title": "Functionality"
},
"height": {
"type": "string",
"title": "Height"
},
"name": {
"type": "string",
"title": "Name"
},
"sex": {
"type": "string",
"title": "Sex"
},
"species": {
"type": "string",
"title": "Species"
},
"version": {
"type": "string",
"title": "Version"
},
"weight": {
"type": "string",
"title": "Weight"
}
},
"type": "object",
"required": [
"date"
],
"title": "LicensedResourceFeaturesDict"
},
"LicensedResourceType": {
"type": "string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Models added here "cover" models from within the deployment in order to restore backwards compatibility

from datetime import datetime
from datetime import date, datetime
from decimal import Decimal
from typing import Annotated, Any
from typing import Annotated, Literal, NotRequired

from models_library.api_schemas_api_server.pricing_plans import (
ServicePricingPlanGet as _ServicePricingPlanGet,
)
from models_library.api_schemas_webserver.licensed_items import (
LicensedItemRpcGet as _LicensedItemGet,
)
from models_library.api_schemas_webserver.licensed_items import (
LicensedResource as _LicensedResource,
)
from models_library.api_schemas_webserver.licensed_items import (
LicensedResourceFeaturesDict as _LicensedResourceFeaturesDict,
)
from models_library.api_schemas_webserver.licensed_items_checkouts import (
LicensedItemCheckoutRpcGet as _LicensedItemCheckoutRpcGet,
)
Expand Down Expand Up @@ -46,10 +52,12 @@
BaseModel,
ConfigDict,
Field,
HttpUrl,
NonNegativeFloat,
NonNegativeInt,
PlainSerializer,
)
from typing_extensions import TypedDict


class GetCreditPriceLegacy(BaseModel):
Expand Down Expand Up @@ -140,13 +148,61 @@ class ServicePricingPlanGetLegacy(BaseModel):
)


class LicensedResourceFeaturesDict(TypedDict):
age: NotRequired[str]
date: date
ethnicity: NotRequired[str]
functionality: NotRequired[str]
height: NotRequired[str]
name: NotRequired[str]
sex: NotRequired[str]
species: NotRequired[str]
version: NotRequired[str]
weight: NotRequired[str]


assert set(LicensedResourceFeaturesDict.__annotations__.keys()) == set(
_LicensedResourceFeaturesDict.__annotations__.keys()
), "LicensedResourceFeaturesDict keys do not match"

for key in LicensedResourceFeaturesDict.__annotations__:
assert (
LicensedResourceFeaturesDict.__annotations__[key]
== _LicensedResourceFeaturesDict.__annotations__[key]
), f"Type of {key} in LicensedResourceFeaturesDict does not match"


class LicensedResource(BaseModel):
id: int
description: str
thumbnail: str
features: LicensedResourceFeaturesDict
doi: str | None
license_key: str
license_version: str
protection: Literal["Code", "PayPal"]
available_from_url: HttpUrl | None


assert set(LicensedResource.model_fields.keys()) == set(
_LicensedResource.model_fields.keys()
), "LicensedResource keys do not match"

for key in LicensedResource.model_fields.keys():
if key == "features":
continue
assert (
LicensedResource.__annotations__[key] == _LicensedResource.__annotations__[key]
), f"Type of {key} in LicensedResource does not match"


class LicensedItemGet(BaseModel):
licensed_item_id: LicensedItemID
key: LicensedItemKey
version: LicensedItemVersion
display_name: str
licensed_resource_type: LicensedResourceType
licensed_resources: list[dict[str, Any]]
licensed_resources: list[LicensedResource]
pricing_plan_id: PricingPlanId
is_hidden_on_market: bool
created_at: datetime
Expand Down
Loading