Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 18 additions & 12 deletions preprocess_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,21 @@ def rewrite_refs_to_variants(root, op, file_path, variant_needs):
for node in iter_nodes(root):
if isinstance(node, dict) and "$ref" in node:
ref = node["$ref"]
if "#" not in ref: # External file reference
abs_target = (file_path.parent / ref).resolve()
if (
str(abs_target) in variant_needs
and op in variant_needs[str(abs_target)]
):
ref_path = Path(ref)
node["$ref"] = str(
ref_path.parent / f"{ref_path.stem}_{op}_request.json"
)
ref_file, separator, fragment = ref.partition("#")
if not ref_file:
continue
abs_target = (file_path.parent / ref_file).resolve()
if (
str(abs_target) in variant_needs
and op in variant_needs[str(abs_target)]
):
ref_path = Path(ref_file)
variant_ref = str(
ref_path.parent / f"{ref_path.stem}_{op}_request.json"
)
node["$ref"] = variant_ref + (
separator + fragment if separator else ""
)


def _apply_request_rules_to_object(
Expand Down Expand Up @@ -592,8 +597,9 @@ def extract_external_refs(schema, path):
for node in iter_nodes(data):
if isinstance(node, dict) and "$ref" in node:
ref = node["$ref"]
if "#" not in ref:
abs_path = str((path.parent / ref).resolve())
ref_file, _, _ = ref.partition("#")
if ref_file:
abs_path = str((path.parent / ref_file).resolve())
refs.append((name, abs_path))
return refs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pydantic import BaseModel, ConfigDict

from .types import payment_instrument
from .types import payment_instrument_complete_request


class PaymentCompleteRequest(BaseModel):
Expand All @@ -31,9 +31,10 @@ class PaymentCompleteRequest(BaseModel):
model_config = ConfigDict(
extra="allow",
)
instruments: list[payment_instrument.SelectedPaymentInstrument] | None = (
None
)
instruments: (
list[payment_instrument_complete_request.SelectedPaymentInstrument]
| None
) = None
"""
The payment instruments available for this payment. Each instrument is associated with a specific handler via the handler_id field. Handlers can extend the base payment_instrument schema to add handler-specific fields.
"""
8 changes: 4 additions & 4 deletions src/ucp_sdk/models/schemas/shopping/payment_create_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pydantic import BaseModel, ConfigDict

from .types import payment_instrument
from .types import payment_instrument_create_request


class PaymentCreateRequest(BaseModel):
Expand All @@ -31,9 +31,9 @@ class PaymentCreateRequest(BaseModel):
model_config = ConfigDict(
extra="allow",
)
instruments: list[payment_instrument.SelectedPaymentInstrument] | None = (
None
)
instruments: (
list[payment_instrument_create_request.SelectedPaymentInstrument] | None
) = None
"""
The payment instruments available for this payment. Each instrument is associated with a specific handler via the handler_id field. Handlers can extend the base payment_instrument schema to add handler-specific fields.
"""
8 changes: 4 additions & 4 deletions src/ucp_sdk/models/schemas/shopping/payment_update_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pydantic import BaseModel, ConfigDict

from .types import payment_instrument
from .types import payment_instrument_update_request


class PaymentUpdateRequest(BaseModel):
Expand All @@ -31,9 +31,9 @@ class PaymentUpdateRequest(BaseModel):
model_config = ConfigDict(
extra="allow",
)
instruments: list[payment_instrument.SelectedPaymentInstrument] | None = (
None
)
instruments: (
list[payment_instrument_update_request.SelectedPaymentInstrument] | None
) = None
"""
The payment instruments available for this payment. Each instrument is associated with a specific handler via the handler_id field. Handlers can extend the base payment_instrument schema to add handler-specific fields.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from pydantic import BaseModel, ConfigDict


class PaymentCredentialCompleteRequest(BaseModel):
"""
The base definition for any payment credential. Handlers define specific credential types.
"""

model_config = ConfigDict(
extra="allow",
)
type: str
"""
The credential type discriminator. Specific schemas will constrain this to a constant value.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from pydantic import BaseModel, ConfigDict


class PaymentCredentialCreateRequest(BaseModel):
"""
The base definition for any payment credential. Handlers define specific credential types.
"""

model_config = ConfigDict(
extra="allow",
)
type: str
"""
The credential type discriminator. Specific schemas will constrain this to a constant value.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from pydantic import BaseModel, ConfigDict


class PaymentCredentialUpdateRequest(BaseModel):
"""
The base definition for any payment credential. Handlers define specific credential types.
"""

model_config = ConfigDict(
extra="allow",
)
type: str
"""
The credential type discriminator. Specific schemas will constrain this to a constant value.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict

from . import (
payment_credential_complete_request,
postal_address_complete_request,
)


class PaymentInstrumentCompleteRequest(BaseModel):
"""
The base definition for any payment instrument. It links the instrument to a specific payment handler.
"""

model_config = ConfigDict(
extra="allow",
)
id: str
"""
A unique identifier for this instrument instance, assigned by the platform.
"""
handler_id: str
"""
The unique identifier for the handler instance that produced this instrument. This corresponds to the 'id' field in the Payment Handler definition.
"""
type: str
"""
The broad category of the instrument (e.g., 'card', 'tokenized_card'). Specific schemas will constrain this to a constant value.
"""
billing_address: (
postal_address_complete_request.PostalAddressCompleteRequest | None
) = None
"""
The billing address associated with this payment method.
"""
credential: (
payment_credential_complete_request.PaymentCredentialCompleteRequest
| None
) = None
display: dict[str, Any] | None = None
"""
Display information for this payment instrument. Each payment instrument schema defines its specific display properties, as outlined by the payment handler.
"""


class SelectedPaymentInstrument(PaymentInstrumentCompleteRequest):
"""
A payment instrument with selection state.
"""

model_config = ConfigDict(
extra="allow",
)
selected: bool | None = None
"""
Whether this instrument is selected by the user.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict

from . import payment_credential_create_request, postal_address_create_request


class PaymentInstrumentCreateRequest(BaseModel):
"""
The base definition for any payment instrument. It links the instrument to a specific payment handler.
"""

model_config = ConfigDict(
extra="allow",
)
id: str
"""
A unique identifier for this instrument instance, assigned by the platform.
"""
handler_id: str
"""
The unique identifier for the handler instance that produced this instrument. This corresponds to the 'id' field in the Payment Handler definition.
"""
type: str
"""
The broad category of the instrument (e.g., 'card', 'tokenized_card'). Specific schemas will constrain this to a constant value.
"""
billing_address: (
postal_address_create_request.PostalAddressCreateRequest | None
) = None
"""
The billing address associated with this payment method.
"""
credential: (
payment_credential_create_request.PaymentCredentialCreateRequest | None
) = None
display: dict[str, Any] | None = None
"""
Display information for this payment instrument. Each payment instrument schema defines its specific display properties, as outlined by the payment handler.
"""


class SelectedPaymentInstrument(PaymentInstrumentCreateRequest):
"""
A payment instrument with selection state.
"""

model_config = ConfigDict(
extra="allow",
)
selected: bool | None = None
"""
Whether this instrument is selected by the user.
"""
Loading
Loading