feat(oas): identify required fields in responses - store (#3282)

## Scope

Store routes

## What

Add OAS `required` to response schemas.

## Why

Code generator can use the `required` property of a schema to mark fields as optional or not when generating TS types.

## Test

* Run `yarn build`
* Run `yarn openapi:generate`
* Run `yarn redocly preview-docs docs/api/store/openapi.yaml --config=docs-util/redocly/config.yaml`
* Open the documentation preview URL in a browser (http://127.0.0.1:8080)
* Expect responses to have their fields declared as `required`
This commit is contained in:
Patrick authored and GitHub committed 2023-02-17 15:28:01 +00:00
1 parent 7e6f15d4a9
commit 38503fff56
20 files changed
+121 -26

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
feat(oas): identify required fields in responses - store
@@ -22,6 +22,8 @@ export default (app) => {
/** /**
* @schema StoreAuthRes * @schema StoreAuthRes
* type: object * type: object
* required:
* - customer
* properties: * properties:
* customer: * customer:
* $ref: "#/components/schemas/Customer" * $ref: "#/components/schemas/Customer"
@@ -33,10 +35,12 @@ export type StoreAuthRes = {
/** /**
* @schema StoreGetAuthEmailRes * @schema StoreGetAuthEmailRes
* type: object * type: object
* required:
* - exists
* properties: * properties:
* exists: * exists:
* type: boolean
* description: Whether email exists or not. * description: Whether email exists or not.
* type: boolean
*/ */
export type StoreGetAuthEmailRes = { export type StoreGetAuthEmailRes = {
exists: boolean exists: boolean
@@ -2,7 +2,7 @@ import "reflect-metadata"
import { RequestHandler, Router } from "express" import { RequestHandler, Router } from "express"
import { Cart, Order, Swap } from "../../../../" import { Cart, Order, Swap } from "../../../../"
import { DeleteResponse, FindParams } from "../../../../types/common" import { FindParams } from "../../../../types/common"
import middlewares, { import middlewares, {
transformBody, transformBody,
transformQuery, transformQuery,
@@ -160,6 +160,8 @@ export const defaultStoreCartRelations = [
/** /**
* @schema StoreCartsRes * @schema StoreCartsRes
* type: object * type: object
* required:
* - cart
* properties: * properties:
* cart: * cart:
* $ref: "#/components/schemas/Cart" * $ref: "#/components/schemas/Cart"
@@ -171,6 +173,9 @@ export type StoreCartsRes = {
/** /**
* @schema StoreCompleteCartRes * @schema StoreCompleteCartRes
* type: object * type: object
* required:
* - type
* - data
* properties: * properties:
* type: * type:
* type: string * type: string
@@ -207,8 +212,6 @@ export type StoreCompleteCartRes =
data: Swap data: Swap
} }
export type StoreCartsDeleteRes = DeleteResponse
export * from "./add-shipping-method" export * from "./add-shipping-method"
export * from "./create-cart" export * from "./create-cart"
export * from "./create-line-item" export * from "./create-line-item"
@@ -37,6 +37,11 @@ export const allowedFields = [
/** /**
* @schema StoreCollectionsListRes * @schema StoreCollectionsListRes
* type: object * type: object
* required:
* - collections
* - count
* - offset
* - limit
* properties: * properties:
* collections: * collections:
* type: array * type: array
@@ -59,6 +64,8 @@ export type StoreCollectionsListRes = PaginatedResponse & {
/** /**
* @schema StoreCollectionsRes * @schema StoreCollectionsRes
* type: object * type: object
* required:
* - collection
* properties: * properties:
* collection: * collection:
* $ref: "#/components/schemas/ProductCollection" * $ref: "#/components/schemas/ProductCollection"
@@ -114,6 +114,8 @@ export const allowedStoreCustomersFields = [
/** /**
* @schema StoreCustomersRes * @schema StoreCustomersRes
* type: object * type: object
* required:
* - customer
* properties: * properties:
* customer: * customer:
* $ref: "#/components/schemas/Customer" * $ref: "#/components/schemas/Customer"
@@ -125,20 +127,25 @@ export type StoreCustomersRes = {
/** /**
* @schema StoreCustomersListOrdersRes * @schema StoreCustomersListOrdersRes
* type: object * type: object
* required:
* - orders
* - count
* - offset
* - limit
* properties: * properties:
* orders: * orders:
* type: array * type: array
* items: * items:
* $ref: "#/components/schemas/Order" * $ref: "#/components/schemas/Order"
* count: * count:
* type: integer
* description: The total number of items available * description: The total number of items available
* type: integer
* offset: * offset:
* type: integer
* description: The number of items skipped before these items * description: The number of items skipped before these items
* limit:
* type: integer * type: integer
* limit:
* description: The number of items per page * description: The number of items per page
* type: integer
*/ */
export type StoreCustomersListOrdersRes = PaginatedResponse & { export type StoreCustomersListOrdersRes = PaginatedResponse & {
orders: Order[] orders: Order[]
@@ -147,18 +154,23 @@ export type StoreCustomersListOrdersRes = PaginatedResponse & {
/** /**
* @schema StoreCustomersListPaymentMethodsRes * @schema StoreCustomersListPaymentMethodsRes
* type: object * type: object
* required:
* - payment_methods
* properties: * properties:
* payment_methods: * payment_methods:
* type: array * type: array
* items: * items:
* type: object * type: object
* required:
* - provider_id
* - data
* properties: * properties:
* provider_id: * provider_id:
* type: string
* description: The id of the Payment Provider where the payment method is saved. * description: The id of the Payment Provider where the payment method is saved.
* type: string
* data: * data:
* type: object
* description: The data needed for the Payment Provider to use the saved payment method. * description: The data needed for the Payment Provider to use the saved payment method.
* type: object
*/ */
export type StoreCustomersListPaymentMethodsRes = { export type StoreCustomersListPaymentMethodsRes = {
payment_methods: { payment_methods: {
@@ -28,6 +28,8 @@ export const allowedStoreGiftCardFields = ["id", "code", "value", "balance"]
/** /**
* @schema StoreGiftCardsRes * @schema StoreGiftCardsRes
* type: object * type: object
* required:
* - gift_card
* properties: * properties:
* gift_card: * gift_card:
* $ref: "#/components/schemas/GiftCard" * $ref: "#/components/schemas/GiftCard"
@@ -44,6 +44,8 @@ export default (app) => {
/** /**
* @schema StoreOrderEditsRes * @schema StoreOrderEditsRes
* type: object * type: object
* required:
* - order_edit
* properties: * properties:
* order_edit: * order_edit:
* $ref: "#/components/schemas/OrderEdit" * $ref: "#/components/schemas/OrderEdit"
@@ -129,6 +129,8 @@ export const allowedStoreOrdersFields = [
/** /**
* @schema StoreOrdersRes * @schema StoreOrdersRes
* type: object * type: object
* required:
* - order
* properties: * properties:
* order: * order:
* $ref: "#/components/schemas/Order" * $ref: "#/components/schemas/Order"
@@ -74,6 +74,8 @@ export const defaultPaymentCollectionRelations = ["region", "payment_sessions"]
/** /**
* @schema StorePaymentCollectionsRes * @schema StorePaymentCollectionsRes
* type: object * type: object
* required:
* - payment_collection
* properties: * properties:
* payment_collection: * payment_collection:
* $ref: "#/components/schemas/PaymentCollection" * $ref: "#/components/schemas/PaymentCollection"
@@ -85,6 +87,8 @@ export type StorePaymentCollectionsRes = {
/** /**
* @schema StorePaymentCollectionsSessionRes * @schema StorePaymentCollectionsSessionRes
* type: object * type: object
* required:
* - payment_session
* properties: * properties:
* payment_session: * payment_session:
* $ref: "#/components/schemas/PaymentSession" * $ref: "#/components/schemas/PaymentSession"
@@ -72,6 +72,8 @@ export const allowedStoreProductCategoryFields = [
/** /**
* @schema StoreGetProductCategoriesCategoryRes * @schema StoreGetProductCategoriesCategoryRes
* type: object * type: object
* required:
* - product_category
* properties: * properties:
* product_category: * product_category:
* $ref: "#/components/schemas/ProductCategory" * $ref: "#/components/schemas/ProductCategory"
@@ -83,6 +85,11 @@ export type StoreGetProductCategoriesCategoryRes = {
/** /**
* @schema StoreProductCategoriesListRes * @schema StoreProductCategoriesListRes
* type: object * type: object
* required:
* - product_categories
* - count
* - offset
* - limit
* properties: * properties:
* product_categories: * product_categories:
* type: array * type: array
@@ -34,6 +34,29 @@ export const allowedStoreProductTagFields = [...defaultStoreProductTagFields]
export const defaultStoreProductTagRelations = [] export const defaultStoreProductTagRelations = []
/**
* @schema StoreProductTagsListRes
* type: object
* required:
* - product_tags
* - count
* - offset
* - limit
* properties:
* product_tags:
* type: array
* items:
* $ref: "#/components/schemas/ProductTag"
* 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 StoreProductTagsListRes = PaginatedResponse & { export type StoreProductTagsListRes = PaginatedResponse & {
product_tags: ProductTag[] product_tags: ProductTag[]
} }
@@ -15,6 +15,9 @@ import { IsType } from "../../../../utils/validators/is-type"
* summary: "List Product Tags" * summary: "List Product Tags"
* description: "Retrieve a list of Product Tags." * description: "Retrieve a list of Product Tags."
* x-authenticated: true * x-authenticated: true
* x-codegen:
* method: list
* queryParams: StoreGetProductTagsParams
* parameters: * parameters:
* - (query) limit=20 {integer} The number of types to return. * - (query) limit=20 {integer} The number of types to return.
* - (query) offset=0 {integer} The number of items to skip before the results. * - (query) offset=0 {integer} The number of items to skip before the results.
@@ -105,19 +108,7 @@ import { IsType } from "../../../../utils/validators/is-type"
* content: * content:
* application/json: * application/json:
* schema: * schema:
* type: object * $ref: "#/components/schemas/StoreProductTagsListRes"
* properties:
* product_tags:
* $ref: "#/components/schemas/ProductTag"
* 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":
@@ -42,6 +42,11 @@ export const defaultStoreProductTypeRelations = []
/** /**
* @schema StoreProductTypesListRes * @schema StoreProductTypesListRes
* type: object * type: object
* required:
* - product_types
* - count
* - offset
* - limit
* properties: * properties:
* product_types: * product_types:
* type: array * type: array
@@ -113,6 +113,8 @@ export * from "./search"
/** /**
* @schema StoreProductsRes * @schema StoreProductsRes
* type: object * type: object
* required:
* - product
* properties: * properties:
* product: * product:
* $ref: "#/components/schemas/PricedProduct" * $ref: "#/components/schemas/PricedProduct"
@@ -123,20 +125,28 @@ export type StoreProductsRes = {
/** /**
* @schema StorePostSearchRes * @schema StorePostSearchRes
* type: object * allOf:
* - type: object
* required:
* - hits
* properties: * properties:
* hits: * hits:
* type: array
* description: Array of results. The format of the items depends on the search engine installed on the server. * description: Array of results. The format of the items depends on the search engine installed on the server.
* type: array
* - type: object
*/ */
export type StorePostSearchRes = { export type StorePostSearchRes = {
hits: unknown[] hits: unknown[]
[k: string]: unknown } & Record<string, unknown>
}
/** /**
* @schema StoreProductsListRes * @schema StoreProductsListRes
* type: object * type: object
* required:
* - products
* - count
* - offset
* - limit
* properties: * properties:
* products: * products:
* type: array * type: array
@@ -16,6 +16,8 @@ export default (app) => {
/** /**
* @schema StoreRegionsListRes * @schema StoreRegionsListRes
* type: object * type: object
* required:
* - regions
* properties: * properties:
* regions: * regions:
* type: array * type: array
@@ -29,6 +31,8 @@ export type StoreRegionsListRes = {
/** /**
* @schema StoreRegionsRes * @schema StoreRegionsRes
* type: object * type: object
* required:
* - region
* properties: * properties:
* region: * region:
* $ref: "#/components/schemas/Region" * $ref: "#/components/schemas/Region"
@@ -39,6 +39,8 @@ export const defaultStoreReturnReasonRelations: (keyof ReturnReason)[] = [
/** /**
* @schema StoreReturnReasonsListRes * @schema StoreReturnReasonsListRes
* type: object * type: object
* required:
* - return_reasons
* properties: * properties:
* return_reasons: * return_reasons:
* type: array * type: array
@@ -52,6 +54,8 @@ export type StoreReturnReasonsListRes = {
/** /**
* @schema StoreReturnReasonsRes * @schema StoreReturnReasonsRes
* type: object * type: object
* required:
* - return_reason
* properties: * properties:
* return_reason: * return_reason:
* $ref: "#/components/schemas/ReturnReason" * $ref: "#/components/schemas/ReturnReason"
@@ -15,6 +15,8 @@ export default (app) => {
/** /**
* @schema StoreReturnsRes * @schema StoreReturnsRes
* type: object * type: object
* required:
* - return
* properties: * properties:
* return: * return:
* $ref: "#/components/schemas/Return" * $ref: "#/components/schemas/Return"
@@ -19,6 +19,8 @@ export default (app) => {
/** /**
* @schema StoreShippingOptionsListRes * @schema StoreShippingOptionsListRes
* type: object * type: object
* required:
* - shipping_options
* properties: * properties:
* shipping_options: * shipping_options:
* type: array * type: array
@@ -49,6 +49,8 @@ export const defaultStoreSwapFields: FindConfig<Swap>["select"] = [
/** /**
* @schema StoreSwapsRes * @schema StoreSwapsRes
* type: object * type: object
* required:
* - swap
* properties: * properties:
* swap: * swap:
* $ref: "#/components/schemas/Swap" * $ref: "#/components/schemas/Swap"
@@ -32,6 +32,8 @@ export const defaultStoreVariantRelations = ["prices", "options", "product"]
/** /**
* @schema StoreVariantsRes * @schema StoreVariantsRes
* type: object * type: object
* required:
* - variant
* properties: * properties:
* variant: * variant:
* $ref: "#/components/schemas/PricedVariant" * $ref: "#/components/schemas/PricedVariant"
@@ -43,6 +45,8 @@ export type StoreVariantsRes = {
/** /**
* @schema StoreVariantsListRes * @schema StoreVariantsListRes
* type: object * type: object
* required:
* - variants
* properties: * properties:
* variants: * variants:
* type: array * type: array