11from datetime import datetime
22from typing import Annotated , Any , TypeAlias
33
4+ from common_library .basic_types import DEFAULT_FACTORY
45from pydantic import (
56 ConfigDict ,
67 Field ,
1011 PlainSerializer ,
1112 PositiveInt ,
1213)
14+ from pydantic .config import JsonDict
1315
1416from ..basic_types import IDStr , NonNegativeDecimal
1517from ..emails import LowerCaseEmailStr
@@ -27,32 +29,40 @@ class GetCreditPrice(OutputSchema):
2729 description = "Price of a credit in USD. "
2830 "If None, then this product's price is UNDEFINED" ,
2931 )
30- min_payment_amount_usd : NonNegativeInt | None = Field (
31- ...,
32- description = "Minimum amount (included) in USD that can be paid for this product"
33- "Can be None if this product's price is UNDEFINED" ,
34- )
32+ min_payment_amount_usd : Annotated [
33+ NonNegativeInt | None ,
34+ Field (
35+ description = "Minimum amount (included) in USD that can be paid for this product"
36+ "Can be None if this product's price is UNDEFINED" ,
37+ ),
38+ ]
39+
40+ @staticmethod
41+ def _update_json_schema_extra (schema : JsonDict ) -> None :
42+ schema .update (
43+ {
44+ "examples" : [
45+ {
46+ "productName" : "osparc" ,
47+ "usdPerCredit" : None ,
48+ "minPaymentAmountUsd" : None ,
49+ },
50+ {
51+ "productName" : "osparc" ,
52+ "usdPerCredit" : "10" ,
53+ "minPaymentAmountUsd" : "10" ,
54+ },
55+ ]
56+ }
57+ )
3558
3659 model_config = ConfigDict (
37- json_schema_extra = {
38- "examples" : [
39- {
40- "productName" : "osparc" ,
41- "usdPerCredit" : None ,
42- "minPaymentAmountUsd" : None ,
43- },
44- {
45- "productName" : "osparc" ,
46- "usdPerCredit" : "10" ,
47- "minPaymentAmountUsd" : "10" ,
48- },
49- ]
50- }
60+ json_schema_extra = _update_json_schema_extra ,
5161 )
5262
5363
5464class GetProductTemplate (OutputSchema ):
55- id_ : IDStr = Field (..., alias = "id" )
65+ id_ : Annotated [ IDStr , Field (alias = "id" )]
5666 content : str
5767
5868
@@ -87,13 +97,14 @@ class ProductGet(OutputSchema):
8797 description = "List of templates available to this product for communications (e.g. emails, sms, etc)" ,
8898 default_factory = list ,
8999 ),
90- ]
100+ ] = DEFAULT_FACTORY
91101
92102
93103class ProductUIGet (OutputSchema ):
94104 product_name : ProductName
95105 ui : Annotated [
96- dict [str , Any ], Field (description = "Front-end owned ui product configuration" )
106+ dict [str , Any ],
107+ Field (description = "Front-end owned ui product configuration" ),
97108 ]
98109
99110
@@ -115,26 +126,32 @@ class InvitationGenerated(OutputSchema):
115126 created : datetime
116127 invitation_link : HttpUrl
117128
129+ @staticmethod
130+ def _update_json_schema_extra (schema : JsonDict ) -> None :
131+ schema .update (
132+ {
133+ "examples" : [
134+ {
135+ "productName" : "osparc" ,
136+ "issuer" : "john.doe" ,
137+ 138+ "trialAccountDays" : 7 ,
139+ "extraCreditsInUsd" : 30 ,
140+ "created" : "2023-09-27T15:30:00" ,
141+ "invitationLink" : "https://example.com/invitation#1234" ,
142+ },
143+ # w/o optional
144+ {
145+ "productName" : "osparc" ,
146+ 147+ 148+ "created" : "2023-09-27T15:30:00" ,
149+ "invitationLink" : "https://example.com/invitation#1234" ,
150+ },
151+ ]
152+ }
153+ )
154+
118155 model_config = ConfigDict (
119- json_schema_extra = {
120- "examples" : [
121- {
122- "productName" : "osparc" ,
123- "issuer" : "john.doe" ,
124- 125- "trialAccountDays" : 7 ,
126- "extraCreditsInUsd" : 30 ,
127- "created" : "2023-09-27T15:30:00" ,
128- "invitationLink" : "https://example.com/invitation#1234" ,
129- },
130- # w/o optional
131- {
132- "productName" : "osparc" ,
133- 134- 135- "created" : "2023-09-27T15:30:00" ,
136- "invitationLink" : "https://example.com/invitation#1234" ,
137- },
138- ]
139- }
156+ json_schema_extra = _update_json_schema_extra ,
140157 )
0 commit comments