oas: [2/2] improve store OAS (#9035)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-09-06 18:52:38 +03:00
1 parent b5dbf572e3
commit cd909f9db3
17 files changed
+178 -110

No files matched your search

@@ -28,14 +28,14 @@
* application/json: * application/json:
* schema: * schema:
* allOf: * allOf:
* - $ref: "#/components/schemas/CreateCartWorkflowInput" * - $ref: "#/components/schemas/StoreCreateCart"
* - type: object * - type: object
* description: SUMMARY * description: The cart's details.
* properties: * properties:
* additional_data: * additional_data:
* type: object * type: object
* description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter. * description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
* description: SUMMARY * description: The cart's details.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -2,7 +2,7 @@
* @oas [post] /store/carts/{id} * @oas [post] /store/carts/{id}
* operationId: PostCartsId * operationId: PostCartsId
* summary: Update a Cart * summary: Update a Cart
* description: Update a cart's details. * description: Update a cart's details. This unsets the shipping an payment methods chosen before, and the customer would have to choose them again.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -36,12 +36,12 @@
* allOf: * allOf:
* - $ref: "#/components/schemas/UpdateCartData" * - $ref: "#/components/schemas/UpdateCartData"
* - type: object * - type: object
* description: SUMMARY * description: The properties to update in the cart item.
* properties: * properties:
* additional_data: * additional_data:
* type: object * type: object
* description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter. * description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
* description: SUMMARY * description: The properties to update in the cart item.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -55,7 +55,7 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The updated cart's details.
* required: * required:
* - cart * - cart
* properties: * properties:
@@ -1,9 +1,12 @@
/** /**
* @oas [post] /store/carts/{id}/complete * @oas [post] /store/carts/{id}/complete
* operationId: PostCartsIdComplete * operationId: PostCartsIdComplete
* summary: Add Completes to Cart * summary: Complete Cart
* description: Add a list of completes to a cart. * description: Complete a cart and place an order.
* x-authenticated: false * x-authenticated: false
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/checkout/complete-cart
* description: Storefront guide: How to implement cart completion during checkout.
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -29,17 +32,6 @@
* title: fields * title: fields
* description: Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default * description: Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default
* fields. without prefix it will replace the entire default fields. * fields. without prefix it will replace the entire default fields.
* requestBody:
* content:
* application/json:
* schema:
* type: object
* description: SUMMARY
* properties:
* idempotency_key:
* type: string
* title: idempotency_key
* description: The cart's idempotency key.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -54,7 +46,20 @@
* schema: * schema:
* oneOf: * oneOf:
* - type: object * - type: object
* description: SUMMARY * description: The created order's details.
* required:
* - type
* - order
* properties:
* type:
* type: string
* title: type
* description: The type of the returned object.
* default: order
* order:
* $ref: "#/components/schemas/StoreOrder"
* - type: object
* description: The details of why the cart completion failed.
* required: * required:
* - type * - type
* - cart * - cart
@@ -63,12 +68,13 @@
* type: * type:
* type: string * type: string
* title: type * title: type
* description: The cart's type. * description: The type of the returned object.
* default: cart
* cart: * cart:
* $ref: "#/components/schemas/StoreCart" * $ref: "#/components/schemas/StoreCart"
* error: * error:
* type: object * type: object
* description: The cart's error. * description: The error's details.
* required: * required:
* - message * - message
* - name * - name
@@ -85,19 +91,9 @@
* type: * type:
* type: string * type: string
* title: type * title: type
* description: The error's type. * description: >
* - type: object * The error's type. Can be a [MedusaError type](https://docs.medusajs.com/v2/advanced-development/api-routes/errors#medusaerror-types)
* description: SUMMARY * or `payment_authorization_error` or `payment_requires_more_error` for payment-related errors.
* required:
* - type
* - order
* properties:
* type:
* type: string
* title: type
* description: The cart's type.
* order:
* $ref: "#/components/schemas/StoreOrder"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "401": * "401":
@@ -1,8 +1,12 @@
/** /**
* @oas [post] /store/carts/{id}/line-items * @oas [post] /store/carts/{id}/line-items
* operationId: PostCartsIdLineItems * operationId: PostCartsIdLineItems
* summary: Add Line Items to Cart * summary: Add Line Item to Cart
* description: Add a list of line items to a cart. * x-sidebar-summary: Add Line Item
* description: Add a product variant as a line item in the cart.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/cart/manage-items#add-product-variant-to-cart
* description: Storefront guide: How to add a product variant to the cart.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -1,8 +1,12 @@
/** /**
* @oas [post] /store/carts/{id}/line-items/{line_id} * @oas [post] /store/carts/{id}/line-items/{line_id}
* operationId: PostCartsIdLineItemsLine_id * operationId: PostCartsIdLineItemsLine_id
* summary: Add Line Items to Cart * summary: Update a Line Item in a Cart
* description: Add a list of line items to a cart. * x-sidebar-summary: Update Line Item
* description: Update a line item's details in the cart.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/cart/manage-items#update-line-item-in-cart
* description: Storefront guide: How to update a cart's line item.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -13,7 +17,7 @@
* type: string * type: string
* - name: line_id * - name: line_id
* in: path * in: path
* description: The cart's line id. * description: The line item's ID.
* required: true * required: true
* schema: * schema:
* type: string * type: string
@@ -2,6 +2,7 @@
* @oas [post] /store/carts/{id}/promotions * @oas [post] /store/carts/{id}/promotions
* operationId: PostCartsIdPromotions * operationId: PostCartsIdPromotions
* summary: Add Promotions to Cart * summary: Add Promotions to Cart
* x-sidebar-summary: Add Promotions
* description: Add a list of promotions to a cart. * description: Add a list of promotions to a cart.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
@@ -34,17 +35,17 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The promotion's details.
* required: * required:
* - promo_codes * - promo_codes
* properties: * properties:
* promo_codes: * promo_codes:
* type: array * type: array
* description: The cart's promo codes. * description: Promotion codes to add to the cart.
* items: * items:
* type: string * type: string
* title: promo_codes * title: promo_codes
* description: The promo code's promo codes. * description: A promotion code.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -1,8 +1,12 @@
/** /**
* @oas [post] /store/carts/{id}/shipping-methods * @oas [post] /store/carts/{id}/shipping-methods
* operationId: PostCartsIdShippingMethods * operationId: PostCartsIdShippingMethods
* summary: Add Shipping Methods to Cart * summary: Add Shipping Method to Cart
* description: Add a list of shipping methods to a cart. * x-sidebar-summary: Add Shipping Method
* description: Add a shipping method to a cart. Use this API route when the customer chooses their preferred shipping option.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/checkout/shipping
* description: Storefront guide: How to implement shipping during checkout.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -34,17 +38,20 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The shipping method's details.
* required: * required:
* - option_id * - option_id
* properties: * properties:
* option_id: * option_id:
* type: string * type: string
* title: option_id * title: option_id
* description: The cart's option id. * description: The ID of the shipping option this method is created from.
* data: * data:
* type: object * type: object
* description: The cart's data. * description: Any additional data relevant for the third-party fulfillment provider to process the shipment.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/checkout/shipping#data-request-body-parameter
* description: Learn more about the `data` parameter.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -1,8 +1,9 @@
/** /**
* @oas [post] /store/carts/{id}/taxes * @oas [post] /store/carts/{id}/taxes
* operationId: PostCartsIdTaxes * operationId: PostCartsIdTaxes
* summary: Add Taxes to Cart * summary: Calculate Cart Taxes
* description: Add a list of taxes to a cart. * x-sidebar-summary: Calculate Taxes
* description: Calculate the cart's tax lines and amounts.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -1,9 +1,12 @@
/** /**
* @oas [post] /store/customers * @oas [post] /store/customers
* operationId: PostCustomers * operationId: PostCustomers
* summary: Create Customer * summary: Register Customer
* description: Create a customer. * description: Register a customer. Use the `/auth/customer/emailpass/register` API route first to retrieve the registration token and pass it in the header of the request.
* x-authenticated: false * externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/register
* description: Storefront guide: How to register a customer.
* x-authenticated: true
* parameters: * parameters:
* - name: expand * - name: expand
* in: query * in: query
@@ -33,6 +36,7 @@
* label: cURL * label: cURL
* source: |- * source: |-
* curl -X POST '{backend_url}/store/customers' \ * curl -X POST '{backend_url}/store/customers' \
* -H 'Authorization: Bearer {token}' \
* -H 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "email": "Monserrate.Leannon88@yahoo.com", * "email": "Monserrate.Leannon88@yahoo.com",
@@ -1,8 +1,11 @@
/** /**
* @oas [post] /store/customers/me * @oas [post] /store/customers/me
* operationId: PostCustomersMe * operationId: PostCustomersMe
* summary: Create Customer * summary: Update Customer
* description: Create a customer. * description: Update the logged-in customer's details.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/profile
* description: Storefront guide: How to edit a customer's profile.
* x-authenticated: true * x-authenticated: true
* parameters: * parameters:
* - name: expand * - name: expand
@@ -1,8 +1,12 @@
/** /**
* @oas [post] /store/customers/me/addresses * @oas [post] /store/customers/me/addresses
* operationId: PostCustomersMeAddresses * operationId: PostCustomersMeAddresses
* summary: Create Customer * summary: Create Address for Logged-In Customer
* description: Create a customer. * x-sidebar-summary: Create Address
* description: Create an address for the logged-in customer.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses#add-customer-address
* description: Storefront guide: How to create an address for the logged-in customer.
* x-authenticated: true * x-authenticated: true
* parameters: * parameters:
* - name: expand * - name: expand
@@ -31,11 +35,8 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The address's details.
* properties: * properties:
* metadata:
* type: object
* description: The customer's metadata.
* first_name: * first_name:
* type: string * type: string
* title: first_name * title: first_name
@@ -51,43 +52,46 @@
* company: * company:
* type: string * type: string
* title: company * title: company
* description: The customer's company. * description: The address's company.
* address_1: * address_1:
* type: string * type: string
* title: address_1 * title: address_1
* description: The customer's address 1. * description: The address's first line.
* address_2: * address_2:
* type: string * type: string
* title: address_2 * title: address_2
* description: The customer's address 2. * description: The address's second line.
* city: * city:
* type: string * type: string
* title: city * title: city
* description: The customer's city. * description: The address's city.
* country_code: * country_code:
* type: string * type: string
* title: country_code * title: country_code
* description: The customer's country code. * description: The address's country code.
* province: * province:
* type: string * type: string
* title: province * title: province
* description: The customer's province. * description: The address's province.
* postal_code: * postal_code:
* type: string * type: string
* title: postal_code * title: postal_code
* description: The customer's postal code. * description: The address's postal code.
* address_name: * address_name:
* type: string * type: string
* title: address_name * title: address_name
* description: The customer's address name. * description: The address's name.
* is_default_shipping: * is_default_shipping:
* type: boolean * type: boolean
* title: is_default_shipping * title: is_default_shipping
* description: The customer's is default shipping. * description: Whether the address is used by default for shipping during checkout.
* is_default_billing: * is_default_billing:
* type: boolean * type: boolean
* title: is_default_billing * title: is_default_billing
* description: The customer's is default billing. * description: Whether the address is used by default for billing during checkout.
* metadata:
* type: object
* description: Holds custom key-value pairs.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -1,13 +1,17 @@
/** /**
* @oas [post] /store/customers/me/addresses/{address_id} * @oas [post] /store/customers/me/addresses/{address_id}
* operationId: PostCustomersMeAddressesAddress_id * operationId: PostCustomersMeAddressesAddress_id
* summary: Add Addresses to Customer * summary: Update Customer's Address
* description: Add a list of addresses to a customer. * x-sidebar-summary: Update Address
* description: Update the logged-in customer's address.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses#edit-an-address
* description: Storefront guide: How to update an address of the logged-in customer.
* x-authenticated: true * x-authenticated: true
* parameters: * parameters:
* - name: address_id * - name: address_id
* in: path * in: path
* description: The customer's address id. * description: The address's ID.
* required: true * required: true
* schema: * schema:
* type: string * type: string
@@ -37,11 +41,8 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The properties to update in the address.
* properties: * properties:
* metadata:
* type: object
* description: The customer's metadata.
* first_name: * first_name:
* type: string * type: string
* title: first_name * title: first_name
@@ -57,43 +58,46 @@
* company: * company:
* type: string * type: string
* title: company * title: company
* description: The customer's company. * description: The address's company.
* address_1: * address_1:
* type: string * type: string
* title: address_1 * title: address_1
* description: The customer's address 1. * description: The address's first line.
* address_2: * address_2:
* type: string * type: string
* title: address_2 * title: address_2
* description: The customer's address 2. * description: The address's second line.
* city: * city:
* type: string * type: string
* title: city * title: city
* description: The customer's city. * description: The address's city.
* country_code: * country_code:
* type: string * type: string
* title: country_code * title: country_code
* description: The customer's country code. * description: The address's country code.
* province: * province:
* type: string * type: string
* title: province * title: province
* description: The customer's province. * description: The address's province.
* postal_code: * postal_code:
* type: string * type: string
* title: postal_code * title: postal_code
* description: The customer's postal code. * description: The address's postal code.
* address_name: * address_name:
* type: string * type: string
* title: address_name * title: address_name
* description: The customer's address name. * description: The address's name.
* is_default_shipping: * is_default_shipping:
* type: boolean * type: boolean
* title: is_default_shipping * title: is_default_shipping
* description: The customer's is default shipping. * description: Whether the address is used by default for shipping during checkout.
* is_default_billing: * is_default_billing:
* type: boolean * type: boolean
* title: is_default_billing * title: is_default_billing
* description: The customer's is default billing. * description: Whether the address is used by default for billing during checkout.
* metadata:
* type: object
* description: Holds custom key-value pairs.
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -102,18 +106,7 @@
* -H 'Authorization: Bearer {access_token}' \ * -H 'Authorization: Bearer {access_token}' \
* -H 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "metadata": {},
* "first_name": "{value}", * "first_name": "{value}",
* "last_name": "{value}",
* "phone": "{value}",
* "company": "{value}",
* "address_1": "{value}",
* "address_2": "{value}",
* "city": "{value}",
* "country_code": "{value}",
* "province": "{value}",
* "postal_code": "{value}",
* "address_name": "{value}"
* }' * }'
* tags: * tags:
* - Customers * - Customers
@@ -2,7 +2,10 @@
* @oas [post] /store/payment-collections * @oas [post] /store/payment-collections
* operationId: PostPaymentCollections * operationId: PostPaymentCollections
* summary: Create Payment Collection * summary: Create Payment Collection
* description: Create a payment collection. * description: Create a payment collection for a cart. This is used during checkout, where the payment collection holds the cart's payment sessions.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment
* description: Storefront guide: How to implement payment during checkout.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: expand * - name: expand
@@ -1,8 +1,12 @@
/** /**
* @oas [post] /store/payment-collections/{id}/payment-sessions * @oas [post] /store/payment-collections/{id}/payment-sessions
* operationId: PostPaymentCollectionsIdPaymentSessions * operationId: PostPaymentCollectionsIdPaymentSessions
* summary: Add Payment Sessions to Payment Collection * summary: Initialize Payment Session of a Payment Collection
* description: Add a list of payment sessions to a payment collection. * x-sidebar-summary: Initialize Payment Session
* description: Initialize and add a payment session to a payment collection. This is used during checkout, where you create a payment collection for the cart, then initialize a payment session for the payment provider that the customer chooses.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment
* description: Storefront guide: How to implement payment during checkout.
* x-authenticated: false * x-authenticated: false
* parameters: * parameters:
* - name: id * - name: id
@@ -34,20 +38,24 @@
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* description: SUMMARY * description: The payment session's details.
* required: * required:
* - provider_id * - provider_id
* properties: * properties:
* provider_id: * provider_id:
* type: string * type: string
* title: provider_id * title: provider_id
* description: The payment collection's provider id. * description: The ID of the payment provider the customer chose.
* example: pp_stripe_stripe
* context: * context:
* type: object * type: object
* description: The payment collection's context. * description: The payment's context, such as the customer or address details. If the customer is logged-in, the customer `id` is set in the context under a `customer.id` property.
* data: * data:
* type: object * type: object
* description: The payment collection's data. * description: Any data necessary for the payment provider to process the payment.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/payment/payment-session#data-property
* description: Learn more about the payment session's data property
* x-codeSamples: * x-codeSamples:
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
@@ -2,7 +2,7 @@
* @oas [post] /store/return * @oas [post] /store/return
* operationId: PostReturn * operationId: PostReturn
* summary: Create Return * summary: Create Return
* description: Create a return. * description: Create a return for an order's items. The admin receives the return and process it from their side.
* x-authenticated: false * x-authenticated: false
* requestBody: * requestBody:
* content: * content:
@@ -0,0 +1,38 @@
/**
* @schema StoreCreateCart
* type: object
* description: SUMMARY
* x-schemaName: StoreCreateCart
* properties:
* region_id:
* type: string
* title: region_id
* description: The cart's region id.
* shipping_address:
* $ref: "#/components/schemas/StoreCartAddress"
* billing_address:
* $ref: "#/components/schemas/StoreCartAddress"
* email:
* type: string
* title: email
* description: The cart's email.
* format: email
* currency_code:
* type: string
* title: currency_code
* description: The cart's currency code.
* items:
* type: array
* description: The cart's items.
* items:
* $ref: "#/components/schemas/StoreCartLineItem"
* sales_channel_id:
* type: string
* title: sales_channel_id
* description: The cart's sales channel id.
* metadata:
* type: object
* description: The cart's metadata.
*
*/
@@ -69,7 +69,7 @@ class OasKindGenerator extends FunctionKindGenerator {
requiresAuthentication: true, requiresAuthentication: true,
}, },
{ {
startsWith: "store/customers/me", startsWith: "store/customers",
requiresAuthentication: true, requiresAuthentication: true,
}, },
] ]
@@ -779,7 +779,9 @@ class OasKindGenerator extends FunctionKindGenerator {
oasPath.startsWith("admin") oasPath.startsWith("admin")
const isStoreAuthenticated = hasAuthenticationOverride const isStoreAuthenticated = hasAuthenticationOverride
? oasPath.startsWith("store") ? oasPath.startsWith("store")
: !isAuthenticationDisabled && oasPath.startsWith("store") : !isAuthenticationDisabled &&
hasAuthenticationOverride &&
oasPath.startsWith("store")
const isAuthenticated = const isAuthenticated =
isAdminAuthenticated || isStoreAuthenticated || hasAuthenticationOverride isAdminAuthenticated || isStoreAuthenticated || hasAuthenticationOverride