chore(): start moving some packages to the core directory (#7215)

This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-05-03 13:37:41 +02:00
1 parent fdee748eed
commit bbccd6481d
1436 files changed
+275 -756

No files matched your search

@@ -0,0 +1,87 @@
module.exports = CircularPatch
/**
* Since ref() is triggered upon reaching a $ref OAS line (leaf),
* we want to inverse `schemas` instructions in order to optimize iterators.
*/
function preparePatches(schemas) {
const patches = []
const patchesObj = {}
for (const schemaToPatch in schemas) {
for (const schemaName of schemas[schemaToPatch]) {
if (!patchesObj[schemaName]) {
patchesObj[schemaName] = {
schemaName,
schemaPointer: `#/components/schemas/${schemaName}`,
schemaToPatchPointers: [],
}
}
const schemaToPatchPointer = `#/components/schemas/${schemaToPatch}`
if (
!patchesObj[schemaName].schemaToPatchPointers.includes(
schemaToPatchPointer
)
) {
patchesObj[schemaName].schemaToPatchPointers.push(schemaToPatchPointer)
}
}
}
for (const key in patchesObj) {
patches.push(patchesObj[key])
}
return patches
}
function applyPatch(node, schemaName) {
delete node["$ref"]
node.type = "object"
if (!node.description && schemaName) {
node.description = `${schemaName} object.`
}
}
function CircularPatch({ schemas = {}, verbose = false }) {
const logs = []
const patches = preparePatches(schemas)
const refPathPrefix = "#/components/schemas/"
const refPathPrefixLength = refPathPrefix.length
const refPathPrefixRegex = /#\/components\/schemas\/\w+/
return {
ref(ref, ctx, resolved) {
if (
ctx.type.name.toLowerCase() !== "schema" ||
!resolved?.location?.pointer
) {
return
}
for (const patch of patches) {
if (resolved.location.pointer !== patch.schemaPointer) {
continue
}
const ctxSchemaPointer =
ctx.location.pointer.match(refPathPrefixRegex)[0]
if (!patch.schemaToPatchPointers.includes(ctxSchemaPointer)) {
continue
}
applyPatch(ref)
if (verbose) {
logs.push(
`${ctxSchemaPointer.substring(refPathPrefixLength)} patch $ref to ${
patch.schemaName
}`
)
}
}
},
Root: {
leave() {
if (verbose) {
logs.sort()
for (const log of logs) {
console.debug(log)
}
}
},
},
}
}
@@ -0,0 +1,14 @@
const CircularPatch = require("./decorators/circular-patch")
const id = "medusa"
const decorators = {
oas3: {
"circular-patch": CircularPatch,
},
}
module.exports = {
id,
decorators,
}
@@ -0,0 +1,164 @@
plugins:
- "./plugins/medusa/index.js"
# Allows to replace a $ref with `type: object` in order to avoid infinite loops
# when Redocly attempts to render circular references.
decorators:
medusa/circular-patch:
schemas:
Address:
- Customer
Cart:
- Customer
- Order
- Payment
- PaymentSession
ClaimImage:
- ClaimItem
ClaimItem:
- ClaimOrder
ClaimOrder:
- Fulfillment
- Order
- Return
Country:
- Region
Customer:
- Order
CustomerGroup:
- Customer
- PriceList
Discount:
- Discount
DiscountRule:
- DiscountCondition
DraftOrder:
- Cart
- Order
Fulfillment:
- ClaimOrder
- Order
- Swap
FulfillmentItem:
- Fulfillment
GiftCard:
- Order
GiftCardTransaction:
- GiftCard
- Order
LineItem:
- Cart
- ClaimOrder
- Order
- OrderEdit
- Swap
LineItemAdjustment:
- LineItem
LineItemTaxLine:
- LineItem
MoneyAmount:
- PriceList
- ProductVariant
- Region
Notification:
- Notification
Order:
- Cart
- ClaimOrder
- Customer
- DraftOrder
- Fulfillment
- OrderEdit
- Payment
- Refund
- Return
- Swap
OrderEdit:
- Order
OrderItemChange:
- OrderEdit
Payment:
- Cart
- Order
- Swap
ProductCategory:
- ProductCategory
- Product
ProductCollection:
- Product
ProductOption:
- Product
ProductOptionValue:
- ProductOption
- ProductVariant
ProductVariant:
- Product
ProductVariantInventoryItem:
- ProductVariant
Refund:
- Order
- Payment
Return:
- ClaimOrder
- Order
- Swap
ReturnItem:
- Return
ReturnReason:
- ReturnReason
SalesChannelLocation:
- SalesChannel
ShippingMethod:
- Cart
- ClaimOrder
- Order
- Payment
- Return
- Swap
ShippingMethodTaxLine:
- ShippingMethod
ShippingOption:
- Region
ShippingOptionRequirement:
- ShippingOption
ShippingProfile:
- Product
- ShippingOption
Swap:
- Cart
- Fulfillment
- Order
- Payment
- Return
TaxRate:
- Region
TrackingLink:
- Fulfillment
SalesChannel:
- Order
- Cart
- PublishableApiKey
CustomerGroupResponse:
- CustomerResponse
ProductCategoryResponse:
- ProductCategoryResponse
# Similar config to /www/docs/docusaurus.config.js > redocusaurus
# Allows to emulate rendering of API public documentation when using `yarn redocly preview-docs openapi.yaml`
theme:
openapi:
theme:
colors:
primary:
dark: "#242526"
sidebar:
width: "250px"
disableSearch: true
expandResponses: "200,204"
generatedPayloadSamplesMaxDepth: 4
hideDownloadButton: true
hideRequestPayloadSample: true
nativeScrollbars: true
requiredPropsFirst: true
showObjectSchemaExamples: true
sortTagsAlphabetically: true