chore(oas): replace response with $ref class JSDoc (Store PRO-V) (#3044)

### Scope

Store routes directories PRO to V.

### What

Move inline OAS response schema declaration under their respective class declarations in order to expose them through  `#/components/schemas`. Replace inline OAS response schema with a `$ref` reference pointing to the newly declared schema.

### Why

Having response declared as its own "named" schema will allow OAS code generators to output typed entities/DTO that can be consumed without having to reference the route/operation.

### How

Declare a new @schema JSDoc for each "Res" class used to parse and validate request body. Move the current inline requestBody to the new @schema.

### Test

- Ran OAS validator.
- Ran docs build script.

Expect no visible changes to the documentation.
This commit is contained in:
Patrick
2023-01-17 09:22:10 -05:00
committed by GitHub
parent 0175388835
commit cb1ec0076b
29 changed files with 215 additions and 166 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
chore(oas): replace response with $ref class JSDoc (Store PRO-V)

View File

@@ -211,7 +211,9 @@ export type AdminProductsDeleteRes = {
* products: * products:
* type: array * type: array
* items: * items:
* $ref: "#/components/schemas/Product" * oneOf:
* - $ref: "#/components/schemas/Product"
* - $ref: "#/components/schemas/PricedProduct"
* count: * count:
* type: integer * type: integer
* description: The total number of items available * description: The total number of items available

View File

@@ -3,7 +3,7 @@ import { Request, Response } from "express"
import ProductCategoryService from "../../../../services/product-category" import ProductCategoryService from "../../../../services/product-category"
import { FindParams } from "../../../../types/common" import { FindParams } from "../../../../types/common"
import { transformTreeNodesWithConfig } from "../../../../utils/transformers/tree" import { transformTreeNodesWithConfig } from "../../../../utils/transformers/tree"
import { defaultStoreProductCategoryRelations, defaultStoreScope } from "." import { defaultStoreScope } from "."
/** /**
* @oas [get] /product-categories/{id} * @oas [get] /product-categories/{id}
@@ -42,10 +42,7 @@ import { defaultStoreProductCategoryRelations, defaultStoreScope } from "."
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreGetProductCategoryRes"
* properties:
* productCategory:
* $ref: "#/components/schemas/ProductCategory"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "401": * "401":

View File

@@ -3,6 +3,7 @@ import middlewares, { transformQuery } from "../../../middlewares"
import getProductCategory, { import getProductCategory, {
StoreGetProductCategoryParams, StoreGetProductCategoryParams,
} from "./get-product-category" } from "./get-product-category"
import { ProductCategory } from "../../../../models"
import listProductCategories, { import listProductCategories, {
StoreGetProductCategoriesParams, StoreGetProductCategoriesParams,
@@ -66,5 +67,16 @@ export const allowedStoreProductCategoryFields = [
"updated_at", "updated_at",
] ]
/**
* @schema StoreGetProductCategoryRes
* type: object
* properties:
* product_category:
* $ref: "#/components/schemas/ProductCategory"
*/
export type StoreGetProductCategoryRes = {
product_category: ProductCategory
}
export * from "./get-product-category" export * from "./get-product-category"
export * from "./list-product-categories" export * from "./list-product-categories"

View File

@@ -39,12 +39,26 @@ export const defaultStoreProductTypeFields = [
] ]
export const defaultStoreProductTypeRelations = [] export const defaultStoreProductTypeRelations = []
/**
* @schema StoreProductTypesListRes
* type: object
* properties:
* product_types:
* type: array
* items:
* $ref: "#/components/schemas/ProductType"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
*/
export type StoreProductTypesListRes = PaginatedResponse & { export type StoreProductTypesListRes = PaginatedResponse & {
product_types: ProductType[] product_types: ProductType[]
} }
export type StoreProductTypesRes = {
product_type: ProductType
}
export * from "./list-product-types" export * from "./list-product-types"

View File

@@ -109,19 +109,7 @@ import ProductTypeService from "../../../../services/product-type"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreProductTypesListRes"
* properties:
* product_types:
* $ref: "#/components/schemas/ProductType"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "401": * "401":

View File

@@ -49,19 +49,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreProductsRes"
* properties:
* product:
* allOf:
* - $ref: "#/components/schemas/Product"
* - type: object
* properties:
* variants:
* type: array
* items:
* allOf:
* - $ref: "#/components/schemas/ProductVariant"
* - $ref: "#/components/schemas/ProductVariantPricesFields"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -54,15 +54,48 @@ export const defaultStoreProductsRelations = [
export * from "./list-products" export * from "./list-products"
export * from "./search" export * from "./search"
/**
* @schema StoreProductsRes
* type: object
* properties:
* product:
* $ref: "#/components/schemas/PricedProduct"
*/
export type StoreProductsRes = { export type StoreProductsRes = {
product: Product product: Product
} }
/**
* @schema StorePostSearchRes
* type: object
* properties:
* hits:
* type: array
* description: Array of results. The format of the items depends on the search engine installed on the server.
*/
export type StorePostSearchRes = { export type StorePostSearchRes = {
hits: unknown[] hits: unknown[]
[k: string]: unknown [k: string]: unknown
} }
/**
* @schema StoreProductsListRes
* type: object
* properties:
* products:
* type: array
* items:
* $ref: "#/components/schemas/PricedProduct"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
*/
export type StoreProductsListRes = PaginatedResponse & { export type StoreProductsListRes = PaginatedResponse & {
products: Product[] products: Product[]
} }

View File

@@ -151,30 +151,7 @@ import PublishableAPIKeysFeatureFlag from "../../../../loaders/feature-flags/pub
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreProductsListRes"
* properties:
* products:
* type: array
* items:
* allOf:
* - $ref: "#/components/schemas/Product"
* - type: object
* properties:
* variants:
* type: array
* items:
* allOf:
* - $ref: "#/components/schemas/ProductVariant"
* - $ref: "#/components/schemas/ProductVariantPricesFields"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -39,11 +39,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StorePostSearchRes"
* properties:
* hits:
* type: array
* description: Array of results. The format of the items depends on the search engine installed on the server.
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -29,10 +29,7 @@ import RegionService from "../../../../services/region"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreRegionsRes"
* properties:
* region:
* $ref: "#/components/schemas/Region"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -13,10 +13,26 @@ export default (app) => {
return app return app
} }
/**
* @schema StoreRegionsListRes
* type: object
* properties:
* regions:
* type: array
* items:
* $ref: "#/components/schemas/Region"
*/
export type StoreRegionsListRes = { export type StoreRegionsListRes = {
regions: Region[] regions: Region[]
} }
/**
* @schema StoreRegionsRes
* type: object
* properties:
* region:
* $ref: "#/components/schemas/Region"
*/
export type StoreRegionsRes = { export type StoreRegionsRes = {
region: Region region: Region
} }

View File

@@ -80,12 +80,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreRegionsListRes"
* properties:
* regions:
* type: array
* items:
* $ref: "#/components/schemas/Region"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -33,10 +33,7 @@ import ReturnReasonService from "../../../../services/return-reason"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreReturnReasonsRes"
* properties:
* return_reason:
* $ref: "#/components/schemas/ReturnReason"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -36,10 +36,26 @@ export const defaultStoreReturnReasonRelations: (keyof ReturnReason)[] = [
"return_reason_children", "return_reason_children",
] ]
/**
* @schema StoreReturnReasonsListRes
* type: object
* properties:
* return_reasons:
* type: array
* items:
* $ref: "#/components/schemas/ReturnReason"
*/
export type StoreReturnReasonsListRes = { export type StoreReturnReasonsListRes = {
return_reasons: ReturnReason[] return_reasons: ReturnReason[]
} }
/**
* @schema StoreReturnReasonsRes
* type: object
* properties:
* return_reason:
* $ref: "#/components/schemas/ReturnReason"
*/
export type StoreReturnReasonsRes = { export type StoreReturnReasonsRes = {
return_reason: ReturnReason return_reason: ReturnReason
} }

