Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oas): declare x-codegen on Store routes #3074

Merged
merged 6 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/medusa/src/api/routes/store/auth/create-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { validator } from "../../../../utils/validator"
* operationId: "PostAuth"
* summary: "Customer Login"
* description: "Logs a Customer in and authorizes them to view their details. Successful authentication will set a session cookie in the Customer's browser."
* parameters:
* - (body) email=* {string} The Customer's email.
* - (body) password=* {string} The Customer's password.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostAuthReq"
* x-codegen:
* method: authenticate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

authenticate(payload: StorePostAuthReq, customHeaders: Record<string, any> = {}): ResponsePromise<StoreAuthRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -93,6 +97,20 @@ export default async (req, res) => {
res.json({ customer })
}

/**
* @schema StorePostAuthReq
* type: object
* required:
* - email
* - password
* properties:
* email:
* type: string
* description: The Customer's email.
* password:
* type: string
* description: The Customer's password.
*/
export class StorePostAuthReq {
@IsEmail()
email: string
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/auth/delete-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* summary: "Customer Log out"
* description: "Destroys a Customer's authenticated session."
* x-authenticated: true
* x-codegen:
* method: deleteSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleteSession(customHeaders: Record<string, any> = {}): ResponsePromise<void> {

* x-codeSamples:
* - lang: Shell
* label: cURL
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/auth/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import CustomerService from "../../../../services/customer"
* format: email
* required: true
* description: The email to check if exists.
* x-codegen:
* method: exists
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exists(email: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreGetAuthEmailRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/auth/get-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import CustomerService from "../../../../services/customer"
* summary: "Get Current Customer"
* description: "Gets the currently logged in Customer."
* x-authenticated: true
* x-codegen:
* method: getSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getSession(customHeaders: Record<string, any> = {}): ResponsePromise<StoreAuthRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import { validator } from "../../../../utils/validator"
* summary: "Add a Shipping Method"
* parameters:
* - (path) id=* {string} The cart ID.
* - (body) option_id=* {string} ID of the shipping option to create the method from
* - (body) data {Object} Used to hold any data that the shipping method may need to process the fulfillment of the order. Look at the documentation for your installed fulfillment providers to find out what to send.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartShippingMethodReq"
* x-codegen:
* method: addShippingMethod
Copy link
Contributor Author

Choose a reason for hiding this comment

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

addShippingMethod(
cart_id: string,
payload: StorePostCartsCartShippingMethodReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -91,6 +96,19 @@ export default async (req, res) => {
res.status(200).json({ cart: data })
}

/**
* @schema StorePostCartsCartShippingMethodReq
* type: object
* required:
* - option_id
* properties:
* option_id:
* type: string
* description: ID of the shipping option to create the method from
* data:
* type: object
* description: Used to hold any data that the shipping method may need to process the fulfillment of the order. Look at the documentation for your installed fulfillment providers to find out what to send.
*/
export class StorePostCartsCartShippingMethodReq {
@IsString()
option_id: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { IdempotencyKey } from "../../../../models/idempotency-key"
* this may involve making 3rd party API calls to a Tax Provider service."
* parameters:
* - (path) id=* {String} The Cart ID.
* x-codegen:
* method: calculateTaxes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could not find an equivalent in JS client.

* x-codeSamples:
* - lang: Shell
* label: cURL
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/carts/complete-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { IdempotencyKeyService } from "../../../../services"
* will generate one for the request."
* parameters:
* - (path) id=* {String} The Cart id.
* x-codegen:
* method: complete
Copy link
Contributor Author

Choose a reason for hiding this comment

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

complete(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCompleteCartRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/carts/create-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import PublishableAPIKeysFeatureFlag from "../../../../loaders/feature-flags/pub
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartReq"
* x-codegen:
* method: create
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create(
payload?: StorePostCartReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import {
* to the Cart"
* parameters:
* - (path) id=* {string} The id of the Cart to add the Line Item to.
* - (body) variant_id=* {string} The id of the Product Variant to generate the Line Item from.
* - (body) quantity=* {integer} The quantity of the Product Variant to add to the Line Item.
* - (body) metadata {object} An optional key-value map with additional details about the Line Item.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartLineItemsReq"
* x-codegen:
* method: createLineItem
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will introduce a breaking change with the current JS client.

create(
cart_id: string,
payload: StorePostCartsCartLineItemsReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/line-items`
return this.client.request("POST", path, payload, {}, customHeaders)
}

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -129,6 +133,23 @@ export default async (req, res) => {
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
}

/**
* @schema StorePostCartsCartLineItemsReq
* type: object
* required:
* - variant_id
* - quantity
* properties:
* variant_id:
* type: string
* description: The id of the Product Variant to generate the Line Item from.
* quantity:
* type: number
* description: The quantity of the Product Variant to add to the Line Item.
* metadata:
* type: object
* description: An optional key-value map with additional details about the Line Item.
*/
export class StorePostCartsCartLineItemsReq {
@IsString()
variant_id: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import IdempotencyKeyService from "../../../../services/idempotency-key"
* description: "Creates Payment Sessions for each of the available Payment Providers in the Cart's Region."
* parameters:
* - (path) id=* {string} The id of the Cart.
* x-codegen:
* method: createPaymentSessions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

createPaymentSessions(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { CartService } from "../../../../services"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) code=* {string} The unique Discount code.
* x-codegen:
* method: deleteDiscount
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleteDiscount(
cart_id: string,
code: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { CartService } from "../../../../services"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) line_id=* {string} The id of the Line Item.
* x-codegen:
* method: deleteLineItem
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking change

delete(cart_id: string, line_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/line-items/${line_id}`
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { EntityManager } from "typeorm"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) provider_id=* {string} The id of the Payment Provider used to create the Payment Session to be deleted.
* x-codegen:
* method: deletePaymentSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deletePaymentSession(
cart_id: string,
provider_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/carts/get-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { CartService } from "../../../../services"
* description: "Retrieves a Cart."
* parameters:
* - (path) id=* {string} The id of the Cart.
* x-codegen:
* method: retrieve
Copy link
Contributor Author

Choose a reason for hiding this comment

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

retrieve(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { EntityManager } from "typeorm"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) provider_id=* {string} The id of the Payment Provider that created the Payment Session to be refreshed.
* x-codegen:
* method: refreshPaymentSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

refreshPaymentSession(
cart_id: string,
provider_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { validator } from "../../../../utils/validator"
* parameters:
* - (path) id=* {string} The ID of the Cart.
* - (body) provider_id=* {string} The ID of the Payment Provider.
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed in afe7924

* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartPaymentSessionReq"
* x-codegen:
* method: setPaymentSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setPaymentSession(
cart_id: string,
payload: StorePostCartsCartPaymentSessionReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -78,6 +85,16 @@ export default async (req, res) => {
res.status(200).json({ cart: data })
}

/**
* @schema StorePostCartsCartPaymentSessionReq
* type: object
* required:
* - provider_id
* properties:
* provider_id:
* type: string
* description: The ID of the Payment Provider.
*/
export class StorePostCartsCartPaymentSessionReq {
@IsString()
provider_id: string
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/api/routes/store/carts/update-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { IsType } from "../../../../utils/validators/is-type"
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartReq"
* x-codegen:
* method: update
Copy link
Contributor Author

Choose a reason for hiding this comment

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

update(
cart_id: string,
payload: StorePostCartsCartReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
18 changes: 17 additions & 1 deletion packages/medusa/src/api/routes/store/carts/update-line-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { validator } from "../../../../utils/validator"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) line_id=* {string} The id of the Line Item.
* - (body) quantity=* {integer} The quantity to set the Line Item to.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartLineItemsItemReq"
* x-codegen:
* method: updateLineItem
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking change

update(
cart_id: string,
line_id: string,
payload: StorePostCartsCartLineItemsItemReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/line-items/${line_id}`
return this.client.request("POST", path, payload, {}, customHeaders)
}

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -112,6 +118,16 @@ export default async (req, res) => {
res.status(200).json({ cart: data })
}

/**
* @schema StorePostCartsCartLineItemsItemReq
* type: object
* required:
* - quantity
* properties:
* quantity:
* type: number
* description: The quantity to set the Line Item to.
*/
export class StorePostCartsCartLineItemsItemReq {
@IsInt()
quantity: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { EntityManager } from "typeorm"
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) provider_id=* {string} The id of the payment provider.
* - (body) data=* {object} The data to update the payment session with.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCartsCartPaymentSessionUpdateReq"
* x-codegen:
* method: updatePaymentSession
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updatePaymentSession(
cart_id: string,
provider_id: string,
payload: StorePostCartsCartPaymentSessionUpdateReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down Expand Up @@ -83,6 +89,16 @@ export default async (req, res) => {
res.status(200).json({ cart: data })
}

/**
* @schema StorePostCartsCartPaymentSessionUpdateReq
* type: object
* required:
* - data
* properties:
* data:
* type: object
* description: The data to update the payment session with.
*/
export class StorePostCartsCartPaymentSessionUpdateReq {
@IsObject()
data: Record<string, unknown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import ProductCollectionService from "../../../../services/product-collection"
* description: "Retrieves a Product Collection."
* parameters:
* - (path) id=* {string} The id of the Product Collection
* x-codegen:
* method: retrieve
Copy link
Contributor Author

Choose a reason for hiding this comment

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

retrieve(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCollectionsRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ import { Type } from "class-transformer"
* type: string
* description: filter by dates greater than or equal to this date
* format: date
* x-codegen:
* method: list
* queryParams: StoreGetCollectionsParams
Comment on lines +60 to +61
Copy link
Contributor Author

Choose a reason for hiding this comment

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

list(
query?: StoreGetCollectionsParams,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCollectionsListRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCustomersCustomerAddressesReq"
* x-codegen:
* method: addAddress
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking change. customers.addAddress instead of customers.addresses.addAddress

addAddress(
payload: StorePostCustomersCustomerAddressesReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/StorePostCustomersReq"
* x-codegen:
* method: create
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create(
payload: StorePostCustomersReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import CustomerService from "../../../../services/customer"
* x-authenticated: true
* parameters:
* - (path) address_id=* {string} The id of the Address to remove.
* x-codegen:
* method: deleteAddress
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking change

deleteAddress(
address_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {
const path = `/store/customers/me/addresses/${address_id}`
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import CustomerService from "../../../../services/customer"
* summary: Get a Customer
* description: "Retrieves a Customer - the Customer must be logged in to retrieve their details."
* x-authenticated: true
* x-codegen:
* method: retrieve
Copy link
Contributor Author

Choose a reason for hiding this comment

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

retrieve(
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { PaymentProvider } from "../../../../models"
* summary: Get Payment Methods
* description: "Retrieves a list of a Customer's saved payment methods. Payment methods are saved with Payment Providers and it is their responsibility to fetch saved methods."
* x-authenticated: true
* x-codegen:
* method: listPaymentMethods
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking change

list(
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersListPaymentMethodsRes> {
const path = `/store/customers/me/payment-methods`
return this.client.request("GET", path, undefined, {}, customHeaders)
}

* x-codeSamples:
* - lang: JavaScript
* label: JS Client
Expand Down