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

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

View File

@@ -28,14 +28,14 @@
* application/json:
* schema:
* allOf:
* - $ref: "#/components/schemas/CreateCartWorkflowInput"
* - $ref: "#/components/schemas/StoreCreateCart"
* - type: object
* description: SUMMARY
* description: The cart's details.
* properties:
* additional_data:
* 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: SUMMARY
* description: The cart's details.
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -2,7 +2,7 @@
* @oas [post] /store/carts/{id}
* operationId: PostCartsId
* 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
* parameters:
* - name: id
@@ -36,12 +36,12 @@
* allOf:
* - $ref: "#/components/schemas/UpdateCartData"
* - type: object
* description: SUMMARY
* description: The properties to update in the cart item.
* properties:
* additional_data:
* 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: SUMMARY
* description: The properties to update in the cart item.
* x-codeSamples:
* - lang: Shell
* label: cURL
@@ -55,7 +55,7 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The updated cart's details.
* required:
* - cart
* properties:

View File

@@ -1,9 +1,12 @@
/**
* @oas [post] /store/carts/{id}/complete
* operationId: PostCartsIdComplete
* summary: Add Completes to Cart
* description: Add a list of completes to a cart.
* summary: Complete Cart
* description: Complete a cart and place an order.
* 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:
* - name: id
* in: path
@@ -29,17 +32,6 @@
* 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
* 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:
* - lang: Shell
* label: cURL
@@ -54,7 +46,20 @@
* schema:
* oneOf:
* - 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:
* - type
* - cart
@@ -63,12 +68,13 @@
* type:
* type: string
* title: type
* description: The cart's type.
* description: The type of the returned object.
* default: cart
* cart:
* $ref: "#/components/schemas/StoreCart"
* error:
* type: object
* description: The cart's error.
* description: The error's details.
* required:
* - message
* - name
@@ -85,19 +91,9 @@
* type:
* type: string
* title: type
* description: The error's type.
* - type: object
* description: SUMMARY
* required:
* - type
* - order
* properties:
* type:
* type: string
* title: type
* description: The cart's type.
* order:
* $ref: "#/components/schemas/StoreOrder"
* description: >
* The error's type. Can be a [MedusaError type](https://docs.medusajs.com/v2/advanced-development/api-routes/errors#medusaerror-types)
* or `payment_authorization_error` or `payment_requires_more_error` for payment-related errors.
* "400":
* $ref: "#/components/responses/400_error"
* "401":

View File

@@ -1,8 +1,12 @@
/**
* @oas [post] /store/carts/{id}/line-items
* operationId: PostCartsIdLineItems
* summary: Add Line Items to Cart
* description: Add a list of line items to a cart.
* summary: Add Line Item to 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
* parameters:
* - name: id

View File

@@ -1,8 +1,12 @@
/**
* @oas [post] /store/carts/{id}/line-items/{line_id}
* operationId: PostCartsIdLineItemsLine_id
* summary: Add Line Items to Cart
* description: Add a list of line items to a cart.
* summary: Update a Line Item in 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
* parameters:
* - name: id
@@ -13,7 +17,7 @@
* type: string
* - name: line_id
* in: path
* description: The cart's line id.
* description: The line item's ID.
* required: true
* schema:
* type: string

View File

@@ -2,6 +2,7 @@
* @oas [post] /store/carts/{id}/promotions
* operationId: PostCartsIdPromotions
* summary: Add Promotions to Cart
* x-sidebar-summary: Add Promotions
* description: Add a list of promotions to a cart.
* x-authenticated: false
* parameters:
@@ -34,17 +35,17 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The promotion's details.
* required:
* - promo_codes
* properties:
* promo_codes:
* type: array
* description: The cart's promo codes.
* description: Promotion codes to add to the cart.
* items:
* type: string
* title: promo_codes
* description: The promo code's promo codes.
* description: A promotion code.
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -1,8 +1,12 @@
/**
* @oas [post] /store/carts/{id}/shipping-methods
* operationId: PostCartsIdShippingMethods
* summary: Add Shipping Methods to Cart
* description: Add a list of shipping methods to a cart.
* summary: Add Shipping Method to 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
* parameters:
* - name: id
@@ -34,17 +38,20 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The shipping method's details.
* required:
* - option_id
* properties:
* option_id:
* type: string
* title: option_id
* description: The cart's option id.
* description: The ID of the shipping option this method is created from.
* data:
* 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:
* - lang: Shell
* label: cURL

View File

@@ -1,8 +1,9 @@
/**
* @oas [post] /store/carts/{id}/taxes
* operationId: PostCartsIdTaxes
* summary: Add Taxes to Cart
* description: Add a list of taxes to a cart.
* summary: Calculate Cart Taxes
* x-sidebar-summary: Calculate Taxes
* description: Calculate the cart's tax lines and amounts.
* x-authenticated: false
* parameters:
* - name: id

View File

@@ -1,9 +1,12 @@
/**
* @oas [post] /store/customers
* operationId: PostCustomers
* summary: Create Customer
* description: Create a customer.
* x-authenticated: false
* summary: Register 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.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/register
* description: Storefront guide: How to register a customer.
* x-authenticated: true
* parameters:
* - name: expand
* in: query
@@ -33,6 +36,7 @@
* label: cURL
* source: |-
* curl -X POST '{backend_url}/store/customers' \
* -H 'Authorization: Bearer {token}' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "email": "Monserrate.Leannon88@yahoo.com",

View File

@@ -1,8 +1,11 @@
/**
* @oas [post] /store/customers/me
* operationId: PostCustomersMe
* summary: Create Customer
* description: Create a customer.
* summary: Update 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
* parameters:
* - name: expand

View File

@@ -1,8 +1,12 @@
/**
* @oas [post] /store/customers/me/addresses
* operationId: PostCustomersMeAddresses
* summary: Create Customer
* description: Create a customer.
* summary: Create Address for Logged-In 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
* parameters:
* - name: expand
@@ -31,11 +35,8 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The address's details.
* properties:
* metadata:
* type: object
* description: The customer's metadata.
* first_name:
* type: string
* title: first_name
@@ -51,43 +52,46 @@
* company:
* type: string
* title: company
* description: The customer's company.
* description: The address's company.
* address_1:
* type: string
* title: address_1
* description: The customer's address 1.
* description: The address's first line.
* address_2:
* type: string
* title: address_2
* description: The customer's address 2.
* description: The address's second line.
* city:
* type: string
* title: city
* description: The customer's city.
* description: The address's city.
* country_code:
* type: string
* title: country_code
* description: The customer's country code.
* description: The address's country code.
* province:
* type: string
* title: province
* description: The customer's province.
* description: The address's province.
* postal_code:
* type: string
* title: postal_code
* description: The customer's postal code.
* description: The address's postal code.
* address_name:
* type: string
* title: address_name
* description: The customer's address name.
* description: The address's name.
* is_default_shipping:
* type: boolean
* 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:
* type: boolean
* 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:
* - lang: Shell
* label: cURL

View File

@@ -1,13 +1,17 @@
/**
* @oas [post] /store/customers/me/addresses/{address_id}
* operationId: PostCustomersMeAddressesAddress_id
* summary: Add Addresses to Customer
* description: Add a list of addresses to a customer.
* summary: Update Customer's Address
* 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
* parameters:
* - name: address_id
* in: path
* description: The customer's address id.
* description: The address's ID.
* required: true
* schema:
* type: string
@@ -37,11 +41,8 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The properties to update in the address.
* properties:
* metadata:
* type: object
* description: The customer's metadata.
* first_name:
* type: string
* title: first_name
@@ -57,43 +58,46 @@
* company:
* type: string
* title: company
* description: The customer's company.
* description: The address's company.
* address_1:
* type: string
* title: address_1
* description: The customer's address 1.
* description: The address's first line.
* address_2:
* type: string
* title: address_2
* description: The customer's address 2.
* description: The address's second line.
* city:
* type: string
* title: city
* description: The customer's city.
* description: The address's city.
* country_code:
* type: string
* title: country_code
* description: The customer's country code.
* description: The address's country code.
* province:
* type: string
* title: province
* description: The customer's province.
* description: The address's province.
* postal_code:
* type: string
* title: postal_code
* description: The customer's postal code.
* description: The address's postal code.
* address_name:
* type: string
* title: address_name
* description: The customer's address name.
* description: The address's name.
* is_default_shipping:
* type: boolean
* 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:
* type: boolean
* 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:
* - lang: Shell
* label: cURL
@@ -102,18 +106,7 @@
* -H 'Authorization: Bearer {access_token}' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "metadata": {},
* "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:
* - Customers

View File

@@ -2,7 +2,10 @@
* @oas [post] /store/payment-collections
* operationId: PostPaymentCollections
* 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
* parameters:
* - name: expand

View File

@@ -1,8 +1,12 @@
/**
* @oas [post] /store/payment-collections/{id}/payment-sessions
* operationId: PostPaymentCollectionsIdPaymentSessions
* summary: Add Payment Sessions to Payment Collection
* description: Add a list of payment sessions to a payment collection.
* summary: Initialize Payment Session of 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
* parameters:
* - name: id
@@ -34,20 +38,24 @@
* application/json:
* schema:
* type: object
* description: SUMMARY
* description: The payment session's details.
* required:
* - provider_id
* properties:
* provider_id:
* type: string
* 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:
* 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:
* 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:
* - lang: Shell
* label: cURL

View File

@@ -2,7 +2,7 @@
* @oas [post] /store/return
* operationId: PostReturn
* 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
* requestBody:
* content:

View File

@@ -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.
*
*/

View File

@@ -69,7 +69,7 @@ class OasKindGenerator extends FunctionKindGenerator {
requiresAuthentication: true,
},
{
startsWith: "store/customers/me",
startsWith: "store/customers",
requiresAuthentication: true,
},
]
@@ -779,7 +779,9 @@ class OasKindGenerator extends FunctionKindGenerator {
oasPath.startsWith("admin")
const isStoreAuthenticated = hasAuthenticationOverride
? oasPath.startsWith("store")
: !isAuthenticationDisabled && oasPath.startsWith("store")
: !isAuthenticationDisabled &&
hasAuthenticationOverride &&
oasPath.startsWith("store")
const isAuthenticated =
isAdminAuthenticated || isStoreAuthenticated || hasAuthenticationOverride