View File

@@ -31,12 +31,7 @@ import ReturnReasonService from "../../../../services/return-reason"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreReturnReasonsListRes"
* properties:
* return_reasons:
* type: array
* items:
* $ref: "#/components/schemas/ReturnReason"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -66,10 +66,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreReturnsRes"
* properties:
* return:
* $ref: "#/components/schemas/Return"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -12,6 +12,13 @@ export default (app) => {
return app return app
} }
/**
* @schema StoreReturnsRes
* type: object
* properties:
* return:
* $ref: "#/components/schemas/Return"
*/
export type StoreReturnsRes = { export type StoreReturnsRes = {
return: Return return: Return
} }

View File

@@ -16,6 +16,15 @@ export default (app) => {
return app return app
} }
/**
* @schema StoreShippingOptionsListRes
* type: object
* properties:
* shipping_options:
* type: array
* items:
* $ref: "#/components/schemas/ShippingOption"
*/
export type StoreShippingOptionsListRes = { export type StoreShippingOptionsListRes = {
shipping_options: ShippingOption[] shipping_options: ShippingOption[]
} }

View File

@@ -34,12 +34,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreShippingOptionsListRes"
* properties:
* shipping_options:
* type: array
* items:
* $ref: "#/components/schemas/ShippingOption"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -30,12 +30,7 @@ import ShippingProfileService from "../../../../services/shipping-profile"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreShippingOptionsListRes"
* properties:
* shipping_options:
* type: array
* items:
* $ref: "#/components/schemas/ShippingOption"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -80,10 +80,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreSwapsRes"
* properties:
* swap:
* $ref: "#/components/schemas/Swap"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -29,10 +29,7 @@ import SwapService from "../../../../services/swap"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreSwapsRes"
* properties:
* swap:
* $ref: "#/components/schemas/Swap"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -45,6 +45,13 @@ export const defaultStoreSwapFields: FindConfig<Swap>["select"] = [
"idempotency_key", "idempotency_key",
] ]
/**
* @schema StoreSwapsRes
* type: object
* properties:
* swap:
* $ref: "#/components/schemas/Swap"
*/
export type StoreSwapsRes = { export type StoreSwapsRes = {
swap: Swap swap: Swap
} }

