chore(oas): [8/n] improve oas schemas (#9163)

Improve OAS schemas [8/n]
This commit is contained in:
Shahed Nasser
2024-09-17 17:26:41 +00:00
committed by GitHub
parent cda5bbac78
commit 78eaed70e5
20 changed files with 95 additions and 85 deletions
@@ -1,20 +1,20 @@
/** /**
* @schema AdminPostExchangesShippingActionReqSchema * @schema AdminPostExchangesShippingActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The details of the shipping method to update.
* x-schemaName: AdminPostExchangesShippingActionReqSchema * x-schemaName: AdminPostExchangesShippingActionReqSchema
* properties: * properties:
* custom_amount: * custom_amount:
* type: number * type: number
* title: custom_amount * title: custom_amount
* description: The exchange's custom amount. * description: The shipping method's custom amount.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The exchange's internal note. * description: A note viewed by admin users only.
* metadata: * metadata:
* type: object * type: object
* description: The exchange's metadata. * description: The exchange's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostExchangesShippingReqSchema * @schema AdminPostExchangesShippingReqSchema
* type: object * type: object
* description: SUMMARY * description: The outbound shipping method's details.
* x-schemaName: AdminPostExchangesShippingReqSchema * x-schemaName: AdminPostExchangesShippingReqSchema
* required: * required:
* - shipping_option_id * - shipping_option_id
@@ -9,22 +9,22 @@
* shipping_option_id: * shipping_option_id:
* type: string * type: string
* title: shipping_option_id * title: shipping_option_id
* description: The exchange's shipping option id. * description: The ID of the associated shipping option.
* custom_amount: * custom_amount:
* type: number * type: number
* title: custom_amount * title: custom_amount
* description: The exchange's custom amount. * description: Set a custom amount for the shipping method.
* description: * description:
* type: string * type: string
* title: description * title: description
* description: The exchange's description. * description: The shipping method's description.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The exchange's internal note. * description: A note viewed by admin users only.
* metadata: * metadata:
* type: object * type: object
* description: The exchange's metadata. * description: The exchange's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostOrderClaimsReqSchema * @schema AdminPostOrderClaimsReqSchema
* type: object * type: object
* description: SUMMARY * description: The claim's details.
* x-schemaName: AdminPostOrderClaimsReqSchema * x-schemaName: AdminPostOrderClaimsReqSchema
* required: * required:
* - type * - type
@@ -16,7 +16,7 @@
* order_id: * order_id:
* type: string * type: string
* title: order_id * title: order_id
* description: The claim's order id. * description: The ID of the order the claim is created for.
* description: * description:
* type: string * type: string
* title: description * title: description
@@ -24,14 +24,14 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The claim's internal note. * description: A note viewed only by admin users.
* reason_id: * reason_id:
* type: string * type: string
* title: reason_id * title: reason_id
* description: The claim's reason id. * description: The ID of the associated return reason.
* metadata: * metadata:
* type: object * type: object
* description: The claim's metadata. * description: The claim's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,15 +1,15 @@
/** /**
* @schema AdminPostOrderEditsAddItemsReqSchema * @schema AdminPostOrderEditsAddItemsReqSchema
* type: object * type: object
* description: SUMMARY * description: The details of items to be edited.
* x-schemaName: AdminPostOrderEditsAddItemsReqSchema * x-schemaName: AdminPostOrderEditsAddItemsReqSchema
* properties: * properties:
* items: * items:
* type: array * type: array
* description: The order edit's items. * description: The details of items to be edited.
* items: * items:
* type: object * type: object
* description: The item's items. * description: An item's details.
* required: * required:
* - variant_id * - variant_id
* - quantity * - quantity
@@ -17,7 +17,7 @@
* variant_id: * variant_id:
* type: string * type: string
* title: variant_id * title: variant_id
* description: The item's variant id. * description: The ID of the associated product variant.
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
@@ -29,14 +29,14 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The item's internal note. * description: A note viewed only by admin users.
* allow_backorder: * allow_backorder:
* type: boolean * type: boolean
* title: allow_backorder * title: allow_backorder
* description: The item's allow backorder. * description: Whether the item can be added even if there's no available invenotory quantity of the variant.
* metadata: * metadata:
* type: object * type: object
* description: The item's metadata. * description: The item's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,17 +1,17 @@
/** /**
* @schema AdminPostOrderEditsItemsActionReqSchema * @schema AdminPostOrderEditsItemsActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The details to update in the item.
* x-schemaName: AdminPostOrderEditsItemsActionReqSchema * x-schemaName: AdminPostOrderEditsItemsActionReqSchema
* properties: * properties:
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The order edit's quantity. * description: The item's quantity.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The order edit's internal note. * description: A note viewed only by admin users.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostOrderEditsReqSchema * @schema AdminPostOrderEditsReqSchema
* type: object * type: object
* description: SUMMARY * description: The order edit's details.
* x-schemaName: AdminPostOrderEditsReqSchema * x-schemaName: AdminPostOrderEditsReqSchema
* required: * required:
* - order_id * - order_id
@@ -9,7 +9,7 @@
* order_id: * order_id:
* type: string * type: string
* title: order_id * title: order_id
* description: The order edit's order id. * description: The ID of the order this edit is for.
* description: * description:
* type: string * type: string
* title: description * title: description
@@ -17,10 +17,10 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The order edit's internal note. * description: A note viewed only by admin users.
* metadata: * metadata:
* type: object * type: object
* description: The order edit's metadata. * description: The order edit's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,20 +1,20 @@
/** /**
* @schema AdminPostOrderEditsShippingActionReqSchema * @schema AdminPostOrderEditsShippingActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The shipping method's details.
* x-schemaName: AdminPostOrderEditsShippingActionReqSchema * x-schemaName: AdminPostOrderEditsShippingActionReqSchema
* properties: * properties:
* custom_amount: * custom_amount:
* type: number * type: number
* title: custom_amount * title: custom_amount
* description: The order edit's custom amount. * description: Set a custom price for the shipping method.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The order edit's internal note. * description: A note viewed only by admin users.
* metadata: * metadata:
* type: object * type: object
* description: The order edit's metadata. * description: The order edit's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostOrderEditsShippingReqSchema * @schema AdminPostOrderEditsShippingReqSchema
* type: object * type: object
* description: SUMMARY * description: The shipping method's details.
* x-schemaName: AdminPostOrderEditsShippingReqSchema * x-schemaName: AdminPostOrderEditsShippingReqSchema
* required: * required:
* - shipping_option_id * - shipping_option_id
@@ -9,22 +9,22 @@
* shipping_option_id: * shipping_option_id:
* type: string * type: string
* title: shipping_option_id * title: shipping_option_id
* description: The order edit's shipping option id. * description: The ID of the associated shipping option.
* custom_amount: * custom_amount:
* type: number * type: number
* title: custom_amount * title: custom_amount
* description: The order edit's custom amount. * description: Set a custom price for the shipping method.
* description: * description:
* type: string * type: string
* title: description * title: description
* description: The order edit's description. * description: The shipping method's description.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The order edit's internal note. * description: A note viewed only by admin users.
* metadata: * metadata:
* type: object * type: object
* description: The order edit's metadata. * description: The shipping method's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostOrderEditsUpdateItemQuantityReqSchema * @schema AdminPostOrderEditsUpdateItemQuantityReqSchema
* type: object * type: object
* description: SUMMARY * description: The order item's details to update.
* x-schemaName: AdminPostOrderEditsUpdateItemQuantityReqSchema * x-schemaName: AdminPostOrderEditsUpdateItemQuantityReqSchema
* required: * required:
* - quantity * - quantity
@@ -9,11 +9,11 @@
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The order edit's quantity. * description: The item's quantity.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The order edit's internal note. * description: A note viewed only by admin users.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostOrderExchangesReqSchema * @schema AdminPostOrderExchangesReqSchema
* type: object * type: object
* description: SUMMARY * description: The exchange's details.
* x-schemaName: AdminPostOrderExchangesReqSchema * x-schemaName: AdminPostOrderExchangesReqSchema
* required: * required:
* - order_id * - order_id
@@ -9,7 +9,7 @@
* order_id: * order_id:
* type: string * type: string
* title: order_id * title: order_id
* description: The exchange's order id. * description: The ID of the order this exchange is created for.
* description: * description:
* type: string * type: string
* title: description * title: description
@@ -17,10 +17,10 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The exchange's internal note. * description: A note viewed only by admin users.
* metadata: * metadata:
* type: object * type: object
* description: The exchange's metadata. * description: The exchange's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,20 +1,20 @@
/** /**
* @schema AdminPostReceiveReturnsReqSchema * @schema AdminPostReceiveReturnsReqSchema
* type: object * type: object
* description: SUMMARY * description: The return receival details.
* x-schemaName: AdminPostReceiveReturnsReqSchema * x-schemaName: AdminPostReceiveReturnsReqSchema
* properties: * properties:
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The return's internal note. * description: A note viewed only by admin users.
* description: * description:
* type: string * type: string
* title: description * title: description
* description: The return's description. * description: The return's description.
* metadata: * metadata:
* type: object * type: object
* description: The return's metadata. * description: The return's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,13 +1,13 @@
/** /**
* @schema AdminPostReturnsConfirmRequestReqSchema * @schema AdminPostReturnsConfirmRequestReqSchema
* type: object * type: object
* description: SUMMARY * description: The confirmation's details.
* x-schemaName: AdminPostReturnsConfirmRequestReqSchema * x-schemaName: AdminPostReturnsConfirmRequestReqSchema
* properties: * properties:
* no_notification: * no_notification:
* type: boolean * type: boolean
* title: no_notification * title: no_notification
* description: The return's no notification. * description: Whether to send the customer a notification about the confirmation.
* *
*/ */
@@ -1,17 +1,17 @@
/** /**
* @schema AdminPostReturnsDismissItemsActionReqSchema * @schema AdminPostReturnsDismissItemsActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The details to update of the damaged item.
* x-schemaName: AdminPostReturnsDismissItemsActionReqSchema * x-schemaName: AdminPostReturnsDismissItemsActionReqSchema
* properties: * properties:
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The return's quantity. * description: The item's quantity.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The return's internal note. * description: A note viewed only by admin users.
* *
*/ */
@@ -1,17 +1,17 @@
/** /**
* @schema AdminPostReturnsReceiveItemsActionReqSchema * @schema AdminPostReturnsReceiveItemsActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The details of the received item.
* x-schemaName: AdminPostReturnsReceiveItemsActionReqSchema * x-schemaName: AdminPostReturnsReceiveItemsActionReqSchema
* properties: * properties:
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The return's quantity. * description: The item's quantity.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The return's internal note. * description: A note viewed only by admin users.
* *
*/ */
@@ -1,15 +1,15 @@
/** /**
* @schema AdminPostReturnsReceiveItemsReqSchema * @schema AdminPostReturnsReceiveItemsReqSchema
* type: object * type: object
* description: SUMMARY * description: The items details.
* x-schemaName: AdminPostReturnsReceiveItemsReqSchema * x-schemaName: AdminPostReturnsReceiveItemsReqSchema
* properties: * properties:
* items: * items:
* type: array * type: array
* description: The return's items. * description: The items details.
* items: * items:
* type: object * type: object
* description: The item's items. * description: An item's details.
* required: * required:
* - id * - id
* - quantity * - quantity
@@ -17,7 +17,7 @@
* id: * id:
* type: string * type: string
* title: id * title: id
* description: The item's ID. * description: The ID of the item in the order.
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
@@ -29,7 +29,7 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The item's internal note. * description: A note viewed only by admin users.
* *
*/ */
@@ -1,7 +1,7 @@
/** /**
* @schema AdminPostReturnsReqSchema * @schema AdminPostReturnsReqSchema
* type: object * type: object
* description: SUMMARY * description: The return's details.
* x-schemaName: AdminPostReturnsReqSchema * x-schemaName: AdminPostReturnsReqSchema
* required: * required:
* - order_id * - order_id
@@ -9,11 +9,11 @@
* order_id: * order_id:
* type: string * type: string
* title: order_id * title: order_id
* description: The return's order id. * description: The ID of the order the return belongs to.
* location_id: * location_id:
* type: string * type: string
* title: location_id * title: location_id
* description: The return's location id. * description: The ID of the location the items are returned to.
* description: * description:
* type: string * type: string
* title: description * title: description
@@ -21,14 +21,14 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The return's internal note. * description: A note viewed only by admin users.
* no_notification: * no_notification:
* type: boolean * type: boolean
* title: no_notification * title: no_notification
* description: The return's no notification. * description: Whether to send the customer a notification about the created return.
* metadata: * metadata:
* type: object * type: object
* description: The return's metadata. * description: The return's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,24 +1,24 @@
/** /**
* @schema AdminPostReturnsRequestItemsActionReqSchema * @schema AdminPostReturnsRequestItemsActionReqSchema
* type: object * type: object
* description: SUMMARY * description: The details to update in the item.
* x-schemaName: AdminPostReturnsRequestItemsActionReqSchema * x-schemaName: AdminPostReturnsRequestItemsActionReqSchema
* properties: * properties:
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The claim's quantity. * description: The item's quantity.
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The claim's internal note. * description: A note viewed only by admin users.
* reason_id: * reason_id:
* type: string * type: string
* title: reason_id * title: reason_id
* description: The claim's reason id. * description: The ID of the associated return reason.
* metadata: * metadata:
* type: object * type: object
* description: The claim's metadata. * description: The claim's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -1,15 +1,15 @@
/** /**
* @schema AdminPostReturnsRequestItemsReqSchema * @schema AdminPostReturnsRequestItemsReqSchema
* type: object * type: object
* description: SUMMARY * description: The items' details.
* x-schemaName: AdminPostReturnsRequestItemsReqSchema * x-schemaName: AdminPostReturnsRequestItemsReqSchema
* properties: * properties:
* items: * items:
* type: array * type: array
* description: The claim's items. * description: The items' details.
* items: * items:
* type: object * type: object
* description: The item's items. * description: An item's details.
* required: * required:
* - id * - id
* - quantity * - quantity
@@ -29,14 +29,14 @@
* internal_note: * internal_note:
* type: string * type: string
* title: internal_note * title: internal_note
* description: The item's internal note. * description: A note viewed only by admin users.
* reason_id: * reason_id:
* type: string * type: string
* title: reason_id * title: reason_id
* description: The item's reason id. * description: The ID of the associated return reason.
* metadata: * metadata:
* type: object * type: object
* description: The item's metadata. * description: The item's metadata, can hold custom key-value pairs.
* *
*/ */
@@ -31,6 +31,12 @@ class SchemaFactory {
BigNumber: { BigNumber: {
type: "string", type: "string",
}, },
IBigNumber: {
type: "number",
},
BigNumberValue: {
type: "number",
},
} }
/** /**
* Schemas used only for response types. * Schemas used only for response types.
@@ -60,7 +66,7 @@ class SchemaFactory {
public tryGetSchema( public tryGetSchema(
name: string, name: string,
additionalData?: Partial<OpenApiSchema>, additionalData?: Partial<OpenApiSchema>,
type: "request" | "response" | "all" = "all" type: "request" | "query" | "response" | "all" = "all"
): OpenApiSchema | undefined { ): OpenApiSchema | undefined {
const schemasFactory = const schemasFactory =
type === "response" type === "response"
@@ -1047,7 +1047,7 @@ class OasKindGenerator extends FunctionKindGenerator {
itemType: propertyType, itemType: propertyType,
title: propertyName, title: propertyName,
descriptionOptions, descriptionOptions,
context: "request", context: "query",
saveSchema: !forUpdate, saveSchema: !forUpdate,
}), }),
}) })
@@ -1063,6 +1063,7 @@ class OasKindGenerator extends FunctionKindGenerator {
typeReferenceNode: node.parameters[0].type, typeReferenceNode: node.parameters[0].type,
itemType: requestTypeArguments[0], itemType: requestTypeArguments[0],
}) })
const isQuery = methodName === "get"
const parameterSchema = this.typeToSchema({ const parameterSchema = this.typeToSchema({
itemType: requestTypeArguments[0], itemType: requestTypeArguments[0],
descriptionOptions: { descriptionOptions: {
@@ -1070,13 +1071,13 @@ class OasKindGenerator extends FunctionKindGenerator {
rawParentName: this.checker.typeToString(requestTypeArguments[0]), rawParentName: this.checker.typeToString(requestTypeArguments[0]),
}, },
zodObjectTypeName: zodObjectTypeName, zodObjectTypeName: zodObjectTypeName,
context: "request", context: isQuery ? "query" : "request",
saveSchema: !forUpdate, saveSchema: !forUpdate,
}) })
// If function is a GET function, add the type parameter to the // If function is a GET function, add the type parameter to the
// query parameters instead of request parameters. // query parameters instead of request parameters.
if (methodName === "get") { if (isQuery) {
if (parameterSchema.type === "object" && parameterSchema.properties) { if (parameterSchema.type === "object" && parameterSchema.properties) {
Object.entries(parameterSchema.properties).forEach( Object.entries(parameterSchema.properties).forEach(
([key, propertySchema]) => { ([key, propertySchema]) => {
@@ -1244,7 +1245,7 @@ class OasKindGenerator extends FunctionKindGenerator {
/** /**
* Whether the type is in a request / response * Whether the type is in a request / response
*/ */
context?: "request" | "response" context?: "request" | "response" | "query"
/** /**
* Whether to save object schemas. Useful when only getting schemas to update. * Whether to save object schemas. Useful when only getting schemas to update.
*/ */
@@ -1550,6 +1551,7 @@ class OasKindGenerator extends FunctionKindGenerator {
// if property's type is same as parent's property, // if property's type is same as parent's property,
// create a reference to the parent // create a reference to the parent
const arrHasParentType = const arrHasParentType =
rest.context !== "query" &&
this.checker.isArrayType(propertyType) && this.checker.isArrayType(propertyType) &&
this.areTypesEqual( this.areTypesEqual(
itemType, itemType,
@@ -1557,7 +1559,9 @@ class OasKindGenerator extends FunctionKindGenerator {
propertyType as ts.TypeReference propertyType as ts.TypeReference
)[0] )[0]
) )
const isParentType = this.areTypesEqual(itemType, propertyType) const isParentType =
rest.context !== "query" &&
this.areTypesEqual(itemType, propertyType)
if (isParentType && objSchema["x-schemaName"]) { if (isParentType && objSchema["x-schemaName"]) {
properties[property.name] = { properties[property.name] = {