feat(oas): declare x-codegen on Admin routes - PRO to R (#3093)

### What

Declare `x-codegen` in OAS for Admin routes - PRO to R.

### 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.
This commit is contained in:
Patrick
2023-01-24 10:11:34 -05:00
committed by GitHub
parent 8e41c69966
commit d25a531045
52 changed files with 128 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
feat(oas): declare x-codegen on Admin routes - PRO to R

View File

@@ -1,4 +1,4 @@
import { IsNotEmpty, IsOptional, IsString, IsBoolean } from "class-validator"
import { IsNotEmpty, IsString } from "class-validator"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
@@ -13,13 +13,15 @@ import { FindParams } from "../../../../types/common"
* description: "Creates a Product Category."
* x-authenticated: true
* parameters:
* - (query) expand {string} (Comma separated) Which fields should be expanded in each product category.
* - (query) fields {string} (Comma separated) Which fields should be retrieved in each product category.
* - (query) expand {string} (Comma separated) Which fields should be expanded in the results.
* - (query) fields {string} (Comma separated) Which fields should be retrieved in the results.
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductCategoriesReq"
* x-codegen:
* method: create
* x-codeSamples:
* - lang: Shell
* label: cURL
@@ -76,7 +78,7 @@ export default async (req: Request, res: Response) => {
const productCategory = await productCategoryService.retrieve(
created.id,
req.retrieveConfig,
req.retrieveConfig
)
res.status(200).json({ product_category: productCategory })

View File

@@ -11,6 +11,8 @@ import { ProductCategoryService } from "../../../../services"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Product Category
* x-codegen:
* method: delete
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -12,6 +12,11 @@ import { defaultAdminProductCategoryRelations } from "."
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Product Category
* - (query) expand {string} (Comma separated) Which fields should be expanded in the results.
* - (query) fields {string} (Comma separated) Which fields should be included in the results.
* x-codegen:
* method: retrieve
* queryParams: AdminGetProductCategoryParams
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -1,6 +1,6 @@
import { IsNumber, IsOptional, IsString } from "class-validator"
import { IsOptional, IsString } from "class-validator"
import { Request, Response } from "express"
import { Type, Transform } from "class-transformer"
import { Transform } from "class-transformer"
import { ProductCategoryService } from "../../../../services"
import { extendedFindParamsMixin } from "../../../../types/common"
@@ -20,6 +20,9 @@ import { extendedFindParamsMixin } from "../../../../types/common"
* - (query) limit=100 {integer} Limit the number of product categories returned.
* - (query) expand {string} (Comma separated) Which fields should be expanded in the product category.
* - (query) fields {string} (Comma separated) Which fields should be included in the product category.
* x-codegen:
* method: list
* queryParams: AdminGetProductCategoriesParams
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -5,6 +5,7 @@ import { EntityManager } from "typeorm"
import { ProductCategoryService } from "../../../../services"
import { AdminProductCategoriesReqBase } from "../../../../types/product-category"
import { FindParams } from "../../../../types/common"
/**
* @oas [post] /product-categories/{id}
* operationId: "PostProductCategoriesCategory"
@@ -20,6 +21,9 @@ import { FindParams } from "../../../../types/common"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductCategoriesCategoryReq"
* x-codegen:
* method: update
* queryParams: AdminPostProductCategoriesCategoryParams
* x-codeSamples:
* - lang: Shell
* label: cURL
@@ -77,7 +81,7 @@ export default async (req: Request, res: Response) => {
const productCategory = await productCategoryService.retrieve(
updated.id,
req.retrieveConfig,
req.retrieveConfig
)
res.status(200).json({ product_category: productCategory })

View File

@@ -83,6 +83,9 @@ import { Request, Response } from "express"
* type: string
* description: filter by dates greater than or equal to this date
* format: date
* x-codegen:
* method: list
* queryParams: AdminGetProductTagsParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -82,6 +82,9 @@ import ProductTypeService from "../../../../services/product-type"
* type: string
* description: filter by dates greater than or equal to this date
* format: date
* x-codegen:
* method: list
* queryParams: AdminGetProductTypesParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -18,6 +18,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductOptionsReq"
* x-codegen:
* method: addOption
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -43,6 +43,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsReq"
* x-codegen:
* method: create
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -47,6 +47,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductVariantsReq"
* x-codegen:
* method: createVariant
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -12,6 +12,8 @@ import { ProductService } from "../../../../services"
* parameters:
* - (path) id=* {string} The ID of the Product.
* - (path) option_id=* {string} The ID of the Product Option.
* x-codegen:
* method: deleteOption
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -9,6 +9,8 @@ import { ProductService } from "../../../../services"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Product.
* x-codegen:
* method: delete
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -16,6 +16,8 @@ import { EntityManager } from "typeorm"
* parameters:
* - (path) id=* {string} The ID of the Product.
* - (path) variant_id=* {string} The ID of the Product Variant.
* x-codegen:
* method: deleteVariant
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -8,6 +8,8 @@ import { PricingService, ProductService } from "../../../../services"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Product.
* x-codegen:
* method: retrieve
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -158,6 +158,9 @@ import { FilterableProductProps } from "../../../../types/product"
* - (query) expand {string} (Comma separated) Which fields should be expanded in each product of the result.
* - (query) fields {string} (Comma separated) Which fields should be included in each product of the result.
* - (query) order {string} the field used to order the products.
* x-codegen:
* method: list
* queryParams: AdminGetProductsParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -6,6 +6,8 @@ import { ProductService } from "../../../../services"
* summary: "List Tags Usage Number"
* description: "Retrieves a list of Product Tags with how many times each is used."
* x-authenticated: true
* x-codegen:
* method: listTags
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -7,6 +7,8 @@ import { ProductService } from "../../../../services"
* summary: "List Product Types"
* description: "Retrieves a list of Product Types."
* x-authenticated: true
* x-codegen:
* method: listTypes
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -20,6 +20,9 @@ import { validator } from "../../../../utils/validator"
* - (query) expand {string} Comma separated string of the relations to include.
* - (query) offset=0 {integer} How many items to skip before the results.
* - (query) limit=100 {integer} Limit the number of items returned.
* x-codegen:
* method: listVariants
* queryParams: AdminGetProductsVariantsParams
* x-codeSamples:
* - lang: Shell
* label: cURL

View File

@@ -17,6 +17,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductMetadataReq"
* x-codegen:
* method: setMetadata
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductOptionsOption"
* x-codegen:
* method: updateOption
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -40,6 +40,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductReq"
* x-codegen:
* method: update
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -34,6 +34,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostProductsProductVariantsVariantReq"
* x-codegen:
* method: updateVariant
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostPublishableApiKeySalesChannelsBatchReq"
* x-codegen:
* method: addSalesChannelsBatch
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -15,6 +15,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* schema:
* $ref: "#/components/schemas/AdminPostPublishableApiKeysReq"
* x-authenticated: true
* x-codegen:
* method: create
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminDeletePublishableApiKeySalesChannelsBatchReq"
* x-codegen:
* method: deleteSalesChannelsBatch
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -10,6 +10,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the PublishableApiKeys to delete.
* x-codegen:
* method: delete
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -10,6 +10,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* parameters:
* - (path) id=* {string} The ID of the PublishableApiKey.
* x-authenticated: true
* x-codegen:
* method: retrieve
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -13,6 +13,9 @@ import { extendedFindParamsMixin } from "../../../../types/common"
* parameters:
* - (path) id=* {string} The ID of the Publishable Api Key.
* - (query) q {string} Query used for searching sales channels' names and descriptions.
* x-codegen:
* method: listSalesChannels
* queryParams: GetPublishableApiKeySalesChannelsParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -16,6 +16,9 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* - (query) offset=0 {number} The offset of items in response
* - (query) expand {string} Comma separated list of relations to include in the results.
* - (query) fields {string} Comma separated list of fields to include in the results.
* x-codegen:
* method: list
* queryParams: GetPublishableApiKeysParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -11,6 +11,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* parameters:
* - (path) id=* {string} The ID of the PublishableApiKey.
* x-authenticated: true
* x-codegen:
* method: revoke
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -17,6 +17,8 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostPublishableApiKeysPublishableApiKeyReq"
* x-codegen:
* method: update
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostRegionsRegionCountriesReq"
* x-codegen:
* method: addCountry
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostRegionsRegionFulfillmentProvidersReq"
* x-codegen:
* method: addFulfillmentProvider
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostRegionsRegionPaymentProvidersReq"
* x-codegen:
* method: addPaymentProvider
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -25,6 +25,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostRegionsReq"
* x-codegen:
* method: create
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -9,6 +9,8 @@ import RegionService from "../../../../services/region"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Region.
* x-codegen:
* method: delete
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -10,6 +10,8 @@ import RegionService from "../../../../services/region"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Region.
* x-codegen:
* method: retrieveFulfillmentOptions
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -10,6 +10,8 @@ import RegionService from "../../../../services/region"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Region.
* x-codegen:
* method: retrieve
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -47,6 +47,9 @@ import { validator } from "../../../../utils/validator"
* type: object
* required: false
* description: Date comparison for when resulting region was deleted, i.e. less than, greater than etc.
* x-codegen:
* method: list
* queryParams: AdminGetRegionsParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -20,6 +20,8 @@ import RegionService from "../../../../services/region"
* externalDocs:
* url: https://en.wikipedia.org/wiki/ISO_4217#Active_codes
* description: See a list of codes.
* x-codegen:
* method: deleteCountry
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -12,6 +12,8 @@ import RegionService from "../../../../services/region"
* parameters:
* - (path) id=* {string} The ID of the Region.
* - (path) provider_id=* {string} The ID of the Fulfillment Provider.
* x-codegen:
* method: deleteFulfillmentProvider
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -12,6 +12,8 @@ import RegionService from "../../../../services/region"
* parameters:
* - (path) id=* {string} The ID of the Region.
* - (path) provider_id=* {string} The ID of the Payment Provider.
* x-codegen:
* method: deletePaymentProvider
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -27,6 +27,8 @@ import { validator } from "../../../../utils/validator"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostRegionsRegionReq"
* x-codegen:
* method: update
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -19,6 +19,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostReturnReasonsReq"
* x-codegen:
* method: create
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -9,6 +9,8 @@ import { ReturnReasonService } from "../../../../services"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the return reason
* x-codegen:
* method: delete
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -13,6 +13,8 @@ import { ReturnReasonService } from "../../../../services"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Return Reason.
* x-codegen:
* method: retrieve
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -12,6 +12,8 @@ import { Selector } from "../../../../types/common"
* summary: "List Return Reasons"
* description: "Retrieves a list of Return Reasons."
* x-authenticated: true
* x-codegen:
* method: list
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -21,6 +21,8 @@ import { EntityManager } from "typeorm"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostReturnReasonsReasonReq"
* x-codegen:
* method: update
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -12,6 +12,8 @@ import { EntityManager } from "typeorm"
* description: "Registers a Return as canceled."
* parameters:
* - (path) id=* {string} The ID of the Return.
* x-codegen:
* method: cancel
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -14,6 +14,9 @@ import { Return } from "../../../../models"
* parameters:
* - (query) limit=50 {number} The upper limit for the amount of responses returned.
* - (query) offset=0 {number} The offset of the list returned.
* x-codegen:
* method: list
* queryParams: AdminGetReturnsParams
* x-codeSamples:
* - lang: JavaScript
* label: JS Client

View File

@@ -24,6 +24,8 @@ import { isDefined } from "medusa-core-utils"
* application/json:
* schema:
* $ref: "#/components/schemas/AdminPostReturnsReturnReceiveReq"
* x-codegen:
* method: receive
* x-codeSamples:
* - lang: JavaScript
* label: JS Client