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

Conversation

patrick-medusajs
Copy link
Contributor

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 where product is the tag of the route and list 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 fields method and queryParams on all paths.

Match method and queryParams values with equivalent ones from our current JS client package.

Test

  • Ran OAS validator.
  • Ran docs build script.

Expect no visible changes to the documentation.

@patrick-medusajs patrick-medusajs self-assigned this Jan 19, 2023
@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2023

⚠️ No Changeset found

Latest commit: be0f3f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

@patrick-medusajs patrick-medusajs left a 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
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> {

@@ -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> {

@@ -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> {

@@ -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> {

* 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> {

@@ -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
Copy link
Contributor Author

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
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: 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
Copy link
Contributor Author

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> {

Comment on lines +32 to +33
* method: retrieve
* queryParams: StoreGetVariantsVariantParams
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. client.productVariants.retrieve instead of client.products.variants.retrieve

retrieve(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreVariantsRes> {
const path = `/store/variants/${id}`
return this.client.request("GET", path, undefined, {}, customHeaders)
}

Comment on lines +67 to +68
* method: list
* queryParams: StoreGetVariantsParams
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<StoreVariantsRes> {
const path = `/store/variants/${id}`
return this.client.request("GET", path, undefined, {}, customHeaders)
}

@patrick-medusajs patrick-medusajs marked this pull request as ready for review January 19, 2023 22:07
@patrick-medusajs patrick-medusajs requested a review from a team as a code owner January 19, 2023 22:07
Copy link
Contributor

@pKorsholm pKorsholm left a 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 😅

@patrick-medusajs patrick-medusajs requested review from shahednasser and a team January 20, 2023 18:34
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

LGTM! 💪

Copy link
Member

@shahednasser shahednasser left a 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.
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

Copy link
Member

@shahednasser shahednasser left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit 6e89d94 into develop Jan 23, 2023
@kodiakhq kodiakhq bot deleted the feat/oas-x-codegen-store branch January 23, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants