docs: add loyalty plugin routes to OAS (#12811)

* generated OAS

* remove unused schemas

* generated specs

* add cloud badge for routes

* add to loyalty plugin page

* allow clicking the tooltip
This commit is contained in:
Shahed Nasser
2025-06-24 19:17:55 +03:00
committed by GitHub
parent 3826bde591
commit 93cf79cb0f
164 changed files with 16001 additions and 88 deletions
@@ -83,7 +83,7 @@ class OasGenerator extends AbstractGenerator {
isFileIncluded(fileName: string): boolean {
return (
super.isFileIncluded(fileName) &&
minimatch(getBasePath(fileName), "packages/medusa/**/api**/**", {
minimatch(getBasePath(fileName), "**/api**/**", {
matchBase: true,
})
)
@@ -121,6 +121,14 @@ class OasKindGenerator extends FunctionKindGenerator {
requiresAuthentication: true,
allowedAuthTypes: ["cookie_auth", "jwt_token"],
},
{
startsWith: "store/gift-card",
requiresAuthentication: true,
},
{
startsWith: "store/store-credit-accounts",
requiresAuthentication: true,
},
]
readonly RESPONSE_TYPE_NAMES = ["MedusaResponse"]
readonly FIELD_QUERY_PARAMS = ["fields", "expand"]
@@ -116,56 +116,58 @@ export default async function () {
"route.ts"
)
// check if a route exists for the path
if (!existsSync(sourceFilePath)) {
// remove OAS file
rmSync(filePath, {
force: true,
})
return
}
// check if method exists in the file
let exists = false
const program = ts.createProgram([sourceFilePath], {})
const oasKindGenerator = new OasKindGenerator({
checker: program.getTypeChecker(),
generatorEventManager: new GeneratorEventManager(),
additionalOptions: {},
})
const sourceFile = program.getSourceFile(sourceFilePath)
if (!sourceFile) {
// remove file
rmSync(filePath, {
force: true,
})
return
}
const visitChildren = (node: ts.Node) => {
if (
!exists &&
oasKindGenerator.isAllowed(node) &&
oasKindGenerator.canDocumentNode(node) &&
oasKindGenerator.getHTTPMethodName(node) ===
matchOasPrefix.groups!.method
) {
exists = true
} else if (!exists) {
ts.forEachChild(node, visitChildren)
if (!oas["x-ignoreCleanup"]) {
// check if a route exists for the path
if (!existsSync(sourceFilePath)) {
// remove OAS file
rmSync(filePath, {
force: true,
})
return
}
}
ts.forEachChild(sourceFile, visitChildren)
// check if method exists in the file
let exists = false
const program = ts.createProgram([sourceFilePath], {})
if (!exists) {
// remove OAS file
rmSync(filePath, {
force: true,
const oasKindGenerator = new OasKindGenerator({
checker: program.getTypeChecker(),
generatorEventManager: new GeneratorEventManager(),
additionalOptions: {},
})
return
const sourceFile = program.getSourceFile(sourceFilePath)
if (!sourceFile) {
// remove file
rmSync(filePath, {
force: true,
})
return
}
const visitChildren = (node: ts.Node) => {
if (
!exists &&
oasKindGenerator.isAllowed(node) &&
oasKindGenerator.canDocumentNode(node) &&
oasKindGenerator.getHTTPMethodName(node) ===
matchOasPrefix.groups!.method
) {
exists = true
} else if (!exists) {
ts.forEachChild(node, visitChildren)
}
}
ts.forEachChild(sourceFile, visitChildren)
if (!exists) {
// remove OAS file
rmSync(filePath, {
force: true,
})
return
}
}
// collect tags
@@ -14,6 +14,7 @@ export declare type OpenApiOperation = Partial<OpenAPIV3.OperationObject> & {
"x-deprecated_message"?: string
"x-version"?: string
"x-featureFlag"?: string
"x-ignoreCleanup"?: boolean
}
export declare type CommonCliOptions = {
@@ -1,15 +1,9 @@
/**
* Retrieve the pathname of a file without the relative part before `packages/`
* Retrieve the pathname of a file without the relative part
*
* @param fileName - The file name/path
* @returns The path without the relative part.
*/
export default function getBasePath(fileName: string) {
let basePath = fileName
const packageIndex = fileName.indexOf("packages/")
if (packageIndex) {
basePath = basePath.substring(packageIndex)
}
return basePath
return fileName.substring(fileName.lastIndexOf("../") + 3)
}