From f5dced6ad98894fe12698d7883b8c9f6bc1af0af Mon Sep 17 00:00:00 2001 From: Andrew Sprouse Date: Wed, 8 Feb 2023 11:31:39 -0500 Subject: [PATCH] feat(oas): Improve OAS by adding missing type object to schemas (#3177) This PR improves the OAS by adding `type: object` to schemas that have `properties` and no `type`. While this attribute is not required for a valid spec, omitting it opens the possibilities of non-object input. See https://stackoverflow.com/a/47390723 for a detailed description of this behavior. When generating code or schemas from an OAS with tools like takeshape.io having `type` attributes is important to get the correct behavior. --- .../api/routes/admin/customer-groups/add-customers-batch.ts | 1 + .../routes/admin/customer-groups/delete-customers-batch.ts | 1 + .../src/api/routes/admin/customers/update-customer.ts | 1 + .../admin/discounts/add-resources-to-condition-batch.ts | 1 + .../discounts/delete-resources-from-condition-batch.ts | 1 + packages/medusa/src/api/routes/admin/orders/create-claim.ts | 3 +++ .../src/api/routes/admin/orders/create-fulfillment.ts | 1 + packages/medusa/src/api/routes/admin/orders/create-swap.ts | 3 +++ .../medusa/src/api/routes/admin/orders/request-return.ts | 1 + packages/medusa/src/api/routes/admin/orders/update-claim.ts | 2 ++ .../src/api/routes/admin/price-lists/add-prices-batch.ts | 1 + .../src/api/routes/admin/price-lists/create-price-list.ts | 2 ++ .../src/api/routes/admin/price-lists/update-price-list.ts | 2 ++ .../medusa/src/api/routes/admin/products/create-product.ts | 6 ++++++ .../medusa/src/api/routes/admin/products/create-variant.ts | 2 ++ packages/medusa/src/api/routes/admin/products/index.ts | 1 + .../medusa/src/api/routes/admin/products/update-product.ts | 5 +++++ .../medusa/src/api/routes/admin/products/update-variant.ts | 2 ++ .../medusa/src/api/routes/admin/returns/receive-return.ts | 1 + .../routes/admin/shipping-options/create-shipping-option.ts | 1 + .../routes/admin/shipping-options/update-shipping-option.ts | 1 + packages/medusa/src/api/routes/store/carts/create-cart.ts | 1 + packages/medusa/src/api/routes/store/carts/update-cart.ts | 2 ++ .../payment-collections/manage-batch-payment-sessions.ts | 1 + .../medusa/src/api/routes/store/returns/create-return.ts | 1 + packages/medusa/src/api/routes/store/swaps/create-swap.ts | 2 ++ 26 files changed, 46 insertions(+) diff --git a/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts b/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts index 6dd9ba0ec7..f157e4d6e2 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts @@ -114,6 +114,7 @@ export default async (req: Request, res: Response) => { * description: "The ids of the customers to add" * type: array * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts b/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts index da89bc6a58..ab9ad598ea 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts @@ -114,6 +114,7 @@ export default async (req: Request, res: Response) => { * description: "The ids of the customers to remove" * type: array * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/customers/update-customer.ts b/packages/medusa/src/api/routes/admin/customers/update-customer.ts index e66e1b340e..f3217ee648 100644 --- a/packages/medusa/src/api/routes/admin/customers/update-customer.ts +++ b/packages/medusa/src/api/routes/admin/customers/update-customer.ts @@ -148,6 +148,7 @@ class Group { * groups: * type: array * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/discounts/add-resources-to-condition-batch.ts b/packages/medusa/src/api/routes/admin/discounts/add-resources-to-condition-batch.ts index 768e4f3959..a92f63e4d1 100644 --- a/packages/medusa/src/api/routes/admin/discounts/add-resources-to-condition-batch.ts +++ b/packages/medusa/src/api/routes/admin/discounts/add-resources-to-condition-batch.ts @@ -121,6 +121,7 @@ export default async (req: Request, res: Response) => { * description: The resources to be added to the discount condition * type: array * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/discounts/delete-resources-from-condition-batch.ts b/packages/medusa/src/api/routes/admin/discounts/delete-resources-from-condition-batch.ts index df6192ad31..5c3b799926 100644 --- a/packages/medusa/src/api/routes/admin/discounts/delete-resources-from-condition-batch.ts +++ b/packages/medusa/src/api/routes/admin/discounts/delete-resources-from-condition-batch.ts @@ -122,6 +122,7 @@ export class AdminDeleteDiscountsDiscountConditionsConditionBatchParams extends * description: The resources to be deleted from the discount condition * type: array * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/orders/create-claim.ts b/packages/medusa/src/api/routes/admin/orders/create-claim.ts index 4644280ac3..527d66afe4 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-claim.ts @@ -315,6 +315,7 @@ export default async (req, res) => { * description: The Claim Items that the Claim will consist of. * type: array * items: + * type: object * required: * - item_id * - quantity @@ -359,6 +360,7 @@ export default async (req, res) => { * description: The new items to send to the Customer when the Claim type is Replace. * type: array * items: + * type: object * required: * - variant_id * - quantity @@ -373,6 +375,7 @@ export default async (req, res) => { * description: The Shipping Methods to send the additional Line Items with. * type: array * items: + * type: object * properties: * id: * description: The ID of an existing Shipping Method diff --git a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts index 5339a68cd0..61434c7791 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts @@ -192,6 +192,7 @@ const updateInventoryAndReservations = async ( * description: The Line Items to include in the Fulfillment. * type: array * items: + * type: object * required: * - item_id * - quantity diff --git a/packages/medusa/src/api/routes/admin/orders/create-swap.ts b/packages/medusa/src/api/routes/admin/orders/create-swap.ts index 57be9cdeca..29a231f7c1 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-swap.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-swap.ts @@ -262,6 +262,7 @@ export default async (req, res) => { * description: The Line Items to return as part of the Swap. * type: array * items: + * type: object * required: * - item_id * - quantity @@ -294,6 +295,7 @@ export default async (req, res) => { * description: The new items to send to the Customer. * type: array * items: + * type: object * required: * - variant_id * - quantity @@ -308,6 +310,7 @@ export default async (req, res) => { * description: The custom shipping options to potentially create a Shipping Method from. * type: array * items: + * type: object * required: * - option_id * - price diff --git a/packages/medusa/src/api/routes/admin/orders/request-return.ts b/packages/medusa/src/api/routes/admin/orders/request-return.ts index e2b6abdb15..eff4cac4d8 100644 --- a/packages/medusa/src/api/routes/admin/orders/request-return.ts +++ b/packages/medusa/src/api/routes/admin/orders/request-return.ts @@ -296,6 +296,7 @@ type ReturnObj = { * description: The Line Items that will be returned. * type: array * items: + * type: object * required: * - item_id * - quantity diff --git a/packages/medusa/src/api/routes/admin/orders/update-claim.ts b/packages/medusa/src/api/routes/admin/orders/update-claim.ts index 95528245aa..41787f69d1 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/update-claim.ts @@ -112,6 +112,7 @@ export default async (req, res) => { * description: The Claim Items that the Claim will consist of. * type: array * items: + * type: object * required: * - id * - images @@ -168,6 +169,7 @@ export default async (req, res) => { * description: The Shipping Methods to send the additional Line Items with. * type: array * items: + * type: object * properties: * id: * description: The ID of an existing Shipping Method diff --git a/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts b/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts index ea2c4b49e9..c3f7751915 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts @@ -113,6 +113,7 @@ export default async (req, res) => { * description: The prices to update or add. * type: array * items: + * type: object * required: * - amount * - variant_id diff --git a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts index 18395b1d61..9d9923fe79 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts @@ -157,6 +157,7 @@ class CustomerGroup { * description: The prices of the Price List. * type: array * items: + * type: object * required: * - amount * - variant_id @@ -186,6 +187,7 @@ class CustomerGroup { * type: array * description: A list of customer groups that the Price List applies to. * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts index 316940192f..ca76aa4c64 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts @@ -148,6 +148,7 @@ class CustomerGroup { * description: The prices of the Price List. * type: array * items: + * type: object * required: * - amount * - variant_id @@ -180,6 +181,7 @@ class CustomerGroup { * type: array * description: A list of customer groups that the Price List applies to. * items: + * type: object * required: * - id * properties: diff --git a/packages/medusa/src/api/routes/admin/products/create-product.ts b/packages/medusa/src/api/routes/admin/products/create-product.ts index 0a84603f98..9868f37fac 100644 --- a/packages/medusa/src/api/routes/admin/products/create-product.ts +++ b/packages/medusa/src/api/routes/admin/products/create-product.ts @@ -362,6 +362,7 @@ class ProductVariantReq { * description: Tags to associate the Product with. * type: array * items: + * type: object * required: * - value * properties: @@ -375,6 +376,7 @@ class ProductVariantReq { * description: "[EXPERIMENTAL] Sales channels to associate the Product with." * type: array * items: + * type: object * required: * - id * properties: @@ -395,6 +397,7 @@ class ProductVariantReq { * description: The Options that the Product should have. These define on which properties the Product's Product Variants will differ. * type: array * items: + * type: object * required: * - title * properties: @@ -405,6 +408,7 @@ class ProductVariantReq { * description: A list of Product Variants to create with the Product. * type: array * items: + * type: object * required: * - title * properties: @@ -463,6 +467,7 @@ class ProductVariantReq { * prices: * type: array * items: + * type: object * required: * - amount * properties: @@ -487,6 +492,7 @@ class ProductVariantReq { * options: * type: array * items: + * type: object * required: * - value * properties: diff --git a/packages/medusa/src/api/routes/admin/products/create-variant.ts b/packages/medusa/src/api/routes/admin/products/create-variant.ts index 553e8271bd..c48f7b5f95 100644 --- a/packages/medusa/src/api/routes/admin/products/create-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/create-variant.ts @@ -226,6 +226,7 @@ class ProductVariantOptionReq { * prices: * type: array * items: + * type: object * required: * - amount * properties: @@ -253,6 +254,7 @@ class ProductVariantOptionReq { * options: * type: array * items: + * type: object * required: * - option_id * - value diff --git a/packages/medusa/src/api/routes/admin/products/index.ts b/packages/medusa/src/api/routes/admin/products/index.ts index 22e2184f1a..e1fce0db36 100644 --- a/packages/medusa/src/api/routes/admin/products/index.ts +++ b/packages/medusa/src/api/routes/admin/products/index.ts @@ -271,6 +271,7 @@ export type AdminProductsListTypesRes = { * tags: * type: array * items: + * type: object * properties: * id: * description: The ID of the tag. diff --git a/packages/medusa/src/api/routes/admin/products/update-product.ts b/packages/medusa/src/api/routes/admin/products/update-product.ts index b685171b1e..25a0feda20 100644 --- a/packages/medusa/src/api/routes/admin/products/update-product.ts +++ b/packages/medusa/src/api/routes/admin/products/update-product.ts @@ -368,6 +368,7 @@ class ProductVariantReq { * description: Tags to associate the Product with. * type: array * items: + * type: object * required: * - value * properties: @@ -381,6 +382,7 @@ class ProductVariantReq { * description: "[EXPERIMENTAL] Sales channels to associate the Product with." * type: array * items: + * type: object * required: * - id * properties: @@ -401,6 +403,7 @@ class ProductVariantReq { * description: A list of Product Variants to create with the Product. * type: array * items: + * type: object * properties: * id: * description: The ID of the Product Variant. @@ -459,6 +462,7 @@ class ProductVariantReq { * prices: * type: array * items: + * type: object * required: * - amount * properties: @@ -486,6 +490,7 @@ class ProductVariantReq { * options: * type: array * items: + * type: object * required: * - option_id * - value diff --git a/packages/medusa/src/api/routes/admin/products/update-variant.ts b/packages/medusa/src/api/routes/admin/products/update-variant.ts index ee2234f1d5..28ef0767f2 100644 --- a/packages/medusa/src/api/routes/admin/products/update-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/update-variant.ts @@ -207,6 +207,7 @@ class ProductVariantOptionReq { * prices: * type: array * items: + * type: object * required: * - amount * properties: @@ -234,6 +235,7 @@ class ProductVariantOptionReq { * options: * type: array * items: + * type: object * required: * - option_id * - value diff --git a/packages/medusa/src/api/routes/admin/returns/receive-return.ts b/packages/medusa/src/api/routes/admin/returns/receive-return.ts index 9948750c04..c5d5a02871 100644 --- a/packages/medusa/src/api/routes/admin/returns/receive-return.ts +++ b/packages/medusa/src/api/routes/admin/returns/receive-return.ts @@ -147,6 +147,7 @@ class Item { * description: The Line Items that have been received. * type: array * items: + * type: object * required: * - item_id * - quantity diff --git a/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts index 322e82235c..6b510b02af 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts @@ -156,6 +156,7 @@ class OptionRequirement { * description: "The requirements that must be satisfied for the Shipping Option to be available." * type: array * items: + * type: object * required: * - type * - amount diff --git a/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts index 094b7c6355..89d30d7ae1 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts @@ -143,6 +143,7 @@ class OptionRequirement { * description: "The requirements that must be satisfied for the Shipping Option to be available." * type: array * items: + * type: object * required: * - type * - amount diff --git a/packages/medusa/src/api/routes/store/carts/create-cart.ts b/packages/medusa/src/api/routes/store/carts/create-cart.ts index fb46d93646..6f98220412 100644 --- a/packages/medusa/src/api/routes/store/carts/create-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/create-cart.ts @@ -209,6 +209,7 @@ export class Item { * description: "An optional array of `variant_id`, `quantity` pairs to generate Line Items from." * type: array * items: + * type: object * required: * - variant_id * - quantity diff --git a/packages/medusa/src/api/routes/store/carts/update-cart.ts b/packages/medusa/src/api/routes/store/carts/update-cart.ts index a27a874000..011e9c8c44 100644 --- a/packages/medusa/src/api/routes/store/carts/update-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/update-cart.ts @@ -151,6 +151,7 @@ class Discount { * description: "An array of Gift Card codes to add to the Cart." * type: array * items: + * type: object * required: * - code * properties: @@ -161,6 +162,7 @@ class Discount { * description: "An array of Discount codes to add to the Cart." * type: array * items: + * type: object * required: * - code * properties: diff --git a/packages/medusa/src/api/routes/store/payment-collections/manage-batch-payment-sessions.ts b/packages/medusa/src/api/routes/store/payment-collections/manage-batch-payment-sessions.ts index 0563f94fa1..70070ff81e 100644 --- a/packages/medusa/src/api/routes/store/payment-collections/manage-batch-payment-sessions.ts +++ b/packages/medusa/src/api/routes/store/payment-collections/manage-batch-payment-sessions.ts @@ -129,6 +129,7 @@ export class StorePostPaymentCollectionsSessionsReq { * description: "An array of payment sessions related to the Payment Collection. If the session_id is not provided, existing sessions not present will be deleted and the provided ones will be created." * type: array * items: + * type: object * required: * - provider_id * - amount diff --git a/packages/medusa/src/api/routes/store/returns/create-return.ts b/packages/medusa/src/api/routes/store/returns/create-return.ts index a35bc39e63..aefad109d9 100644 --- a/packages/medusa/src/api/routes/store/returns/create-return.ts +++ b/packages/medusa/src/api/routes/store/returns/create-return.ts @@ -264,6 +264,7 @@ class Item { * description: "The items to include in the Return." * type: array * items: + * type: object * required: * - item_id * - quantity diff --git a/packages/medusa/src/api/routes/store/swaps/create-swap.ts b/packages/medusa/src/api/routes/store/swaps/create-swap.ts index f0197183ff..0dd9438921 100644 --- a/packages/medusa/src/api/routes/store/swaps/create-swap.ts +++ b/packages/medusa/src/api/routes/store/swaps/create-swap.ts @@ -296,6 +296,7 @@ class AdditionalItem { * description: "The items to include in the Return." * type: array * items: + * type: object * required: * - item_id * - quantity @@ -319,6 +320,7 @@ class AdditionalItem { * description: "The items to exchange the returned items to." * type: array * items: + * type: object * required: * - variant_id * - quantity