|
1 | 1 | import re |
2 | | -from typing import Annotated, Any, Literal, NamedTuple, TypeAlias |
| 2 | +from typing import Annotated, Any, Literal, NamedTuple, TypeAlias, cast |
3 | 3 |
|
4 | 4 | from models_library.basic_types import IDStr |
5 | | -from models_library.licenses import FeaturesDict |
| 5 | +from models_library.licenses import VIP_DETAILS_EXAMPLE, FeaturesDict |
6 | 6 | from pydantic import ( |
7 | 7 | BaseModel, |
8 | 8 | BeforeValidator, |
| 9 | + ConfigDict, |
9 | 10 | Field, |
10 | 11 | HttpUrl, |
11 | 12 | StringConstraints, |
12 | 13 | TypeAdapter, |
13 | 14 | ) |
| 15 | +from pydantic.config import JsonDict |
14 | 16 |
|
15 | 17 | _max_str_adapter: TypeAdapter[str] = TypeAdapter( |
16 | 18 | Annotated[str, StringConstraints(strip_whitespace=True, max_length=1_000)] |
@@ -53,6 +55,31 @@ class ItisVipData(BaseModel): |
53 | 55 | protection: Annotated[Literal["Code", "PayPal"], Field(alias="Protection")] |
54 | 56 | available_from_url: Annotated[HttpUrl | None, Field(alias="AvailableFromURL")] |
55 | 57 |
|
| 58 | + @staticmethod |
| 59 | + def _update_json_schema_extra(schema: JsonDict) -> None: |
| 60 | + schema.update( |
| 61 | + { |
| 62 | + "examples": [ |
| 63 | + # complete |
| 64 | + cast(JsonDict, VIP_DETAILS_EXAMPLE), |
| 65 | + # minimal |
| 66 | + { |
| 67 | + "id": 1, |
| 68 | + "description": "A detailed description of the VIP model", |
| 69 | + "thumbnail": "https://example.com/thumbnail.jpg", |
| 70 | + "features": {"date": "2013-02-01"}, |
| 71 | + "doi": "null", |
| 72 | + "license_key": "ABC123XYZ", |
| 73 | + "license_version": "1.0", |
| 74 | + "protection": "Code", |
| 75 | + "available_from_url": "null", |
| 76 | + }, |
| 77 | + ] |
| 78 | + } |
| 79 | + ) |
| 80 | + |
| 81 | + model_config = ConfigDict(json_schema_extra=_update_json_schema_extra) |
| 82 | + |
56 | 83 |
|
57 | 84 | class ItisVipResourceData(BaseModel): |
58 | 85 | category_id: IDStr |
|
0 commit comments