View File

@@ -41,12 +41,7 @@ import { validator } from "../../../../utils/validator"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreVariantsRes"
* properties:
* variant:
* allOf:
* - $ref: "#/components/schemas/ProductVariant"
* - $ref: "#/components/schemas/ProductVariantPricesFields"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -1,4 +1,3 @@
import { PaginatedResponse } from "./../../../../types/common"
import { ProductVariant } from "../../../../" import { ProductVariant } from "../../../../"
import { Router } from "express" import { Router } from "express"
import middlewares from "../../../middlewares" import middlewares from "../../../middlewares"
@@ -16,11 +15,27 @@ export default (app) => {
export const defaultStoreVariantRelations = ["prices", "options"] export const defaultStoreVariantRelations = ["prices", "options"]
/**
* @schema StoreVariantsRes
* type: object
* properties:
* variant:
* $ref: "#/components/schemas/PricedVariant"
*/
export type StoreVariantsRes = { export type StoreVariantsRes = {
variant: ProductVariant variant: ProductVariant
} }
export type StoreVariantsListRes = PaginatedResponse & { /**
* @schema StoreVariantsListRes
* type: object
* properties:
* variants:
* type: array
* items:
* $ref: "#/components/schemas/PricedVariant"
*/
export type StoreVariantsListRes = {
variants: ProductVariant[] variants: ProductVariant[]
} }

View File

@@ -73,14 +73,7 @@ import { IsType } from "../../../../utils/validators/is-type"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreVariantsListRes"
* properties:
* variants:
* type: array
* items:
* allOf:
* - $ref: "#/components/schemas/ProductVariant"
* - $ref: "#/components/schemas/ProductVariantPricesFields"
* "400": * "400":
* $ref: "#/components/responses/400_error" * $ref: "#/components/responses/400_error"
* "404": * "404":

View File

@@ -216,44 +216,3 @@ export class ProductVariant extends SoftDeletableEntity {
* description: An optional key-value map with additional details * description: An optional key-value map with additional details
* example: {car: "white"} * example: {car: "white"}
*/ */
/**
* @schema ProductVariantPricesFields
* title: "Product Variant Prices Fields"
* description: "Product Variants Prices Fields that are only available in some requests."
* type: object
* properties:
* original_price:
* type: number
* description: The original price of the variant without any discounted prices applied.
* calculated_price:
* type: number
* description: The calculated price of the variant. Can be a discounted price.
* original_price_incl_tax:
* type: number
* description: The original price of the variant including taxes.
* calculated_price_incl_tax:
* type: number
* description: The calculated price of the variant including taxes.
* original_tax:
* type: number
* description: The taxes applied on the original price.
* calculated_tax:
* type: number
* description: The taxes applied on the calculated price.
* tax_rates:
* type: array
* description: An array of applied tax rates
* items:
* type: object
* properties:
* rate:
* type: number
* description: The tax rate value
* name:
* type: string
* description: The name of the tax rate
* code:
* type: string
* description: The code of the tax rate
*/

View File

@@ -34,8 +34,63 @@ export type ShippingOptionPricing = {
export type PricedShippingOption = Partial<ShippingOption> & export type PricedShippingOption = Partial<ShippingOption> &
ShippingOptionPricing ShippingOptionPricing
/**
* @schema PricedVariant
* title: "Priced Product Variant"
* type: object
* allOf:
* - $ref: "#/components/schemas/ProductVariant"
* - type: object
* properties:
* original_price:
* type: number
* description: The original price of the variant without any discounted prices applied.
* calculated_price:
* type: number
* description: The calculated price of the variant. Can be a discounted price.
* original_price_incl_tax:
* type: number
* description: The original price of the variant including taxes.
* calculated_price_incl_tax:
* type: number
* description: The calculated price of the variant including taxes.
* original_tax:
* type: number
* description: The taxes applied on the original price.
* calculated_tax:
* type: number
* description: The taxes applied on the calculated price.
* tax_rates:
* type: array
* description: An array of applied tax rates
* items:
* type: object
* properties:
* rate:
* type: number
* description: The tax rate value
* name:
* type: string
* description: The name of the tax rate
* code:
* type: string
* description: The code of the tax rate
*/
export type PricedVariant = Partial<ProductVariant> & ProductVariantPricing export type PricedVariant = Partial<ProductVariant> & ProductVariantPricing
/**
* @schema PricedProduct
* title: "Priced Product"
* type: object
* allOf:
* - $ref: "#/components/schemas/Product"
* - type: object
* properties:
* variants:
* type: array
* items:
* $ref: "#/components/schemas/PricedVariant"
*/
export type PricedProduct = Omit<Partial<Product>, "variants"> & { export type PricedProduct = Omit<Partial<Product>, "variants"> & {
variants: PricedVariant[] variants: PricedVariant[]
} }