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
Conversation
|
a511e6e
to
5523222
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self-review: highlighted noteworthy code changes.
Added links to JS client.
* schema: | ||
* $ref: "#/components/schemas/StorePostAuthReq" | ||
* x-codegen: | ||
* method: authenticate |
There was a problem hiding this comment.
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> { |
@@ -4,6 +4,8 @@ | |||
* summary: "Customer Log out" | |||
* description: "Destroys a Customer's authenticated session." | |||
* x-authenticated: true | |||
* x-codegen: | |||
* method: deleteSession |
There was a problem hiding this comment.
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> { |
@@ -13,6 +13,8 @@ import CustomerService from "../../../../services/customer" | |||
* format: email | |||
* required: true | |||
* description: The email to check if exists. | |||
* x-codegen: | |||
* method: exists |
There was a problem hiding this comment.
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> { |
@@ -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 |
There was a problem hiding this comment.
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> { |
* schema: | ||
* $ref: "#/components/schemas/StorePostCartsCartShippingMethodReq" | ||
* x-codegen: | ||
* method: addShippingMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
medusa/packages/medusa-js/src/resources/carts.ts
Lines 24 to 28 in 5523222
addShippingMethod( | |
cart_id: string, | |
payload: StorePostCartsCartShippingMethodReq, | |
customHeaders: Record<string, any> = {} | |
): ResponsePromise<StoreCartsRes> { |
@@ -8,6 +8,8 @@ import ShippingProfileService from "../../../../services/shipping-profile" | |||
* description: "Retrieves a list of Shipping Options available to a cart." | |||
* parameters: | |||
* - (path) cart_id {string} The id of the Cart. | |||
* x-codegen: | |||
* method: listCartOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listCartOptions(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreShippingOptionsListRes> { |
@@ -28,6 +28,8 @@ import { validator } from "../../../../utils/validator" | |||
* application/json: | |||
* schema: | |||
* $ref: "#/components/schemas/StorePostSwapsReq" | |||
* x-codegen: | |||
* method: create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create(payload: StorePostSwapsReq, customHeaders: Record<string, any> = {}): ResponsePromise<StoreSwapsRes> { |
@@ -7,6 +7,8 @@ import SwapService from "../../../../services/swap" | |||
* description: "Retrieves a Swap by the id of the Cart used to confirm the Swap." | |||
* parameters: | |||
* - (path) cart_id {string} The id of the Cart | |||
* x-codegen: | |||
* method: retrieveByCartId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retrieveByCartId(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreSwapsRes> { |
* method: retrieve | ||
* queryParams: StoreGetVariantsVariantParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change. client.productVariants.retrieve instead of client.products.variants.retrieve
medusa/packages/medusa-js/src/resources/product-variants.ts
Lines 17 to 20 in 5523222
retrieve(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreVariantsRes> { | |
const path = `/store/variants/${id}` | |
return this.client.request("GET", path, undefined, {}, customHeaders) | |
} |
* method: list | ||
* queryParams: StoreGetVariantsParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
medusa/packages/medusa-js/src/resources/product-variants.ts
Lines 17 to 20 in 5523222
retrieve(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreVariantsRes> { | |
const path = `/store/variants/${id}` | |
return this.client.request("GET", path, undefined, {}, customHeaders) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Very nice!
Given the breaking changes are not breaking the current medusa-js client, but will break in the future I think it's acceptable, also some of the proposed routes make more sense imo 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small change 🙂
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What
Declare
x-codegen
in OAS for Store routes.Why
We are introducing a new
x-codegen
OpenApi extension, also known as vendor extension, in order to help with passing information down to code generators.In our case, we wish to declare the
method
name that we would expect to call on a client. This mimics our current JS client package.E.g.
medusaClient.product.list
whereproduct
is the tag of the route andlist
is the x-codegen.method value.We are also defining the name of a potential typed object for query parameters. OAS 3.0 does not allow to bundle query parameters under a single definition but it is not uncommon to see API clients handle all query parameters as a single typed object, like our JS client package. With x-codegen.queryParams, a code generator can create a named and typed object to bundle all query parameters for a given route.
E.g.
medusaClient.customer.retrieve(id: string, queryParams: AdminGetCustomerParams)
How
Declare
x-codegen
as an object with fieldsmethod
andqueryParams
on all paths.Match method and queryParams values with equivalent ones from our current JS client package.
Test
Expect no visible changes to the documentation.