docs: fix api-reference with proxy (#7952)

This commit is contained in:
Shahed Nasser
2024-07-04 18:10:48 +03:00
committed by GitHub
parent 0d534d4f70
commit 1acbcf612e
17 changed files with 24 additions and 20 deletions

View File

@@ -1,37 +0,0 @@
import { NextResponse } from "next/server"
import path from "path"
import OpenAPIParser from "@readme/openapi-parser"
import getPathsOfTag from "@/utils/get-paths-of-tag"
import type { ExpandedDocument } from "@/types/openapi"
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const area = searchParams.get("area")
const expand = searchParams.get("expand")
if (area !== "admin" && area !== "store") {
return NextResponse.json(
{
success: false,
message: `area ${area} is not allowed`,
},
{
status: 400,
}
)
}
const baseSpecs = (await OpenAPIParser.parse(
path.join(process.cwd(), "specs", area, "openapi.yaml")
)) as ExpandedDocument
if (expand) {
const paths = await getPathsOfTag(expand, area)
if (paths) {
baseSpecs.expandedTags = {}
baseSpecs.expandedTags[expand] = paths.paths
}
}
return NextResponse.json(baseSpecs, {
status: 200,
})
}