Skip to content

Commit 63d4a88

Browse files
committed
server/customer: add maximum length to customer name
1 parent 4c10cc4 commit 63d4a88

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

server/polar/checkout/schemas.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
CustomFieldDataOutputMixin,
2020
)
2121
from polar.custom_field.schemas import AttachedCustomField
22+
from polar.customer.schemas.customer import CustomerNameInput
2223
from polar.discount.schemas import (
2324
DiscountFixedBase,
2425
DiscountOnceForeverDurationBase,
@@ -77,10 +78,6 @@
7778
Ge(MINIMUM_PRICE_AMOUNT),
7879
Le(MAXIMUM_PRICE_AMOUNT),
7980
]
80-
CustomerName = Annotated[
81-
str,
82-
Field(description="Name of the customer."),
83-
]
8481
CustomerEmail = Annotated[
8582
EmailStrDNS,
8683
Field(description="Email address of the customer."),
@@ -201,7 +198,7 @@ class CheckoutCreateBase(
201198
description=_external_customer_id_description,
202199
validation_alias=AliasChoices("external_customer_id", "customer_external_id"),
203200
)
204-
customer_name: Annotated[CustomerName | None, EmptyStrToNoneValidator] = None
201+
customer_name: CustomerNameInput | None = None
205202
customer_email: CustomerEmail | None = None
206203
customer_ip_address: CustomerIPAddress | None = None
207204
customer_billing_name: Annotated[str | None, EmptyStrToNoneValidator] = None
@@ -327,7 +324,7 @@ class CheckoutUpdateBase(CustomFieldDataInputMixin, Schema):
327324
description="Number of seats for seat-based pricing.",
328325
)
329326
is_business_customer: bool | None = None
330-
customer_name: Annotated[CustomerName | None, EmptyStrToNoneValidator] = None
327+
customer_name: CustomerNameInput | None = None
331328
customer_email: CustomerEmail | None = None
332329
customer_billing_name: Annotated[str | None, EmptyStrToNoneValidator] = None
333330
customer_billing_address: CustomerBillingAddressInput | None = None

server/polar/customer/schemas/customer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime
33
from typing import Annotated
44

5+
from annotated_types import MaxLen
56
from fastapi import Path
67
from pydantic import UUID4, Field, computed_field
78

@@ -38,6 +39,13 @@
3839
_name_description = "The name of the customer."
3940
_name_example = "John Doe"
4041

42+
CustomerNameInput = Annotated[
43+
str,
44+
MaxLen(256),
45+
Field(description=_name_description, examples=[_name_example]),
46+
EmptyStrToNoneValidator,
47+
]
48+
4149

4250
class CustomerCreate(MetadataInputMixin, Schema):
4351
external_id: Annotated[str | None, EmptyStrToNoneValidator] = Field(
@@ -48,9 +56,7 @@ class CustomerCreate(MetadataInputMixin, Schema):
4856
email: EmailStrDNS = Field(
4957
description=_email_description, examples=[_email_example]
5058
)
51-
name: str | None = Field(
52-
default=None, description=_name_description, examples=[_name_example]
53-
)
59+
name: CustomerNameInput | None = None
5460
billing_address: AddressInput | None = None
5561
tax_id: TaxID | None = None
5662
organization_id: OrganizationID | None = Field(
@@ -66,9 +72,7 @@ class CustomerUpdateBase(MetadataInputMixin, Schema):
6672
email: EmailStrDNS | None = Field(
6773
default=None, description=_email_description, examples=[_email_example]
6874
)
69-
name: str | None = Field(
70-
default=None, description=_name_description, examples=[_name_example]
71-
)
75+
name: CustomerNameInput | None = None
7276
billing_address: AddressInput | None = None
7377
tax_id: TaxID | None = None
7478

0 commit comments

Comments
 (0)