chore(oas): [16/n] improve oas schemas (#9272)

- Improve OAS schemas [16/n]
- fixes and improvements to docs-generator tool
This commit is contained in:
Shahed Nasser
2024-09-26 16:02:32 +03:00
committed by GitHub
parent ea2cc974cc
commit d352ea8122
20 changed files with 1324 additions and 130 deletions

View File

@@ -0,0 +1,154 @@
/**
* @schema AdminOrderChange
* type: object
* description: The order preview's order change.
* x-schemaName: AdminOrderChange
* required:
* - order
* - claim
* - return
* - exchange
* - id
* - version
* - order_id
* - return_id
* - exchange_id
* - claim_id
* - return_order
* - actions
* - status
* - requested_by
* - requested_at
* - confirmed_by
* - confirmed_at
* - declined_by
* - declined_reason
* - metadata
* - declined_at
* - canceled_by
* - canceled_at
* - created_at
* - updated_at
* properties:
* id:
* type: string
* title: id
* description: The order change's ID.
* order_id:
* type: string
* title: order_id
* description: The order change's order id.
* actions:
* type: array
* description: The order change's actions.
* items:
* $ref: "#/components/schemas/BaseOrderChangeAction"
* status:
* type: string
* title: status
* description: The order change's status.
* requested_by:
* type: string
* title: requested_by
* description: The order change's requested by.
* requested_at:
* oneOf:
* - type: string
* title: requested_at
* description: The order change's requested at.
* - type: string
* title: requested_at
* description: The order change's requested at.
* format: date-time
* confirmed_by:
* type: string
* title: confirmed_by
* description: The order change's confirmed by.
* confirmed_at:
* oneOf:
* - type: string
* title: confirmed_at
* description: The order change's confirmed at.
* - type: string
* title: confirmed_at
* description: The order change's confirmed at.
* format: date-time
* declined_by:
* type: string
* title: declined_by
* description: The order change's declined by.
* declined_reason:
* type: string
* title: declined_reason
* description: The order change's declined reason.
* metadata:
* type: object
* description: The order change's metadata.
* declined_at:
* oneOf:
* - type: string
* title: declined_at
* description: The order change's declined at.
* - type: string
* title: declined_at
* description: The order change's declined at.
* format: date-time
* canceled_by:
* type: string
* title: canceled_by
* description: The order change's canceled by.
* canceled_at:
* oneOf:
* - type: string
* title: canceled_at
* description: The order change's canceled at.
* - type: string
* title: canceled_at
* description: The order change's canceled at.
* format: date-time
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The order change's created at.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The order change's updated at.
* version:
* type: number
* title: version
* description: The order change's version.
* change_type:
* type: string
* description: The order change's change type.
* enum:
* - return
* - exchange
* - claim
* - edit
* - return_request
* return_id:
* type: string
* title: return_id
* description: The order change's return id.
* exchange_id:
* type: string
* title: exchange_id
* description: The order change's exchange id.
* claim_id:
* type: string
* title: claim_id
* description: The order change's claim id.
* order:
* $ref: "#/components/schemas/AdminOrder"
* return_order:
* $ref: "#/components/schemas/AdminReturn"
* exchange:
* $ref: "#/components/schemas/AdminExchange"
* claim:
* $ref: "#/components/schemas/AdminClaim"
*
*/

View File

@@ -0,0 +1,90 @@
/**
* @schema AdminOrderChangeAction
* type: object
* description: The action's details.
* x-schemaName: AdminOrderChangeAction
* properties:
* order_change:
* $ref: "#/components/schemas/AdminOrderChange"
* id:
* type: string
* title: id
* description: The action's ID.
* order_change_id:
* type: string
* title: order_change_id
* description: The ID of the order change this action belongs to.
* order_id:
* type: string
* title: order_id
* description: The ID of the associated order.
* reference:
* type: string
* title: reference
* description: The name of the table this action applies on.
* enum:
* - claim
* - exchange
* - return
* - order_shipping_method
* reference_id:
* type: string
* title: reference_id
* description: The ID of the record in the referenced table.
* action:
* type: string
* title: action
* description: The applied action.
* details:
* type: object
* description: The action's details.
* example:
* reference_id: 123
* quantity: 1
* internal_note:
* type: string
* title: internal_note
* description: A note viewed only by admin users.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the order change action was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the order change action was updated.
* return_id:
* type: string
* title: return_id
* description: The ID of the associated return.
* claim_id:
* type: string
* title: claim_id
* description: The ID of the associated claim.
* exchange_id:
* type: string
* title: exchange_id
* description: The ID of the associated exchange.
* order:
* $ref: "#/components/schemas/BaseOrder"
* required:
* - order_change
* - id
* - order_change_id
* - order_id
* - reference
* - reference_id
* - action
* - details
* - internal_note
* - created_at
* - updated_at
* - return_id
* - claim_id
* - exchange_id
* - order
*
*/

View File

@@ -0,0 +1,76 @@
/**
* @schema AdminOrderFulfillment
* type: object
* description: The fulfillment's details.
* x-schemaName: AdminOrderFulfillment
* required:
* - id
* - location_id
* - packed_at
* - shipped_at
* - delivered_at
* - canceled_at
* - data
* - provider_id
* - shipping_option_id
* - metadata
* - created_at
* - updated_at
* properties:
* id:
* type: string
* title: id
* description: The fulfillment's ID.
* location_id:
* type: string
* title: location_id
* description: The ID of the location the items are fulfilled from.
* packed_at:
* type: string
* title: packed_at
* description: The date the items were packed.
* format: date-time
* shipped_at:
* type: string
* title: shipped_at
* description: The date the items were shipped.
* format: date-time
* delivered_at:
* type: string
* title: delivered_at
* description: The date the items were delivered.
* format: date-time
* canceled_at:
* type: string
* title: canceled_at
* description: The date the items were canceled.
* format: date-time
* data:
* type: object
* description: Data useful for the fulfillment provider handling it. This is taken from the associated shipping option.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/fulfillment/shipping-option#data-property
* provider_id:
* type: string
* title: provider_id
* description: The ID of the fulfillment provider used to handle the fulfillment.
* shipping_option_id:
* type: string
* title: shipping_option_id
* description: The ID of the associated shipping option.
* metadata:
* type: object
* description: The fulfillment's metadata, can hold custom key-value pairs.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the fulfillment was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the fulfillment was updated.
*
*/

View File

@@ -0,0 +1,218 @@
/**
* @schema AdminOrderLineItem
* type: object
* description: The item's details.
* x-schemaName: AdminOrderLineItem
* required:
* - id
* - title
* - subtitle
* - thumbnail
* - variant_id
* - product_id
* - product_title
* - product_description
* - product_subtitle
* - product_type
* - product_collection
* - product_handle
* - variant_sku
* - variant_barcode
* - variant_title
* - variant_option_values
* - requires_shipping
* - is_discountable
* - is_tax_inclusive
* - unit_price
* - quantity
* - detail
* - created_at
* - updated_at
* - metadata
* - original_total
* - original_subtotal
* - original_tax_total
* - item_total
* - item_subtotal
* - item_tax_total
* - total
* - subtotal
* - tax_total
* - discount_total
* - discount_tax_total
* - refundable_total
* - refundable_total_per_unit
* properties:
* id:
* type: string
* title: id
* description: The item's ID.
* title:
* type: string
* title: title
* description: The item's title.
* subtitle:
* type: string
* title: subtitle
* description: The item's subtitle.
* thumbnail:
* type: string
* title: thumbnail
* description: The URL of the item's thumbnail.
* variant:
* $ref: "#/components/schemas/AdminProductVariant"
* variant_id:
* type: string
* title: variant_id
* description: The ID of the associated variant.
* product:
* $ref: "#/components/schemas/BaseProduct"
* product_id:
* type: string
* title: product_id
* description: The ID of the associated product.
* product_title:
* type: string
* title: product_title
* description: The item's product title.
* product_description:
* type: string
* title: product_description
* description: The item's product description.
* product_subtitle:
* type: string
* title: product_subtitle
* description: The item's product subtitle.
* product_type:
* type: string
* title: product_type
* description: The item's product type.
* product_collection:
* type: string
* title: product_collection
* description: The ID of the collection the item's product belongs to.
* product_handle:
* type: string
* title: product_handle
* description: The item's product handle.
* variant_sku:
* type: string
* title: variant_sku
* description: The item's variant SKU.
* variant_barcode:
* type: string
* title: variant_barcode
* description: The item's variant barcode.
* variant_title:
* type: string
* title: variant_title
* description: The item's variant title.
* variant_option_values:
* type: object
* description: The values of the item variant's options.
* example:
* Color: Blue
* requires_shipping:
* type: boolean
* title: requires_shipping
* description: Whether the item requires shipping.
* is_discountable:
* type: boolean
* title: is_discountable
* description: Whether the item is discountable.
* is_tax_inclusive:
* type: boolean
* title: is_tax_inclusive
* description: Whether the item is tax inclusive.
* compare_at_unit_price:
* type: number
* title: compare_at_unit_price
* description: The original price of the item before a promotion or sale.
* unit_price:
* type: number
* title: unit_price
* description: The item's unit price.
* quantity:
* type: number
* title: quantity
* description: The item's quantity.
* tax_lines:
* type: array
* description: The item's tax lines.
* items:
* $ref: "#/components/schemas/BaseOrderLineItemTaxLine"
* adjustments:
* type: array
* description: The item's adjustments.
* items:
* $ref: "#/components/schemas/BaseOrderLineItemAdjustment"
* detail:
* $ref: "#/components/schemas/BaseOrderItemDetail"
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the item was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the item was updated.
* metadata:
* type: object
* description: The item's metadata, can hold custom key-value pairs.
* original_total:
* type: number
* title: original_total
* description: The item's total including taxes, excluding promotions.
* original_subtotal:
* type: number
* title: original_subtotal
* description: The item's total excluding taxes, including promotions.
* original_tax_total:
* type: number
* title: original_tax_total
* description: The total taxes of the item, excluding promotions.
* item_total:
* type: number
* title: item_total
* description: The total taxes of the item, including promotions.
* item_subtotal:
* type: number
* title: item_subtotal
* description: The item's total excluding taxes, including promotions.
* item_tax_total:
* type: number
* title: item_tax_total
* description: The total taxes of the item, including promotions.
* total:
* type: number
* title: total
* description: The item's total, including taxes and promotions.
* subtotal:
* type: number
* title: subtotal
* description: The item's subtotal excluding taxes, including promotions.
* tax_total:
* type: number
* title: tax_total
* description: The tax total of the item including promotions.
* discount_total:
* type: number
* title: discount_total
* description: The total discount amount of the item.
* discount_tax_total:
* type: number
* title: discount_tax_total
* description: The total taxes applied on the discounted amount.
* refundable_total:
* type: number
* title: refundable_total
* description: The total refundable amount of the item's total.
* refundable_total_per_unit:
* type: number
* title: refundable_total_per_unit
* description: The total refundable amount of the item's total for a single quantity.
*
*/

View File

@@ -1,7 +1,7 @@
/** /**
* @schema BaseExchangeItem * @schema BaseExchangeItem
* type: object * type: object
* description: The additional item's additional items. * description: The item's details.
* x-schemaName: BaseExchangeItem * x-schemaName: BaseExchangeItem
* required: * required:
* - id * - id
@@ -15,36 +15,36 @@
* id: * id:
* type: string * type: string
* title: id * title: id
* description: The additional item's ID. * description: The item's ID.
* exchange_id: * exchange_id:
* type: string * type: string
* title: exchange_id * title: exchange_id
* description: The additional item's exchange id. * description: The ID of the exchange this item belongs to.
* order_id: * order_id:
* type: string * type: string
* title: order_id * title: order_id
* description: The additional item's order id. * description: The ID of the order this item belongs to.
* item_id: * item_id:
* type: string * type: string
* title: item_id * title: item_id
* description: The additional item's item id. * description: The ID of the item in the order.
* quantity: * quantity:
* type: number * type: number
* title: quantity * title: quantity
* description: The additional item's quantity. * description: The item's quantity.
* metadata: * metadata:
* type: object * type: object
* description: The additional item's metadata. * description: The item's metadata, can hold custom key-value pairs.
* created_at: * created_at:
* type: string * type: string
* format: date-time * format: date-time
* title: created_at * title: created_at
* description: The additional item's created at. * description: The date the item was created.
* updated_at: * updated_at:
* type: string * type: string
* format: date-time * format: date-time
* title: updated_at * title: updated_at
* description: The additional item's updated at. * description: The date the item was updated.
* *
*/ */

View File

@@ -1,7 +1,7 @@
/** /**
* @schema BaseFulfillmentProvider * @schema BaseFulfillmentProvider
* type: object * type: object
* description: The shipping option's provider. * description: The fulfillment provider's details.
* x-schemaName: BaseFulfillmentProvider * x-schemaName: BaseFulfillmentProvider
* required: * required:
* - id * - id
@@ -14,7 +14,7 @@
* is_enabled: * is_enabled:
* type: boolean * type: boolean
* title: is_enabled * title: is_enabled
* description: The provider's is enabled. * description: Whether the provider is enabled.
* *
*/ */

View File

@@ -1,8 +1,61 @@
/** /**
* @schema BaseLineItemAdjustment * @schema BaseLineItemAdjustment
* type: object * type: object
* description: The adjustment's adjustments. * description: The adjustment's details.
* x-schemaName: BaseLineItemAdjustment * x-schemaName: BaseLineItemAdjustment
* properties:
* item:
* $ref: "#/components/schemas/BaseCartLineItem"
* item_id:
* type: string
* title: item_id
* description: The ID of the item this adjustment applies on.
* id:
* type: string
* title: id
* description: The adjustment's ID.
* code:
* type: string
* title: code
* description: The adjustment's code.
* amount:
* type: number
* title: amount
* description: The adjustment's amount.
* cart_id:
* type: string
* title: cart_id
* description: The ID of the cart this adjustment belongs to.
* description:
* type: string
* title: description
* description: The adjustment's description.
* promotion_id:
* type: string
* title: promotion_id
* description: The ID of the promotion applied by this adjustment.
* provider_id:
* type: string
* title: provider_id
* description: The adjustment's provider ID.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the adjustment was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the adjustment was updated.
* required:
* - item
* - item_id
* - id
* - amount
* - cart_id
* - created_at
* - updated_at
* *
*/ */

View File

@@ -1,8 +1,67 @@
/** /**
* @schema BaseLineItemTaxLine * @schema BaseLineItemTaxLine
* type: object * type: object
* description: The tax line's tax lines. * description: The tax line's details
* x-schemaName: BaseLineItemTaxLine * x-schemaName: BaseLineItemTaxLine
* properties:
* item:
* $ref: "#/components/schemas/BaseCartLineItem"
* item_id:
* type: string
* title: item_id
* description: The ID of the item the tax line applies on.
* total:
* type: number
* title: total
* description: The item's total, including taxes and promotions.
* subtotal:
* type: number
* title: subtotal
* description: The item's subtotal excluding taxes, including promotions.
* id:
* type: string
* title: id
* description: The tax line's ID.
* description:
* type: string
* title: description
* description: The tax line's description.
* tax_rate_id:
* type: string
* title: tax_rate_id
* description: The ID of the associated tax rate.
* code:
* type: string
* title: code
* description: The code the tax rate is identified by.
* rate:
* type: number
* title: rate
* description: The rate to charge.
* provider_id:
* type: string
* title: provider_id
* description: The ID of the tax provider.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the tax line was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the tax line was updated.
* required:
* - item
* - item_id
* - total
* - subtotal
* - id
* - code
* - rate
* - created_at
* - updated_at
* *
*/ */

View File

@@ -1,8 +1,242 @@
/** /**
* @schema BaseOrder * @schema BaseOrder
* type: object * type: object
* description: The order change's order. * description: The order's details.
* x-schemaName: BaseOrder * x-schemaName: BaseOrder
* required:
* - payment_collections
* - id
* - version
* - region_id
* - customer_id
* - sales_channel_id
* - email
* - currency_code
* - items
* - shipping_methods
* - payment_status
* - fulfillment_status
* - summary
* - metadata
* - created_at
* - updated_at
* - original_item_total
* - original_item_subtotal
* - original_item_tax_total
* - item_total
* - item_subtotal
* - item_tax_total
* - original_total
* - original_subtotal
* - original_tax_total
* - total
* - subtotal
* - tax_total
* - discount_total
* - discount_tax_total
* - gift_card_total
* - gift_card_tax_total
* - shipping_total
* - shipping_subtotal
* - shipping_tax_total
* - original_shipping_total
* - original_shipping_subtotal
* - original_shipping_tax_total
* properties:
* payment_collections:
* type: array
* description: The order's payment collections.
* items:
* $ref: "#/components/schemas/AdminPaymentCollection"
* fulfillments:
* type: array
* description: The order's fulfillments.
* items:
* $ref: "#/components/schemas/BaseOrderFulfillment"
* sales_channel:
* $ref: "#/components/schemas/AdminSalesChannel"
* customer:
* $ref: "#/components/schemas/AdminCustomer"
* shipping_address:
* $ref: "#/components/schemas/AdminOrderAddress"
* billing_address:
* $ref: "#/components/schemas/AdminOrderAddress"
* id:
* type: string
* title: id
* description: The order's ID.
* version:
* type: number
* title: version
* description: The order's version.
* region_id:
* type: string
* title: region_id
* description: The ID of the region associated with the order.
* customer_id:
* type: string
* title: customer_id
* description: The ID of the customer that placed the order.
* sales_channel_id:
* type: string
* title: sales_channel_id
* description: The ID of the sales channel the order is placed in.
* email:
* type: string
* title: email
* description: The email of the customer that placed the order.
* format: email
* currency_code:
* type: string
* title: currency_code
* description: The order's currency code.
* display_id:
* type: number
* title: display_id
* description: The order's display ID.
* items:
* type: array
* description: The order's items.
* items:
* $ref: "#/components/schemas/BaseOrderLineItem"
* shipping_methods:
* type: array
* description: The order's shipping methods.
* items:
* $ref: "#/components/schemas/BaseOrderShippingMethod"
* payment_status:
* type: string
* description: The order's payment status.
* enum:
* - canceled
* - not_paid
* - awaiting
* - authorized
* - partially_authorized
* - captured
* - partially_captured
* - partially_refunded
* - refunded
* - requires_action
* fulfillment_status:
* type: string
* description: The order's fulfillment status.
* enum:
* - canceled
* - not_fulfilled
* - partially_fulfilled
* - fulfilled
* - partially_shipped
* - shipped
* - partially_delivered
* - delivered
* transactions:
* type: array
* description: The order's transactions.
* items:
* $ref: "#/components/schemas/BaseOrderTransaction"
* summary:
* $ref: "#/components/schemas/BaseOrderSummary"
* metadata:
* type: object
* description: The order's metadata, can hold custom key-value pairs.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the order was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the order was updated.
* original_item_total:
* type: number
* title: original_item_total
* description: The total of the order's items including taxes, excluding promotions.
* original_item_subtotal:
* type: number
* title: original_item_subtotal
* description: The total of the order's items excluding taxes, including promotions.
* original_item_tax_total:
* type: number
* title: original_item_tax_total
* description: The tax total of the order's items excluding promotions.
* item_total:
* type: number
* title: item_total
* description: The total of the order's items including taxes and promotions.
* item_subtotal:
* type: number
* title: item_subtotal
* description: The total of the order's items excluding taxes, including promotions.
* item_tax_total:
* type: number
* title: item_tax_total
* description: The tax total of the order's items including promotions.
* original_total:
* type: number
* title: original_total
* description: The order's total excluding promotions, including taxes.
* original_subtotal:
* type: number
* title: original_subtotal
* description: The order's total excluding taxes, including promotions.
* original_tax_total:
* type: number
* title: original_tax_total
* description: The order's tax total, excluding promotions.
* total:
* type: number
* title: total
* description: The order's total including taxes and promotions.
* subtotal:
* type: number
* title: subtotal
* description: The order's total excluding taxes, including promotions.
* tax_total:
* type: number
* title: tax_total
* description: The order's tax total including promotions.
* discount_total:
* type: number
* title: discount_total
* description: The order's discount or promotions total.
* discount_tax_total:
* type: number
* title: discount_tax_total
* description: The tax total of order's discount or promotion.
* gift_card_total:
* type: number
* title: gift_card_total
* description: The order's gift card total.
* gift_card_tax_total:
* type: number
* title: gift_card_tax_total
* description: The tax total of the order's gift card.
* shipping_total:
* type: number
* title: shipping_total
* description: The order's shipping total including taxes and promotions.
* shipping_subtotal:
* type: number
* title: shipping_subtotal
* description: The order's shipping total excluding taxes, including promotions.
* shipping_tax_total:
* type: number
* title: shipping_tax_total
* description: The tax total of the order's shipping.
* original_shipping_total:
* type: number
* title: original_shipping_total
* description: The order's shipping total including taxes, excluding promotions.
* original_shipping_subtotal:
* type: number
* title: original_shipping_subtotal
* description: The order's shipping total excluding taxes, including promotions.
* original_shipping_tax_total:
* type: number
* title: original_shipping_tax_total
* description: The tax total of the order's shipping excluding promotions.
* *
*/ */

View File

@@ -1,7 +1,7 @@
/** /**
* @schema BaseOrderAddress * @schema BaseOrderAddress
* type: object * type: object
* description: The exchange's billing address. * description: An order address
* x-schemaName: BaseOrderAddress * x-schemaName: BaseOrderAddress
* required: * required:
* - id * - id
@@ -12,64 +12,67 @@
* id: * id:
* type: string * type: string
* title: id * title: id
* description: The billing address's ID. * description: The address's ID.
* customer_id: * customer_id:
* type: string * type: string
* title: customer_id * title: customer_id
* description: The billing address's customer id. * description: The ID of the customer this address belongs to.
* first_name: * first_name:
* type: string * type: string
* title: first_name * title: first_name
* description: The billing address's first name. * description: The address's first name.
* last_name: * last_name:
* type: string * type: string
* title: last_name * title: last_name
* description: The billing address's last name. * description: The address's last name.
* phone: * phone:
* type: string * type: string
* title: phone * title: phone
* description: The billing address's phone. * description: The address's phone.
* company: * company:
* type: string * type: string
* title: company * title: company
* description: The billing address's company. * description: The address's company.
* address_1: * address_1:
* type: string * type: string
* title: address_1 * title: address_1
* description: The billing address's address 1. * description: The address's first line.
* address_2: * address_2:
* type: string * type: string
* title: address_2 * title: address_2
* description: The billing address's address 2. * description: The address's second line.
* city: * city:
* type: string * type: string
* title: city * title: city
* description: The billing address's city. * description: The address's city.
* country_code: * country_code:
* type: string * type: string
* title: country_code * title: country_code
* description: The billing address's country code. * description: The address's country code.
* example: us
* country:
* $ref: "#/components/schemas/AdminRegionCountry"
* province: * province:
* type: string * type: string
* title: province * title: province
* description: The billing address's province. * description: The address's province.
* postal_code: * postal_code:
* type: string * type: string
* title: postal_code * title: postal_code
* description: The billing address's postal code. * description: The address's postal code.
* metadata: * metadata:
* type: object * type: object
* description: The billing address's metadata. * description: The address's metadata, can hold custom key-value pairs.
* created_at: * created_at:
* type: string * type: string
* format: date-time * format: date-time
* title: created_at * title: created_at
* description: The billing address's created at. * description: The date the address was created.
* updated_at: * updated_at:
* type: string * type: string
* format: date-time * format: date-time
* title: updated_at * title: updated_at
* description: The billing address's updated at. * description: The date the address was updated.
* *
*/ */

View File

@@ -4,8 +4,17 @@
* description: The order preview's order change. * description: The order preview's order change.
* x-schemaName: BaseOrderChange * x-schemaName: BaseOrderChange
* required: * required:
* - order
* - claim
* - return
* - exchange
* - id * - id
* - version
* - order_id * - order_id
* - return_id
* - exchange_id
* - claim_id
* - return_order
* - actions * - actions
* - status * - status
* - requested_by * - requested_by
@@ -20,14 +29,6 @@
* - canceled_at * - canceled_at
* - created_at * - created_at
* - updated_at * - updated_at
* - version
* - return_id
* - exchange_id
* - claim_id
* - order
* - return_order
* - exchange
* - claim
* properties: * properties:
* id: * id:
* type: string * type: string
@@ -141,11 +142,13 @@
* title: claim_id * title: claim_id
* description: The order change's claim id. * description: The order change's claim id.
* order: * order:
* $ref: "#/components/schemas/BaseOrder" * $ref: "#/components/schemas/AdminOrder"
* return_order: {} * return_order:
* exchange: {} * $ref: "#/components/schemas/AdminReturn"
* exchange:
* $ref: "#/components/schemas/AdminExchange"
* claim: * claim:
* $ref: "#/components/schemas/BaseClaim" * $ref: "#/components/schemas/AdminClaim"
* *
*/ */

View File

@@ -3,6 +3,87 @@
* type: object * type: object
* description: The action's actions. * description: The action's actions.
* x-schemaName: BaseOrderChangeAction * x-schemaName: BaseOrderChangeAction
* properties:
* order_change:
* $ref: "#/components/schemas/AdminOrderChange"
* id:
* type: string
* title: id
* description: The action's ID.
* order_change_id:
* type: string
* title: order_change_id
* description: The ID of the order change this action belongs to.
* order_id:
* type: string
* title: order_id
* description: The ID of the associated order.
* reference:
* type: string
* title: reference
* description: The name of the table this action applies on.
* enum:
* - claim
* - exchange
* - return
* - order_shipping_method
* reference_id:
* type: string
* title: reference_id
* description: The ID of the record in the referenced table.
* action:
* type: string
* title: action
* description: The applied action.
* details:
* type: object
* description: The action's details.
* example:
* reference_id: 123
* quantity: 1
* internal_note:
* type: string
* title: internal_note
* description: A note viewed only by admin users.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the order change action was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the order change action was updated.
* return_id:
* type: string
* title: return_id
* description: The ID of the associated return.
* claim_id:
* type: string
* title: claim_id
* description: The ID of the associated claim.
* exchange_id:
* type: string
* title: exchange_id
* description: The ID of the associated exchange.
* order:
* $ref: "#/components/schemas/BaseOrder"
* required:
* - order_change
* - id
* - order_change_id
* - order_id
* - reference
* - reference_id
* - action
* - details
* - internal_note
* - created_at
* - updated_at
* - return_id
* - claim_id
* - exchange_id
* - order
* *
*/ */

View File

@@ -24,51 +24,52 @@
* location_id: * location_id:
* type: string * type: string
* title: location_id * title: location_id
* description: The fulfillment's location id. * description: The ID of the location the items are fulfilled from.
* packed_at: * packed_at:
* type: string * type: string
* title: packed_at * title: packed_at
* description: The fulfillment's packed at. * description: The date the items were packed.
* format: date-time * format: date-time
* shipped_at: * shipped_at:
* type: string * type: string
* title: shipped_at * title: shipped_at
* description: The fulfillment's shipped at. * description: The date the items were shipped.
* format: date-time * format: date-time
* delivered_at: * delivered_at:
* type: string * type: string
* title: delivered_at * title: delivered_at
* description: The fulfillment's delivered at. * description: The date the items were delivered.
* format: date-time * format: date-time
* canceled_at: * canceled_at:
* type: string * type: string
* title: canceled_at * title: canceled_at
* description: The fulfillment's canceled at. * description: The date the items were canceled.
* format: date-time * format: date-time
* data: * data:
* type: object * type: object
* description: The fulfillment's data. * description: Data useful for the fulfillment provider handling it. This is taken from the associated shipping option.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/fulfillment/shipping-option#data-property
* provider_id: * provider_id:
* type: string * type: string
* title: provider_id * title: provider_id
* description: The fulfillment's provider id. * description: The ID of the fulfillment provider used to handle the fulfillment.
* shipping_option_id: * shipping_option_id:
* type: string * type: string
* title: shipping_option_id * title: shipping_option_id
* description: The fulfillment's shipping option id. * description: The ID of the associated shipping option.
* metadata: * metadata:
* type: object * type: object
* description: The fulfillment's metadata. * description: The fulfillment's metadata, can hold custom key-value pairs.
* created_at: * created_at:
* type: string * type: string
* format: date-time * format: date-time
* title: created_at * title: created_at
* description: The fulfillment's created at. * description: The date the fulfillment was created.
* updated_at: * updated_at:
* type: string * type: string
* format: date-time * format: date-time
* title: updated_at * title: updated_at
* description: The fulfillment's updated at. * description: The date the fulfillment was updated.
* *
*/ */

View File

@@ -3,6 +3,76 @@
* type: object * type: object
* description: The item's detail. * description: The item's detail.
* x-schemaName: BaseOrderItemDetail * x-schemaName: BaseOrderItemDetail
* * required:
* - id
* - item_id
* - quantity
* - fulfilled_quantity
* - delivered_quantity
* - shipped_quantity
* - return_requested_quantity
* - return_received_quantity
* - return_dismissed_quantity
* - written_off_quantity
* - metadata
* - created_at
* - updated_at
* properties:
* id:
* type: string
* title: id
* description: the detail's ID.
* item_id:
* type: string
* title: id
* description: the ID of the associated line item.
* item:
* $ref: "#/components/schemas/AdminOrderLineItem"
* quantity:
* type: number
* title: quantity
* description: The item's quantity.
* fulfilled_quantity:
* type: number
* title: fulfilled_quantity
* description: The item's fulfilled quantity.
* delivered_quantity:
* type: number
* title: fulfilled_quantity
* description: The item's delivered quantity.
* shipped_quantity:
* type: number
* title: shipped_quantity
* description: The item's shipped quantity.
* return_requested_quantity:
* type: number
* title: return_requested_quantity
* description: The item's quantity that's requested to be returned.
* return_received_quantity:
* type: number
* title: return_received_quantity
* description: The item's quantity that's returned and added to the underlying variant's stocked quantity.
* return_dismissed_quantity:
* type: number
* title: return_dismissed_quantity
* description: The item's quantity that's returned but damaged. So, it's not added to the underlying variant's stocked quantity.
* written_off_quantity:
* type: number
* title: written_off_quantity
* description: The item's quantity that's removed from the order.
* metadata:
* type: object
* title: metadata
* description: The item's metadata, can hold custom key-value pairs.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the detail was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the detail was updated.
*/ */

View File

@@ -58,19 +58,19 @@
* thumbnail: * thumbnail:
* type: string * type: string
* title: thumbnail * title: thumbnail
* description: The item's thumbnail. * description: The URL of the item's thumbnail.
* variant: * variant:
* $ref: "#/components/schemas/BaseProductVariant" * $ref: "#/components/schemas/AdminProductVariant"
* 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 variant.
* product: * product:
* $ref: "#/components/schemas/BaseProduct" * $ref: "#/components/schemas/BaseProduct"
* product_id: * product_id:
* type: string * type: string
* title: product_id * title: product_id
* description: The item's product id. * description: The ID of the associated product.
* product_title: * product_title:
* type: string * type: string
* title: product_title * title: product_title
@@ -90,7 +90,7 @@
* product_collection: * product_collection:
* type: string * type: string
* title: product_collection * title: product_collection
* description: The item's product collection. * description: The ID of the collection the item's product belongs to.
* product_handle: * product_handle:
* type: string * type: string
* title: product_handle * title: product_handle
@@ -98,7 +98,7 @@
* variant_sku: * variant_sku:
* type: string * type: string
* title: variant_sku * title: variant_sku
* description: The item's variant sku. * description: The item's variant SKU.
* variant_barcode: * variant_barcode:
* type: string * type: string
* title: variant_barcode * title: variant_barcode
@@ -109,23 +109,25 @@
* description: The item's variant title. * description: The item's variant title.
* variant_option_values: * variant_option_values:
* type: object * type: object
* description: The item's variant option values. * description: The values of the item variant's options.
* example:
* Color: Blue
* requires_shipping: * requires_shipping:
* type: boolean * type: boolean
* title: requires_shipping * title: requires_shipping
* description: The item's requires shipping. * description: Whether the item requires shipping.
* is_discountable: * is_discountable:
* type: boolean * type: boolean
* title: is_discountable * title: is_discountable
* description: The item's is discountable. * description: Whether the item is discountable.
* is_tax_inclusive: * is_tax_inclusive:
* type: boolean * type: boolean
* title: is_tax_inclusive * title: is_tax_inclusive
* description: The item's is tax inclusive. * description: Whether the item is tax inclusive.
* compare_at_unit_price: * compare_at_unit_price:
* type: number * type: number
* title: compare_at_unit_price * title: compare_at_unit_price
* description: The item's compare at unit price. * description: The original price of the item before a promotion or sale.
* unit_price: * unit_price:
* type: number * type: number
* title: unit_price * title: unit_price
@@ -150,67 +152,66 @@
* type: string * type: string
* format: date-time * format: date-time
* title: created_at * title: created_at
* description: The item's created at. * description: The date the item was created.
* updated_at: * updated_at:
* type: string * type: string
* format: date-time * format: date-time
* title: updated_at * title: updated_at
* description: The item's updated at. * description: The date the item was updated.
* metadata: * metadata:
* type: object * type: object
* description: The item's metadata. * description: The item's metadata, can hold custom key-value pairs.
* original_total: * original_total:
* type: number * type: number
* title: original_total * title: original_total
* description: The item's original total. * description: The item's total including taxes, excluding promotions.
* original_subtotal: * original_subtotal:
* type: number * type: number
* title: original_subtotal * title: original_subtotal
* description: The item's original subtotal. * description: The item's total excluding taxes, including promotions.
* original_tax_total: * original_tax_total:
* type: number * type: number
* title: original_tax_total * title: original_tax_total
* description: The item's original tax total. * description: The total taxes of the item, excluding promotions.
* item_total: * item_total:
* type: number * type: number
* title: item_total * title: item_total
* description: The item's item total. * description: The total taxes of the item, including promotions.
* item_subtotal: * item_subtotal:
* type: number * type: number
* title: item_subtotal * title: item_subtotal
* description: The item's item subtotal. * description: The item's total excluding taxes, including promotions.
* item_tax_total: * item_tax_total:
* type: number * type: number
* title: item_tax_total * title: item_tax_total
* description: The item's item tax total. * description: The total taxes of the item, including promotions.
* total: * total:
* type: number * type: number
* title: total * title: total
* description: The item's total. * description: The item's total, including taxes and promotions.
* subtotal: * subtotal:
* type: number * type: number
* title: subtotal * title: subtotal
* description: The item's subtotal. * description: The item's subtotal excluding taxes, including promotions.
* tax_total: * tax_total:
* type: number * type: number
* title: tax_total * title: tax_total
* description: The item's tax total. * description: The tax total of the item including promotions.
* discount_total: * discount_total:
* type: number * type: number
* title: discount_total * title: discount_total
* description: The item's discount total. * description: The total discount amount of the item.
* discount_tax_total: * discount_tax_total:
* type: number * type: number
* title: discount_tax_total * title: discount_tax_total
* description: The item's discount tax total. * description: The total taxes applied on the discounted amount.
* refundable_total: * refundable_total:
* type: number * type: number
* title: refundable_total * title: refundable_total
* description: The item's refundable total. * description: The total refundable amount of the item's total.
* refundable_total_per_unit: * refundable_total_per_unit:
* type: number * type: number
* title: refundable_total_per_unit * title: refundable_total_per_unit
* description: The item's refundable total per unit. * description: The total refundable amount of the item's total for a single quantity.
* *
*/ */

View File

@@ -1,8 +1,61 @@
/** /**
* @schema BaseOrderLineItemAdjustment * @schema BaseOrderLineItemAdjustment
* type: object * type: object
* description: The adjustment's adjustments. * description: The adjustment's details.
* x-schemaName: BaseOrderLineItemAdjustment * x-schemaName: BaseOrderLineItemAdjustment
* properties:
* item:
* $ref: "#/components/schemas/BaseOrderLineItem"
* item_id:
* type: string
* title: item_id
* description: The ID of the item this adjustment applies to.
* id:
* type: string
* title: id
* description: The adjustment's ID.
* code:
* type: string
* title: code
* description: The adjustment's code.
* amount:
* type: number
* title: amount
* description: The adjustment's amount.
* order_id:
* type: string
* title: order_id
* description: The ID of the associated order.
* description:
* type: string
* title: description
* description: The adjustment's description.
* promotion_id:
* type: string
* title: promotion_id
* description: The ID of the promotion that this applies on the order's item.
* provider_id:
* type: string
* title: provider_id
* description: The adjustment's provider ID.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the adjustment was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the adjustment was updated.
* required:
* - item
* - item_id
* - id
* - amount
* - order_id
* - created_at
* - updated_at
* *
*/ */

View File

@@ -3,6 +3,65 @@
* type: object * type: object
* description: The tax line's tax lines. * description: The tax line's tax lines.
* x-schemaName: BaseOrderLineItemTaxLine * x-schemaName: BaseOrderLineItemTaxLine
* properties:
* item:
* $ref: "#/components/schemas/BaseOrderLineItem"
* item_id:
* type: string
* title: item_id
* description: The ID of the associated line item.
* total:
* type: number
* title: total
* description: The tax line's total including promotions.
* subtotal:
* type: number
* title: subtotal
* description: The tax line's subtotal excluding promotions.
* id:
* type: string
* title: id
* description: The tax line's ID.
* description:
* type: string
* title: description
* description: The tax line's description.
* tax_rate_id:
* type: string
* title: tax_rate_id
* description: The ID of the applied tax rate.
* code:
* type: string
* title: code
* description: The code that the tax rate is identified by.
* rate:
* type: number
* title: rate
* description: The rate to charge.
* provider_id:
* type: string
* title: provider_id
* description: The ID of the tax provider used to calculate the tax line.
* created_at:
* type: string
* format: date-time
* title: created_at
* description: The date the tax line was created.
* updated_at:
* type: string
* format: date-time
* title: updated_at
* description: The date the tax line was updated.
* required:
* - item
* - item_id
* - total
* - subtotal
* - id
* - code
* - rate
* - created_at
* - updated_at
* *
*/ */

View File

@@ -10,6 +10,10 @@ import formatOas from "../../utils/format-oas.js"
import pluralize from "pluralize" import pluralize from "pluralize"
import { capitalize, wordsToPascal } from "utils" import { capitalize, wordsToPascal } from "utils"
import { OasArea } from "../kinds/oas.js" import { OasArea } from "../kinds/oas.js"
import {
isLevelExceeded,
maybeIncrementLevel,
} from "../../utils/level-utils.js"
export type ParsedSchema = { export type ParsedSchema = {
schema: OpenApiSchema schema: OpenApiSchema
@@ -27,7 +31,7 @@ class OasSchemaHelper {
private schemas: Map<string, OpenApiSchema> private schemas: Map<string, OpenApiSchema>
protected schemaRefPrefix = "#/components/schemas/" protected schemaRefPrefix = "#/components/schemas/"
protected formatter: Formatter protected formatter: Formatter
private MAX_LEVEL = 4 private MAX_LEVEL = 5
/** /**
* The path to the directory holding the base YAML files. * The path to the directory holding the base YAML files.
*/ */
@@ -56,9 +60,9 @@ class OasSchemaHelper {
*/ */
namedSchemaToReference( namedSchemaToReference(
schema: OpenApiSchema, schema: OpenApiSchema,
level = 0 level = 1
): OpenAPIV3.ReferenceObject | undefined { ): OpenAPIV3.ReferenceObject | undefined {
if (level > this.MAX_LEVEL) { if (isLevelExceeded(level, this.MAX_LEVEL)) {
return return
} }
@@ -91,8 +95,10 @@ class OasSchemaHelper {
!("$ref" in propertySchema.items) !("$ref" in propertySchema.items)
) { ) {
propertySchema.items = propertySchema.items =
this.namedSchemaToReference(propertySchema.items, level + 1) || this.namedSchemaToReference(
propertySchema.items propertySchema.items,
maybeIncrementLevel(level, "array")
) || propertySchema.items
} else if ( } else if (
propertySchema.oneOf || propertySchema.oneOf ||
propertySchema.allOf || propertySchema.allOf ||
@@ -108,14 +114,17 @@ class OasSchemaHelper {
} }
schemaTarget![index] = schemaTarget![index] =
this.namedSchemaToReference(item, level + 1) || item this.namedSchemaToReference(
item,
maybeIncrementLevel(level, "allOf")
) || item
}) })
} }
properties![property] = properties![property] =
this.namedSchemaToReference( this.namedSchemaToReference(
propertySchema as OpenApiSchema, propertySchema as OpenApiSchema,
level + 1 maybeIncrementLevel(level, "object")
) || propertySchema ) || propertySchema
}) })
} }
@@ -129,8 +138,8 @@ class OasSchemaHelper {
} }
} }
schemaChildrenToRefs(schema: OpenApiSchema, level = 0): OpenApiSchema { schemaChildrenToRefs(schema: OpenApiSchema, level = 1): OpenApiSchema {
if (level > this.MAX_LEVEL) { if (isLevelExceeded(level, this.MAX_LEVEL)) {
return schema return schema
} }
@@ -142,7 +151,10 @@ class OasSchemaHelper {
return item return item
} }
const transformChildItems = this.schemaChildrenToRefs(item, level + 1) const transformChildItems = this.schemaChildrenToRefs(
item,
maybeIncrementLevel(level, "allOf")
)
return ( return (
this.namedSchemaToReference(transformChildItems) || this.namedSchemaToReference(transformChildItems) ||
transformChildItems transformChildItems
@@ -154,7 +166,10 @@ class OasSchemaHelper {
return item return item
} }
const transformChildItems = this.schemaChildrenToRefs(item, level + 1) const transformChildItems = this.schemaChildrenToRefs(
item,
maybeIncrementLevel(level, "oneOf")
)
return ( return (
this.namedSchemaToReference(transformChildItems) || this.namedSchemaToReference(transformChildItems) ||
transformChildItems transformChildItems
@@ -166,7 +181,7 @@ class OasSchemaHelper {
) { ) {
const transformedChildItems = this.schemaChildrenToRefs( const transformedChildItems = this.schemaChildrenToRefs(
clonedSchema.items, clonedSchema.items,
level maybeIncrementLevel(level, "array")
) )
clonedSchema.items = clonedSchema.items =
this.namedSchemaToReference(transformedChildItems) || this.namedSchemaToReference(transformedChildItems) ||
@@ -179,7 +194,7 @@ class OasSchemaHelper {
const transformedProperty = this.schemaChildrenToRefs( const transformedProperty = this.schemaChildrenToRefs(
property, property,
level + 1 maybeIncrementLevel(level, "object")
) )
schema.properties![key] = schema.properties![key] =
this.namedSchemaToReference(transformedProperty) || this.namedSchemaToReference(transformedProperty) ||
@@ -200,7 +215,7 @@ class OasSchemaHelper {
const transformedProperty = this.schemaChildrenToRefs( const transformedProperty = this.schemaChildrenToRefs(
property, property,
level + 1 maybeIncrementLevel(level, "object")
) )
additionalProps.properties![key] = additionalProps.properties![key] =
this.namedSchemaToReference(transformedProperty) || this.namedSchemaToReference(transformedProperty) ||
@@ -272,13 +287,14 @@ class OasSchemaHelper {
*/ */
getSchemaByName( getSchemaByName(
name: string, name: string,
shouldNormalizeName = true shouldNormalizeName = true,
isUpdating = false
): ParsedSchema | undefined { ): ParsedSchema | undefined {
const schemaName = shouldNormalizeName const schemaName = shouldNormalizeName
? this.normalizeSchemaName(name) ? this.normalizeSchemaName(name)
: name : name
// check if it already exists in the schemas map // check if it already exists in the schemas map
if (this.schemas.has(schemaName)) { if (this.schemas.has(schemaName) && !isUpdating) {
return { return {
schema: JSON.parse(JSON.stringify(this.schemas.get(schemaName)!)), schema: JSON.parse(JSON.stringify(this.schemas.get(schemaName)!)),
schemaPrefix: `@schema ${schemaName}`, schemaPrefix: `@schema ${schemaName}`,

View File

@@ -26,6 +26,10 @@ import FunctionKindGenerator, {
VariableNode, VariableNode,
} from "./function.js" } from "./function.js"
import { API_ROUTE_PARAM_REGEX } from "../../constants.js" import { API_ROUTE_PARAM_REGEX } from "../../constants.js"
import {
isLevelExceeded,
maybeIncrementLevel,
} from "../../utils/level-utils.js"
const RES_STATUS_REGEX = /^res[\s\S]*\.status\((\d+)\)/ const RES_STATUS_REGEX = /^res[\s\S]*\.status\((\d+)\)/
@@ -55,7 +59,7 @@ type AuthRequests = {
class OasKindGenerator extends FunctionKindGenerator { class OasKindGenerator extends FunctionKindGenerator {
public name = "oas" public name = "oas"
protected allowedKinds: SyntaxKind[] = [ts.SyntaxKind.FunctionDeclaration] protected allowedKinds: SyntaxKind[] = [ts.SyntaxKind.FunctionDeclaration]
private MAX_LEVEL = 5 private MAX_LEVEL = 7
readonly REQUEST_TYPE_NAMES = [ readonly REQUEST_TYPE_NAMES = [
"MedusaRequest", "MedusaRequest",
"RequestWithContext", "RequestWithContext",
@@ -1251,7 +1255,7 @@ class OasKindGenerator extends FunctionKindGenerator {
*/ */
saveSchema?: boolean saveSchema?: boolean
}): OpenApiSchema { }): OpenApiSchema {
if (level > this.MAX_LEVEL) { if (isLevelExceeded(level, this.MAX_LEVEL)) {
return {} return {}
} }
@@ -1364,9 +1368,7 @@ class OasKindGenerator extends FunctionKindGenerator {
itemType: this.checker.getTypeArguments( itemType: this.checker.getTypeArguments(
itemType as ts.TypeReference itemType as ts.TypeReference
)[0], )[0],
// can't increment level because level: maybeIncrementLevel(level, "array"),
// array must have items in it
level,
title, title,
descriptionOptions: descriptionOptions:
descriptionOptions || title descriptionOptions || title
@@ -1400,10 +1402,7 @@ class OasKindGenerator extends FunctionKindGenerator {
).map((unionType) => ).map((unionType) =>
this.typeToSchema({ this.typeToSchema({
itemType: unionType, itemType: unionType,
// not incrementing considering the level: maybeIncrementLevel(level, "oneOf"),
// current schema isn't actually a
// schema
level,
title, title,
descriptionOptions, descriptionOptions,
saveSchema, saveSchema,
@@ -1424,10 +1423,7 @@ class OasKindGenerator extends FunctionKindGenerator {
).map((intersectionType) => { ).map((intersectionType) => {
return this.typeToSchema({ return this.typeToSchema({
itemType: intersectionType, itemType: intersectionType,
// not incrementing considering the level: maybeIncrementLevel(level, "allOf"),
// current schema isn't actually a
// schema
level,
title, title,
descriptionOptions, descriptionOptions,
saveSchema, saveSchema,
@@ -1537,7 +1533,7 @@ class OasKindGenerator extends FunctionKindGenerator {
> = {} > = {}
let isAdditionalProperties = false let isAdditionalProperties = false
if (level + 1 <= this.MAX_LEVEL) { if (!isLevelExceeded(level + 1, this.MAX_LEVEL)) {
let itemProperties = itemType.getProperties() let itemProperties = itemType.getProperties()
if ( if (
@@ -1545,9 +1541,18 @@ class OasKindGenerator extends FunctionKindGenerator {
itemType.aliasTypeArguments?.length === 2 && itemType.aliasTypeArguments?.length === 2 &&
itemType.aliasTypeArguments[0].flags === ts.TypeFlags.String itemType.aliasTypeArguments[0].flags === ts.TypeFlags.String
) { ) {
// object has dynamic keys, so put the properties under additionalProperties const isValueObj =
itemProperties = itemType.aliasTypeArguments[1].getProperties() itemType.aliasTypeArguments[1].isClassOrInterface() ||
isAdditionalProperties = true itemType.aliasTypeArguments[1].isTypeParameter() ||
((itemType.aliasTypeArguments[1] as ts.Type).flags ===
ts.TypeFlags.Object &&
!this.checker.isArrayType(itemType.aliasTypeArguments[1]))
if (isValueObj) {
// object has dynamic keys, so put the properties under additionalProperties
itemProperties = itemType.aliasTypeArguments[1].getProperties()
isAdditionalProperties = true
}
} }
itemProperties.forEach((property) => { itemProperties.forEach((property) => {
@@ -1610,7 +1615,7 @@ class OasKindGenerator extends FunctionKindGenerator {
properties[property.name] = this.typeToSchema({ properties[property.name] = this.typeToSchema({
itemType: propertyType, itemType: propertyType,
level: level + 1, level: maybeIncrementLevel(level, "object"),
title: property.name, title: property.name,
descriptionOptions: { descriptionOptions: {
...descriptionOptions, ...descriptionOptions,
@@ -1717,7 +1722,7 @@ class OasKindGenerator extends FunctionKindGenerator {
* @param level - The current recursion level to avoid max-stack error * @param level - The current recursion level to avoid max-stack error
* @returns Whether the symbol is required. * @returns Whether the symbol is required.
*/ */
isRequired(symbol: ts.Symbol, level = 0): boolean { isRequired(symbol: ts.Symbol, level = 1): boolean {
let isRequired = true let isRequired = true
const checkNode = (node: ts.Node) => { const checkNode = (node: ts.Node) => {
switch (node.kind) { switch (node.kind) {
@@ -1749,11 +1754,11 @@ class OasKindGenerator extends FunctionKindGenerator {
!symbol.valueDeclaration && !symbol.valueDeclaration &&
symbol.declarations?.length && symbol.declarations?.length &&
"symbol" in symbol.declarations[0] && "symbol" in symbol.declarations[0] &&
level < this.MAX_LEVEL !isLevelExceeded(level, this.MAX_LEVEL)
) { ) {
return this.isRequired( return this.isRequired(
symbol.declarations[0].symbol as ts.Symbol, symbol.declarations[0].symbol as ts.Symbol,
level + 1 maybeIncrementLevel(level, "object")
) )
} }
@@ -1956,13 +1961,14 @@ class OasKindGenerator extends FunctionKindGenerator {
*/ */
level?: number level?: number
}): OpenApiSchema | undefined { }): OpenApiSchema | undefined {
if (level > this.MAX_LEVEL) { if (isLevelExceeded(level, this.MAX_LEVEL)) {
return return
} }
let oldSchemaObj = ( let oldSchemaObj = (
oldSchema && "$ref" in oldSchema oldSchema && "$ref" in oldSchema
? this.oasSchemaHelper.getSchemaByName(oldSchema.$ref)?.schema ? this.oasSchemaHelper.getSchemaByName(oldSchema.$ref, true, true)
?.schema
: oldSchema : oldSchema
) as OpenApiSchema | undefined ) as OpenApiSchema | undefined
const newSchemaObj = ( const newSchemaObj = (
@@ -1973,7 +1979,7 @@ class OasKindGenerator extends FunctionKindGenerator {
if (!oldSchemaObj && newSchemaObj) { if (!oldSchemaObj && newSchemaObj) {
return newSchemaObj return newSchemaObj
} else if (!newSchemaObj) { } else if (!newSchemaObj || !Object.keys(newSchemaObj)) {
return undefined return undefined
} }
@@ -1984,6 +1990,7 @@ class OasKindGenerator extends FunctionKindGenerator {
oldSchemaObj = { oldSchemaObj = {
...newSchemaObj, ...newSchemaObj,
description: oldSchemaObj?.description, description: oldSchemaObj?.description,
example: oldSchemaObj?.example || newSchemaObj.example,
} }
} else if ( } else if (
oldSchemaObj?.allOf && oldSchemaObj?.allOf &&
@@ -2025,7 +2032,7 @@ class OasKindGenerator extends FunctionKindGenerator {
this.updateSchema({ this.updateSchema({
oldSchema: oldSchemaObj!.additionalProperties, oldSchema: oldSchemaObj!.additionalProperties,
newSchema: newSchemaObj.additionalProperties, newSchema: newSchemaObj.additionalProperties,
level: level + 1, level: maybeIncrementLevel(level, "object"),
}) || oldSchemaObj!.additionalProperties }) || oldSchemaObj!.additionalProperties
} }
} else { } else {
@@ -2047,7 +2054,7 @@ class OasKindGenerator extends FunctionKindGenerator {
newSchema: newSchemaObj!.properties![ newSchema: newSchemaObj!.properties![
propertyName propertyName
] as OpenApiSchema, ] as OpenApiSchema,
level: level + 1, level: maybeIncrementLevel(level, "object"),
}) || propertySchema }) || propertySchema
} }
) )
@@ -2070,7 +2077,7 @@ class OasKindGenerator extends FunctionKindGenerator {
this.updateSchema({ this.updateSchema({
oldSchema: oldSchemaObj.items as OpenApiSchema, oldSchema: oldSchemaObj.items as OpenApiSchema,
newSchema: newSchemaObj!.items as OpenApiSchema, newSchema: newSchemaObj!.items as OpenApiSchema,
level: level + 1, level: maybeIncrementLevel(level, "array"),
}) || oldSchemaObj.items }) || oldSchemaObj.items
} }

View File

@@ -0,0 +1,16 @@
type IncrementType = "array" | "allOf" | "anyOf" | "oneOf" | "object"
export function maybeIncrementLevel(
level: number,
type: IncrementType
): number {
if (type !== "object") {
return level
}
return level + 1
}
export function isLevelExceeded(level: number, maxLevel: number) {
return level > maxLevel
}