Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Then, run `npm run generate` pointing to the `spec` folder of the cloned
repository, e.g.:

```bash
npm run generate -- ucp/spec
npm install
npm run generate -- ucp/source
```

### Building
Expand Down
27 changes: 15 additions & 12 deletions generate_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ fi

SPEC_DIR="${1%/}"

quicktype \
npx quicktype \
--lang typescript-zod \
--src-lang schema \
--src "$SPEC_DIR"/discovery/*.json \
--src "$SPEC_DIR"/schemas/shopping/*.json \
--src "$SPEC_DIR"/schemas/shopping/types/*.json \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/complete_request_with_ap2" \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/checkout_response_with_ap2" \
--src "$SPEC_DIR/schemas/shopping/buyer_consent.create_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/buyer_consent.update_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/buyer_consent_resp.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/discount.create_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/discount.update_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/discount_resp.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.create_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.update_req.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/fulfillment_resp.json#/\$defs/checkout" \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/ap2_with_checkout_mandate" \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/ap2_with_merchant_authorization" \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/checkout_mandate" \
--src "$SPEC_DIR/schemas/shopping/ap2_mandate.json#/\$defs/merchant_authorization" \
--src "$SPEC_DIR/schemas/shopping/buyer_consent.json#/\$defs/buyer" \
--src "$SPEC_DIR/schemas/shopping/buyer_consent.json#/\$defs/consent" \
--src "$SPEC_DIR/schemas/shopping/discount.json#/\$defs/allocation" \
--src "$SPEC_DIR/schemas/shopping/discount.json#/\$defs/applied_discount" \
--src "$SPEC_DIR/schemas/shopping/discount.json#/\$defs/discounts_object" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.json#/\$defs/fulfillment" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.json#/\$defs/fulfillment_available_method" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.json#/\$defs/fulfillment_group" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.json#/\$defs/fulfillment_method" \
--src "$SPEC_DIR/schemas/shopping/fulfillment.json#/\$defs/fulfillment_option" \
-o src/spec_generated.ts
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 8 additions & 42 deletions src/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { z } from "zod";

import {
CheckoutCreateRequestSchema,
CheckoutResponseSchema,
CheckoutUpdateRequestSchema,
CheckoutWithBuyerConsentCreateRequestSchema,
CheckoutWithBuyerConsentResponseSchema,
CheckoutWithBuyerConsentUpdateRequestSchema,
CheckoutWithDiscountCreateRequestSchema,
CheckoutWithDiscountResponseSchema,
CheckoutWithDiscountUpdateRequestSchema,
CheckoutWithFulfillmentCreateRequestSchema,
CheckoutWithFulfillmentResponseSchema,
CheckoutWithFulfillmentUpdateRequestSchema,
CheckoutSchema,
OrderSchema,
PaymentCredentialSchema,
} from "./spec_generated";
Expand All @@ -29,44 +18,21 @@ export const PlatformConfigSchema = z.object({
});
export type PlatformConfig = z.infer<typeof PlatformConfigSchema>;

export const ExtendedCheckoutResponseSchema = CheckoutResponseSchema.extend(
CheckoutWithFulfillmentResponseSchema.pick({ fulfillment: true }).shape
)
.extend(CheckoutWithDiscountResponseSchema.pick({ discounts: true }).shape)
.extend(CheckoutWithBuyerConsentResponseSchema.pick({ buyer: true }).shape)
.extend({
order_id: z.string().optional(),
order_permalink_url: z.string().optional(),
platform: PlatformConfigSchema.optional(),
});
export const ExtendedCheckoutResponseSchema = CheckoutSchema.extend({
order_id: z.string().optional(),
order_permalink_url: z.string().optional(),
platform: PlatformConfigSchema.optional(),
});
export type ExtendedCheckoutResponse = z.infer<
typeof ExtendedCheckoutResponseSchema
>;

export const ExtendedCheckoutCreateRequestSchema =
CheckoutCreateRequestSchema.extend(
CheckoutWithFulfillmentCreateRequestSchema.pick({ fulfillment: true }).shape
)
.extend(
CheckoutWithDiscountCreateRequestSchema.pick({ discounts: true }).shape
)
.extend(
CheckoutWithBuyerConsentCreateRequestSchema.pick({ buyer: true }).shape
);
export const ExtendedCheckoutCreateRequestSchema = CheckoutSchema;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary to export if it doesn't extend anything anymore?

export type ExtendedCheckoutCreateRequest = z.infer<
typeof ExtendedCheckoutCreateRequestSchema
>;

export const ExtendedCheckoutUpdateRequestSchema =
CheckoutUpdateRequestSchema.extend(
CheckoutWithFulfillmentUpdateRequestSchema.pick({ fulfillment: true }).shape
)
.extend(
CheckoutWithDiscountUpdateRequestSchema.pick({ discounts: true }).shape
)
.extend(
CheckoutWithBuyerConsentUpdateRequestSchema.pick({ buyer: true }).shape
);
export const ExtendedCheckoutUpdateRequestSchema = CheckoutSchema;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

export type ExtendedCheckoutUpdateRequest = z.infer<
typeof ExtendedCheckoutUpdateRequestSchema
>;
Expand Down
Loading
Loading